Skip to content

Docs API: Use stdout by default. Add YAML output format.#400

Merged
amotl merged 2 commits intomainfrom
docs-settings-stdout
Apr 13, 2025
Merged

Docs API: Use stdout by default. Add YAML output format.#400
amotl merged 2 commits intomainfrom
docs-settings-stdout

Conversation

@amotl
Copy link
Copy Markdown
Member

@amotl amotl commented Apr 13, 2025

About

Streamline and trim the rendering and output writing subsystem a bit.
When no output parameter is given, emit results to stdout.
Also enable rendering into YAML format.

Python API

from cratedb_toolkit.docs.settings import SettingsExtractor

extractor = SettingsExtractor()
extractor.acquire().render(format).write(output)

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 13, 2025

Walkthrough

This pull request refines the settings extraction functionality in the CrateDB Toolkit. It enhances the CLI to support YAML output in addition to JSON, Markdown, and SQL. The extraction logic has been transformed from a procedural style to an object-oriented approach via the new SettingsExtractor class. Additional improvements include detailed progress reporting, updated error handling, and enhanced SQL and Markdown generation. Documentation has been updated to include installation instructions and usage guidelines, while the test suite has been expanded to cover multiple output formats.

Changes

Files Change Summary
cratedb_toolkit/docs/cli.py
cratedb_toolkit/docs/settings.py
Updated CLI help options to include YAML, refactored settings extraction to utilize the new SettingsExtractor class, added progress reporting using rich.Progress, improved SQL and Markdown generation, and enhanced error handling.
doc/.../docs-api.md Added an "Install" section with installation instructions; restructured documentation by placing the "CrateDB settings" section under a new "Usage" header and updating the usage description.
tests/docs/test_cli.py Modified the existing JSON output test (renamed to test_settings_json) and added new tests for Markdown, SQL, and YAML output formats, updating file paths and assertions to verify the correctness of the outputs.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CLI as CLI Command
    participant SE as SettingsExtractor

    U->>CLI: Run command (e.g., ctk docs settings --format=yaml)
    CLI->>SE: Instantiate SettingsExtractor
    SE->>SE: acquire() - Gather settings data
    SE->>SE: render(format) - Format settings (JSON, YAML, Markdown, SQL)
    SE->>SE: write(output) - Write the formatted output
    SE-->>CLI: Return output confirmation
    CLI-->>U: Display output message
Loading

Poem

I'm a rabbit in a coding warren, so spry,
Hoppin' through refactors with a gleam in my eye.
YAML joins the party, SQL and Markdown too,
New extractor magic now makes our toolkit anew.
With every hop and line of code, my joy is sky-high! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 79a90aa and 238c917.

📒 Files selected for processing (4)
  • cratedb_toolkit/docs/cli.py (2 hunks)
  • cratedb_toolkit/docs/settings.py (4 hunks)
  • doc/docs-api.md (1 hunks)
  • tests/docs/test_cli.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • doc/docs-api.md
🧰 Additional context used
🪛 GitHub Check: codecov/patch
cratedb_toolkit/docs/settings.py

[warning] 15-16: cratedb_toolkit/docs/settings.py#L15-L16
Added lines #L15 - L16 were not covered by tests


[warning] 21-23: cratedb_toolkit/docs/settings.py#L21-L23
Added lines #L21 - L23 were not covered by tests


[warning] 26-26: cratedb_toolkit/docs/settings.py#L26
Added line #L26 was not covered by tests


[warning] 32-33: cratedb_toolkit/docs/settings.py#L32-L33
Added lines #L32 - L33 were not covered by tests


[warning] 49-49: cratedb_toolkit/docs/settings.py#L49
Added line #L49 was not covered by tests


[warning] 54-59: cratedb_toolkit/docs/settings.py#L54-L59
Added lines #L54 - L59 were not covered by tests


[warning] 62-62: cratedb_toolkit/docs/settings.py#L62
Added line #L62 was not covered by tests


[warning] 428-428: cratedb_toolkit/docs/settings.py#L428
Added line #L428 was not covered by tests


[warning] 435-436: cratedb_toolkit/docs/settings.py#L435-L436
Added lines #L435 - L436 were not covered by tests


[warning] 438-439: cratedb_toolkit/docs/settings.py#L438-L439
Added lines #L438 - L439 were not covered by tests


[warning] 442-446: cratedb_toolkit/docs/settings.py#L442-L446
Added lines #L442 - L446 were not covered by tests


[warning] 449-449: cratedb_toolkit/docs/settings.py#L449
Added line #L449 was not covered by tests


[warning] 451-454: cratedb_toolkit/docs/settings.py#L451-L454
Added lines #L451 - L454 were not covered by tests


[warning] 456-456: cratedb_toolkit/docs/settings.py#L456
Added line #L456 was not covered by tests


[warning] 459-463: cratedb_toolkit/docs/settings.py#L459-L463
Added lines #L459 - L463 were not covered by tests


[warning] 465-465: cratedb_toolkit/docs/settings.py#L465
Added line #L465 was not covered by tests


[warning] 467-469: cratedb_toolkit/docs/settings.py#L467-L469
Added lines #L467 - L469 were not covered by tests


[warning] 471-471: cratedb_toolkit/docs/settings.py#L471
Added line #L471 was not covered by tests


[warning] 473-473: cratedb_toolkit/docs/settings.py#L473
Added line #L473 was not covered by tests


[warning] 592-595: cratedb_toolkit/docs/settings.py#L592-L595
Added lines #L592 - L595 were not covered by tests


[warning] 597-600: cratedb_toolkit/docs/settings.py#L597-L600
Added lines #L597 - L600 were not covered by tests


[warning] 603-604: cratedb_toolkit/docs/settings.py#L603-L604
Added lines #L603 - L604 were not covered by tests


[warning] 606-607: cratedb_toolkit/docs/settings.py#L606-L607
Added lines #L606 - L607 were not covered by tests


[warning] 609-610: cratedb_toolkit/docs/settings.py#L609-L610
Added lines #L609 - L610 were not covered by tests


[warning] 613-613: cratedb_toolkit/docs/settings.py#L613
Added line #L613 was not covered by tests


[warning] 616-619: cratedb_toolkit/docs/settings.py#L616-L619
Added lines #L616 - L619 were not covered by tests


[warning] 622-623: cratedb_toolkit/docs/settings.py#L622-L623
Added lines #L622 - L623 were not covered by tests


[warning] 629-630: cratedb_toolkit/docs/settings.py#L629-L630
Added lines #L629 - L630 were not covered by tests

cratedb_toolkit/docs/cli.py

[warning] 60-60: cratedb_toolkit/docs/cli.py#L60
Added line #L60 was not covered by tests


[warning] 62-63: cratedb_toolkit/docs/cli.py#L62-L63
Added lines #L62 - L63 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build-and-publish
  • GitHub Check: Generic: Python 3.12 on OS ubuntu-latest
  • GitHub Check: Generic: Python 3.9 on OS ubuntu-latest
  • GitHub Check: Generic: Python 3.8 on OS ubuntu-latest
  • GitHub Check: CFR for OS windows-latest
  • GitHub Check: CFR for OS macos-13
🔇 Additional comments (14)
cratedb_toolkit/docs/cli.py (2)

49-51: YAML format option added correctly.

The YAML output format has been properly integrated with the CLI options, including the help text update.


60-63:

Details

❓ Verification inconclusive

Good refactoring to OOP approach with SettingsExtractor.

The code has been elegantly refactored from a procedural approach to an object-oriented style using method chaining. This improves readability and maintainability.

The static analysis indicates these lines aren't covered by tests. Let's verify this:


🏁 Script executed:

#!/bin/bash
# Check test coverage for the settings command in CLI
rg -A 5 "def settings" tests/docs/test_cli.py

Length of output: 47


Refactored CLI Settings Command – Verify Test Coverage

Nice refactoring that adopts an object‐oriented design with the SettingsExtractor and improves readability through method chaining. However, the static analysis (using a search for def settings in tests/docs/test_cli.py) returned no results. Please verify manually whether these CLI settings code paths are tested elsewhere or if additional tests should be added.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 60-60: cratedb_toolkit/docs/cli.py#L60
Added line #L60 was not covered by tests


[warning] 62-63: cratedb_toolkit/docs/cli.py#L62-L63
Added lines #L62 - L63 were not covered by tests

tests/docs/test_cli.py (5)

4-4: Required import for the new YAML support.

The yaml import is correctly added to support the new YAML output format testing.


10-28: Well-structured test for JSON output.

The test has been properly updated to use tmp_path for file output and explicitly test the JSON format. This follows good testing practices by isolating test file outputs.


31-51: Good test coverage for Markdown output.

This test effectively verifies the Markdown output format by checking for expected content in the generated file.


53-73: Good test coverage for SQL output.

The test correctly verifies SQL statement generation, including checking for statement formatting with semicolons and summary content.


75-93: Comprehensive test for YAML output.

The test provides good coverage for the new YAML output format, including parsing the output and verifying expected content.

cratedb_toolkit/docs/settings.py (7)

6-8: Documentation properly updated for YAML support.

The file header documentation has been correctly updated to include YAML as a supported output format.


15-17: Required imports added for new functionality.

The necessary imports have been added to support the enhanced functionality, including dataclasses, io for string handling, and yaml for the new output format.

Also applies to: 21-23, 26-26

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 15-16: cratedb_toolkit/docs/settings.py#L15-L16
Added lines #L15 - L16 were not covered by tests


32-33: Improved logging configuration.

The logging configuration has been simplified and modularized using the modern approach of getting a logger by __name__.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 32-33: cratedb_toolkit/docs/settings.py#L32-L33
Added lines #L32 - L33 were not covered by tests


49-60: Enhanced progress reporting.

The extraction process now includes more detailed progress updates, improving user experience during execution. The logging and status updates are well-structured.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 49-49: cratedb_toolkit/docs/settings.py#L49
Added line #L49 was not covered by tests


[warning] 54-59: cratedb_toolkit/docs/settings.py#L54-L59
Added lines #L54 - L59 were not covered by tests


428-473: Refactored Markdown generation to return a string.

The write_markdown_table function has been refactored to return a string instead of writing directly to a file. This is a good design choice that:

  1. Separates content generation from I/O operations
  2. Makes the function more testable
  3. Allows for flexible output handling (stdout or file)
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 428-428: cratedb_toolkit/docs/settings.py#L428
Added line #L428 was not covered by tests


[warning] 435-436: cratedb_toolkit/docs/settings.py#L435-L436
Added lines #L435 - L436 were not covered by tests


[warning] 438-439: cratedb_toolkit/docs/settings.py#L438-L439
Added lines #L438 - L439 were not covered by tests


[warning] 442-446: cratedb_toolkit/docs/settings.py#L442-L446
Added lines #L442 - L446 were not covered by tests


[warning] 449-449: cratedb_toolkit/docs/settings.py#L449
Added line #L449 was not covered by tests


[warning] 451-454: cratedb_toolkit/docs/settings.py#L451-L454
Added lines #L451 - L454 were not covered by tests


[warning] 456-456: cratedb_toolkit/docs/settings.py#L456
Added line #L456 was not covered by tests


[warning] 459-463: cratedb_toolkit/docs/settings.py#L459-L463
Added lines #L459 - L463 were not covered by tests


[warning] 465-465: cratedb_toolkit/docs/settings.py#L465
Added line #L465 was not covered by tests


[warning] 467-469: cratedb_toolkit/docs/settings.py#L467-L469
Added lines #L467 - L469 were not covered by tests


[warning] 471-471: cratedb_toolkit/docs/settings.py#L471
Added line #L471 was not covered by tests


[warning] 473-473: cratedb_toolkit/docs/settings.py#L473
Added line #L473 was not covered by tests


592-610: Added SQL statement generation function.

The write_sql_statements function has been added to generate SQL statements in a string format, consistent with the refactoring approach used for the Markdown function.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 592-595: cratedb_toolkit/docs/settings.py#L592-L595
Added lines #L592 - L595 were not covered by tests


[warning] 597-600: cratedb_toolkit/docs/settings.py#L597-L600
Added lines #L597 - L600 were not covered by tests


[warning] 603-604: cratedb_toolkit/docs/settings.py#L603-L604
Added lines #L603 - L604 were not covered by tests


[warning] 606-607: cratedb_toolkit/docs/settings.py#L606-L607
Added lines #L606 - L607 were not covered by tests


[warning] 609-610: cratedb_toolkit/docs/settings.py#L609-L610
Added lines #L609 - L610 were not covered by tests


613-620: Good use of Enum for output formats.

Using an Enum for output formats is a clean approach that adds type safety and makes the code more maintainable.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 613-613: cratedb_toolkit/docs/settings.py#L613
Added line #L613 was not covered by tests


[warning] 616-619: cratedb_toolkit/docs/settings.py#L616-L619
Added lines #L616 - L619 were not covered by tests

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@amotl amotl requested a review from WalBeh April 13, 2025 14:16
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
doc/docs-api.md (2)

5-8: Add official link or reference to installation docs
While these installation instructions look correct, consider linking to your project's official documentation or referencing a more detailed guide about installing the Docs API, such as in your README or a dedicated installation/integration section.


10-19: Include YAML usage example
You’ve provided examples for JSON, Markdown, and SQL formats. To fully showcase the new YAML format, consider adding a short example demonstrating --format=yaml.

cratedb_toolkit/docs/cli.py (1)

60-63: Ensure all new extractor logic is covered by tests
You might be missing test coverage for scenarios invoking SettingsExtractor from the CLI (e.g., empty or invalid documentation scenarios). Consider adding negative or edge-case tests to further improve coverage.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 60-60: cratedb_toolkit/docs/cli.py#L60
Added line #L60 was not covered by tests


[warning] 62-63: cratedb_toolkit/docs/cli.py#L62-L63
Added lines #L62 - L63 were not covered by tests

tests/docs/test_cli.py (1)

31-51: Align file extension with output format
These tests generate Markdown or SQL output yet save to a file named cratedb-settings.yaml. Renaming the output file to match the actual format (e.g., .md for Markdown, .sql for SQL) improves clarity.

Apply the following diffs for clarity:

--- a/tests/docs/test_cli.py
+++ b/tests/docs/test_cli.py
@@ -36,7 +36,7 @@ def test_settings_markdown(tmp_path: Path):
 
-    output_path = tmp_path / "cratedb-settings.yaml"
+    output_path = tmp_path / "cratedb-settings.md"

@@ -58,7 +58,7 @@ def test_settings_sql(tmp_path: Path):
 
-    output_path = tmp_path / "cratedb-settings.yaml"
+    output_path = tmp_path / "cratedb-settings.sql"

Also applies to: 53-73

cratedb_toolkit/docs/settings.py (2)

614-617: Update docstring to mention YAML output
The docstring says “Output in JSON, Markdown, or SQL format” but YAML is also supported.

Use this small fix:

-    Output in JSON, Markdown, or SQL format.
+    Output in JSON, YAML, Markdown, or SQL format.

53-58: Add negative or timeout test coverage
The code block fetching documentation is not covered by tests if the fetch fails or if the returned content is empty. Consider adding a dedicated scenario forcing a non-200 HTTP status or empty response to confirm error handling and logging.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 53-58: cratedb_toolkit/docs/settings.py#L53-L58
Added lines #L53 - L58 were not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3ec1ea and b56efa7.

📒 Files selected for processing (4)
  • cratedb_toolkit/docs/cli.py (2 hunks)
  • cratedb_toolkit/docs/settings.py (4 hunks)
  • doc/docs-api.md (1 hunks)
  • tests/docs/test_cli.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
cratedb_toolkit/docs/cli.py (1)
cratedb_toolkit/docs/settings.py (4)
  • SettingsExtractor (613-658)
  • acquire (622-632)
  • render (634-648)
  • write (650-658)
🪛 GitHub Check: codecov/patch
cratedb_toolkit/docs/cli.py

[warning] 60-60: cratedb_toolkit/docs/cli.py#L60
Added line #L60 was not covered by tests


[warning] 62-63: cratedb_toolkit/docs/cli.py#L62-L63
Added lines #L62 - L63 were not covered by tests

cratedb_toolkit/docs/settings.py

[warning] 15-16: cratedb_toolkit/docs/settings.py#L15-L16
Added lines #L15 - L16 were not covered by tests


[warning] 21-21: cratedb_toolkit/docs/settings.py#L21
Added line #L21 was not covered by tests


[warning] 25-25: cratedb_toolkit/docs/settings.py#L25
Added line #L25 was not covered by tests


[warning] 31-32: cratedb_toolkit/docs/settings.py#L31-L32
Added lines #L31 - L32 were not covered by tests


[warning] 48-48: cratedb_toolkit/docs/settings.py#L48
Added line #L48 was not covered by tests


[warning] 53-58: cratedb_toolkit/docs/settings.py#L53-L58
Added lines #L53 - L58 were not covered by tests


[warning] 61-61: cratedb_toolkit/docs/settings.py#L61
Added line #L61 was not covered by tests


[warning] 427-427: cratedb_toolkit/docs/settings.py#L427
Added line #L427 was not covered by tests


[warning] 434-435: cratedb_toolkit/docs/settings.py#L434-L435
Added lines #L434 - L435 were not covered by tests


[warning] 437-438: cratedb_toolkit/docs/settings.py#L437-L438
Added lines #L437 - L438 were not covered by tests


[warning] 441-445: cratedb_toolkit/docs/settings.py#L441-L445
Added lines #L441 - L445 were not covered by tests


[warning] 448-448: cratedb_toolkit/docs/settings.py#L448
Added line #L448 was not covered by tests


[warning] 450-453: cratedb_toolkit/docs/settings.py#L450-L453
Added lines #L450 - L453 were not covered by tests


[warning] 455-455: cratedb_toolkit/docs/settings.py#L455
Added line #L455 was not covered by tests


[warning] 458-462: cratedb_toolkit/docs/settings.py#L458-L462
Added lines #L458 - L462 were not covered by tests


[warning] 464-464: cratedb_toolkit/docs/settings.py#L464
Added line #L464 was not covered by tests


[warning] 466-468: cratedb_toolkit/docs/settings.py#L466-L468
Added lines #L466 - L468 were not covered by tests


[warning] 470-470: cratedb_toolkit/docs/settings.py#L470
Added line #L470 was not covered by tests


[warning] 472-472: cratedb_toolkit/docs/settings.py#L472
Added line #L472 was not covered by tests


[warning] 591-594: cratedb_toolkit/docs/settings.py#L591-L594
Added lines #L591 - L594 were not covered by tests


[warning] 596-599: cratedb_toolkit/docs/settings.py#L596-L599
Added lines #L596 - L599 were not covered by tests


[warning] 602-603: cratedb_toolkit/docs/settings.py#L602-L603
Added lines #L602 - L603 were not covered by tests


[warning] 605-606: cratedb_toolkit/docs/settings.py#L605-L606
Added lines #L605 - L606 were not covered by tests


[warning] 608-609: cratedb_toolkit/docs/settings.py#L608-L609
Added lines #L608 - L609 were not covered by tests


[warning] 612-613: cratedb_toolkit/docs/settings.py#L612-L613
Added lines #L612 - L613 were not covered by tests


[warning] 619-620: cratedb_toolkit/docs/settings.py#L619-L620
Added lines #L619 - L620 were not covered by tests


[warning] 622-622: cratedb_toolkit/docs/settings.py#L622
Added line #L622 was not covered by tests


[warning] 624-624: cratedb_toolkit/docs/settings.py#L624
Added line #L624 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Generic: Python 3.12 on OS ubuntu-latest
  • GitHub Check: Kinesis: Python 3.12 on OS ubuntu-latest
  • GitHub Check: Generic: Python 3.9 on OS ubuntu-latest
  • GitHub Check: CFR for OS windows-latest
  • GitHub Check: Kinesis: Python 3.9 on OS ubuntu-latest
  • GitHub Check: CFR for OS ubuntu-latest
  • GitHub Check: build-and-test
  • GitHub Check: Generic: Python 3.8 on OS ubuntu-latest
  • GitHub Check: CFR for OS macos-latest
  • GitHub Check: CFR for OS macos-13
🔇 Additional comments (3)
cratedb_toolkit/docs/cli.py (1)

49-51: No concerns – YAML format choice is consistent
The updated format choices and help text properly reflect the addition of YAML.

tests/docs/test_cli.py (2)

10-28: JSON test logic looks good
This test accurately validates the JSON output and checks for specific text in the result.


75-94: YAML test appears comprehensive
This test covers the new YAML format thoroughly by asserting the presence of expected text in the parsed YAML. Good job.

@amotl amotl force-pushed the docs-settings-stdout branch from b56efa7 to 79a90aa Compare April 13, 2025 14:22
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
cratedb_toolkit/docs/settings.py (3)

650-658: Consider improving error handling in write method

While the error handling for a None payload is good, consider making the method more user-friendly by automatically calling render() with a default format if payload is None instead of raising an error.

def write(self, path: Optional[Path] = None):
    if self.payload is None:
-        raise ValueError("No content to write. Please `render()` first.")
+        logger.info("No content to render, using default JSON format")
+        self.render("json")
    if path is None:
        print(self.payload)  # noqa: T201
    else:
        with open(path, "w", encoding="utf-8") as f:
            f.write(self.payload)
    return self

634-644: Consider using enum for format types

Using string literals for format types could lead to errors. Consider using an Enum to represent the supported formats for better type safety and IDE support.

+from enum import Enum, auto
+
+
+class OutputFormat(str, Enum):
+    """Output formats supported by the SettingsExtractor."""
+
+    JSON = "json"
+    YAML = "yaml"
+    MARKDOWN = "markdown"
+    SQL = "sql"
+

@dataclasses.dataclass
class SettingsExtractor:
    ...
-    def render(self, format_: str):
+    def render(self, format_: Union[str, OutputFormat]):
+        # Convert string format to enum if needed
+        if isinstance(format_, str):
+            try:
+                format_ = OutputFormat(format_.lower())
+            except ValueError:
+                raise ValueError(f"Unsupported format: {format_}. Choose from: {', '.join(f.value for f in OutputFormat)}")
+
        # Save to the file in selected format.
-        if format_ == "json":
+        if format_ == OutputFormat.JSON:
            self.payload = json.dumps(self.settings, indent=2, ensure_ascii=False)
-        elif format_ == "yaml":
+        elif format_ == OutputFormat.YAML:
            self.payload = yaml.dump(self.settings)
-        elif format_ == "markdown":
+        elif format_ == OutputFormat.MARKDOWN:
            self.payload = write_markdown_table(self.settings)
-        elif format_ == "sql":
+        elif format_ == OutputFormat.SQL:
            self.payload = write_sql_statements(self.settings)

619-620: Add type annotations to SettingsExtractor class fields

Consider adding more specific type annotations to improve code clarity.

@dataclasses.dataclass
class SettingsExtractor:
    """
    Extract CrateDB settings from documentation.
    Output in JSON, YAML, Markdown, or SQL format.
    """

-    settings: Dict[str, Dict[str, Any]] = dataclasses.field(default_factory=dict)
-    payload: Optional[str] = None
+    settings: Dict[str, Dict[str, Any]] = dataclasses.field(default_factory=dict)
+    payload: Optional[str] = None
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 619-620: cratedb_toolkit/docs/settings.py#L619-L620
Added lines #L619 - L620 were not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b56efa7 and 79a90aa.

📒 Files selected for processing (3)
  • cratedb_toolkit/docs/settings.py (4 hunks)
  • doc/docs-api.md (1 hunks)
  • tests/docs/test_cli.py (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
cratedb_toolkit/docs/settings.py

[warning] 15-16: cratedb_toolkit/docs/settings.py#L15-L16
Added lines #L15 - L16 were not covered by tests


[warning] 21-21: cratedb_toolkit/docs/settings.py#L21
Added line #L21 was not covered by tests


[warning] 25-25: cratedb_toolkit/docs/settings.py#L25
Added line #L25 was not covered by tests


[warning] 31-32: cratedb_toolkit/docs/settings.py#L31-L32
Added lines #L31 - L32 were not covered by tests


[warning] 48-48: cratedb_toolkit/docs/settings.py#L48
Added line #L48 was not covered by tests


[warning] 53-58: cratedb_toolkit/docs/settings.py#L53-L58
Added lines #L53 - L58 were not covered by tests


[warning] 61-61: cratedb_toolkit/docs/settings.py#L61
Added line #L61 was not covered by tests


[warning] 427-427: cratedb_toolkit/docs/settings.py#L427
Added line #L427 was not covered by tests


[warning] 434-435: cratedb_toolkit/docs/settings.py#L434-L435
Added lines #L434 - L435 were not covered by tests


[warning] 437-438: cratedb_toolkit/docs/settings.py#L437-L438
Added lines #L437 - L438 were not covered by tests


[warning] 441-445: cratedb_toolkit/docs/settings.py#L441-L445
Added lines #L441 - L445 were not covered by tests


[warning] 448-448: cratedb_toolkit/docs/settings.py#L448
Added line #L448 was not covered by tests


[warning] 450-453: cratedb_toolkit/docs/settings.py#L450-L453
Added lines #L450 - L453 were not covered by tests


[warning] 455-455: cratedb_toolkit/docs/settings.py#L455
Added line #L455 was not covered by tests


[warning] 458-462: cratedb_toolkit/docs/settings.py#L458-L462
Added lines #L458 - L462 were not covered by tests


[warning] 464-464: cratedb_toolkit/docs/settings.py#L464
Added line #L464 was not covered by tests


[warning] 466-468: cratedb_toolkit/docs/settings.py#L466-L468
Added lines #L466 - L468 were not covered by tests


[warning] 470-470: cratedb_toolkit/docs/settings.py#L470
Added line #L470 was not covered by tests


[warning] 472-472: cratedb_toolkit/docs/settings.py#L472
Added line #L472 was not covered by tests


[warning] 591-594: cratedb_toolkit/docs/settings.py#L591-L594
Added lines #L591 - L594 were not covered by tests


[warning] 596-599: cratedb_toolkit/docs/settings.py#L596-L599
Added lines #L596 - L599 were not covered by tests


[warning] 602-603: cratedb_toolkit/docs/settings.py#L602-L603
Added lines #L602 - L603 were not covered by tests


[warning] 605-606: cratedb_toolkit/docs/settings.py#L605-L606
Added lines #L605 - L606 were not covered by tests


[warning] 608-609: cratedb_toolkit/docs/settings.py#L608-L609
Added lines #L608 - L609 were not covered by tests


[warning] 612-613: cratedb_toolkit/docs/settings.py#L612-L613
Added lines #L612 - L613 were not covered by tests


[warning] 619-620: cratedb_toolkit/docs/settings.py#L619-L620
Added lines #L619 - L620 were not covered by tests


[warning] 622-622: cratedb_toolkit/docs/settings.py#L622
Added line #L622 was not covered by tests


[warning] 624-624: cratedb_toolkit/docs/settings.py#L624
Added line #L624 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Kinesis: Python 3.12 on OS ubuntu-latest
  • GitHub Check: Generic: Python 3.12 on OS ubuntu-latest
  • GitHub Check: Kinesis: Python 3.9 on OS ubuntu-latest
  • GitHub Check: Generic: Python 3.9 on OS ubuntu-latest
  • GitHub Check: CFR for OS windows-latest
  • GitHub Check: CFR for OS ubuntu-latest
  • GitHub Check: Generic: Python 3.8 on OS ubuntu-latest
  • GitHub Check: CFR for OS macos-latest
  • GitHub Check: build-and-test
  • GitHub Check: CFR for OS macos-13
🔇 Additional comments (15)
doc/docs-api.md (3)

5-8: Great addition of installation instructions!

Adding the installation section with uv pip install command makes it easier for users to get started with the Docs API.


10-11: Good structural improvement with the Usage section

Adding this section improves the document organization, making it more intuitive for readers.


14-15: Nice enhancement to document YAML format support

The documentation now correctly mentions the addition of YAML as an output format option, aligning with the implementation changes.

tests/docs/test_cli.py (5)

4-4: Good addition of yaml import for the new format support

The yaml import is correctly added to support the new YAML testing functionality.


10-28: Well-structured JSON format test

The test has been properly updated to explicitly test the JSON output format with appropriate assertions.


31-51: Good test coverage for Markdown format

This new test properly verifies the Markdown output format by checking for expected content patterns in the generated file.


53-73: Comprehensive SQL format testing

The SQL output format test is thorough and checks for both statement content and summary information.


75-94: Excellent YAML format test implementation

The test appropriately validates the new YAML output format by parsing the output with yaml.safe_load and checking for expected content.

cratedb_toolkit/docs/settings.py (7)

6-6: Updated documentation to include YAML format

Documentation string correctly updated to include YAML as a supported output format.


15-17: Good imports organization for the new functionality

The imports have been properly organized to include necessary modules for the expanded functionality, such as io, pathlib, and yaml.

Also applies to: 21-21, 25-25

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 15-16: cratedb_toolkit/docs/settings.py#L15-L16
Added lines #L15 - L16 were not covered by tests


30-32: Improved logging configuration

Using logger = logging.getLogger(__name__) is a best practice that improves modularity by using the module's name for logging.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 31-32: cratedb_toolkit/docs/settings.py#L31-L32
Added lines #L31 - L32 were not covered by tests


53-58: Enhanced error handling and progress reporting

The improved progress reporting and explicit error handling for HTTP responses makes the code more robust.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 53-58: cratedb_toolkit/docs/settings.py#L53-L58
Added lines #L53 - L58 were not covered by tests


427-472: Refactored markdown table generation to return a string

The function now correctly returns a string instead of writing directly to a file, which improves separation of concerns and flexibility in the API.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 427-427: cratedb_toolkit/docs/settings.py#L427
Added line #L427 was not covered by tests


[warning] 434-435: cratedb_toolkit/docs/settings.py#L434-L435
Added lines #L434 - L435 were not covered by tests


[warning] 437-438: cratedb_toolkit/docs/settings.py#L437-L438
Added lines #L437 - L438 were not covered by tests


[warning] 441-445: cratedb_toolkit/docs/settings.py#L441-L445
Added lines #L441 - L445 were not covered by tests


[warning] 448-448: cratedb_toolkit/docs/settings.py#L448
Added line #L448 was not covered by tests


[warning] 450-453: cratedb_toolkit/docs/settings.py#L450-L453
Added lines #L450 - L453 were not covered by tests


[warning] 455-455: cratedb_toolkit/docs/settings.py#L455
Added line #L455 was not covered by tests


[warning] 458-462: cratedb_toolkit/docs/settings.py#L458-L462
Added lines #L458 - L462 were not covered by tests


[warning] 464-464: cratedb_toolkit/docs/settings.py#L464
Added line #L464 was not covered by tests


[warning] 466-468: cratedb_toolkit/docs/settings.py#L466-L468
Added lines #L466 - L468 were not covered by tests


[warning] 470-470: cratedb_toolkit/docs/settings.py#L470
Added line #L470 was not covered by tests


[warning] 472-472: cratedb_toolkit/docs/settings.py#L472
Added line #L472 was not covered by tests


591-609: Well-implemented SQL statement writer

The new function generates SQL statements in a clean, formatted way and returns a string, consistent with the overall design improvements.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 591-594: cratedb_toolkit/docs/settings.py#L591-L594
Added lines #L591 - L594 were not covered by tests


[warning] 596-599: cratedb_toolkit/docs/settings.py#L596-L599
Added lines #L596 - L599 were not covered by tests


[warning] 602-603: cratedb_toolkit/docs/settings.py#L602-L603
Added lines #L602 - L603 were not covered by tests


[warning] 605-606: cratedb_toolkit/docs/settings.py#L605-L606
Added lines #L605 - L606 were not covered by tests


[warning] 608-609: cratedb_toolkit/docs/settings.py#L608-L609
Added lines #L608 - L609 were not covered by tests


612-659: Great OOP design with the SettingsExtractor class

The introduction of this class with a fluent interface pattern (method chaining) significantly improves the code organization and usability. The class encapsulates extraction, rendering, and output writing in a clear and maintainable way.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 612-613: cratedb_toolkit/docs/settings.py#L612-L613
Added lines #L612 - L613 were not covered by tests


[warning] 619-620: cratedb_toolkit/docs/settings.py#L619-L620
Added lines #L619 - L620 were not covered by tests


[warning] 622-622: cratedb_toolkit/docs/settings.py#L622
Added line #L622 was not covered by tests


[warning] 624-624: cratedb_toolkit/docs/settings.py#L624
Added line #L624 was not covered by tests

Comment on lines +591 to +610
def write_sql_statements(settings) -> str:
f = io.StringIO()
f.write("-- CrateDB Runtime Configurable Settings\n")
f.write("-- Generated by settings extractor\n\n")

This tool scrapes the CrateDB documentation to extract configuration settings,
their default values, descriptions, and runtime configurability status.
count = 0
for _, setting_info in sorted(settings.items()):
if setting_info["runtime_configurable"] and "stmt" in setting_info:
stmt = setting_info["stmt"]

Examples:
# Ensure statement ends with semicolon
if not stmt.endswith(";"):
stmt += ";"

# Extract settings to JSON (default)
python soup2.py
f.write(f"{stmt}\n")
count += 1

# Extract settings to Markdown
python soup2.py --format markdown
f.write(f"\n-- Total statements: {count}\n")
return f.getvalue()
Copy link
Copy Markdown

@coderabbitai coderabbitai bot Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Improve test coverage for new functionality

The static analysis hints indicate that many of the changes in this file are not covered by tests. Consider adding more unit tests to ensure the new functionality works as expected, especially for the SettingsExtractor class methods.


🏁 Script executed:

#!/bin/bash
# Look for existing test coverage of SettingsExtractor class
echo "Checking for existing tests of SettingsExtractor class..."
rg "SettingsExtractor" tests/

Length of output: 154


Action Required: Enhance Test Coverage for SettingsExtractor Functionality

  • The current test suite does not appear to include any tests for the SettingsExtractor class methods, as confirmed by the shell script search.
  • Please add comprehensive unit tests to validate:
    • The behavior of methods within the SettingsExtractor class.
    • Specific logic in the write_sql_statements function (e.g., ensuring statements end with a semicolon and counting the generated statements correctly).
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 591-594: cratedb_toolkit/docs/settings.py#L591-L594
Added lines #L591 - L594 were not covered by tests


[warning] 596-599: cratedb_toolkit/docs/settings.py#L596-L599
Added lines #L596 - L599 were not covered by tests


[warning] 602-603: cratedb_toolkit/docs/settings.py#L602-L603
Added lines #L602 - L603 were not covered by tests


[warning] 605-606: cratedb_toolkit/docs/settings.py#L605-L606
Added lines #L605 - L606 were not covered by tests


[warning] 608-609: cratedb_toolkit/docs/settings.py#L608-L609
Added lines #L608 - L609 were not covered by tests

Copy link
Copy Markdown
Member Author

@amotl amotl Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai: That can be done in a subsequent iteration. Currently, it is good enough to validate the code by invoking the CLI subcommands, and validate that the output is reasonably correct.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amotl I understand your approach. Using CLI subcommand tests to validate the functionality is a practical solution for the current iteration, especially since they verify the actual output is correct. More granular unit tests for the SettingsExtractor class can be added in a subsequent PR when needed.

 ( \
  \ \
   \ \
    \ \
     \ \
      \ \
      /  \
     /    \
    /_    _\
    (•)  (•)
     \    /
     /    \
    /      \
   /        \
  /__    ___\
     /  \
     \__/  thoughtful bunny

✏️ Learnings added
Learnt from: amotl
PR: crate/cratedb-toolkit#400
File: cratedb_toolkit/docs/settings.py:0-0
Timestamp: 2025-04-13T14:43:29.811Z
Learning: For the cratedb-toolkit project, functional validation through CLI commands is preferred as the initial testing approach, with more granular unit tests being deferred to subsequent iterations when necessary.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@amotl amotl force-pushed the docs-settings-stdout branch from 79a90aa to 238c917 Compare April 13, 2025 14:34
@amotl amotl marked this pull request as ready for review April 13, 2025 14:50
@amotl amotl merged commit 54c0c62 into main Apr 13, 2025
19 checks passed
@amotl amotl deleted the docs-settings-stdout branch April 13, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant