Skip to content

Conversation

@LKress
Copy link
Contributor

@LKress LKress commented Mar 16, 2025

This is required, to allow custom metadata in the report (snakemake/snakemake#3452).

Summary by CodeRabbit

  • New Features
    • Added support for including optional metadata when creating reports.

@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2025

📝 Walkthrough

Walkthrough

The constructor of the ReporterBase class in snakemake_interface_report_plugins/reporter.py was updated to accept an optional metadata parameter typed as Optional[Dict[str, Union[str, int, float, List[str], List[int], List[float]]]] defaulting to None. The parameter is assigned directly to self.metadata. Imports were updated accordingly.

Changes

File(s) Change Summary
snakemake_interface_report_plugins/reporter.py Added optional metadata parameter with complex type hint to ReporterBase.__init__; assigned metadata to self.metadata; updated imports to include Dict, Optional, and Union from typing.

Possibly related issues

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes


📜 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 214535a and 09e170a.

📒 Files selected for processing (1)
  • snakemake_interface_report_plugins/reporter.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • snakemake_interface_report_plugins/reporter.py
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@LKress LKress changed the title feat:Add the metadata interface to the reporter class feat: add the metadata interface to the reporter class Mar 16, 2025
@LKress LKress changed the title feat: add the metadata interface to the reporter class feat: Add the metadata interface to the reporter class Mar 26, 2025
Copy link

@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

♻️ Duplicate comments (1)
snakemake_interface_report_plugins/reporter.py (1)

31-33: Fix the mutable default argument issue.

The current implementation uses a mutable default argument {}, which is flagged by static analysis and violates Python best practices. Based on the past review comments, this should use None as the default and initialize an empty dict inside the constructor.

Apply this diff to fix the mutable default argument:

-        metadata: Optional[
-            Dict[str, Union[str, int, float, List[str], List[int], List[float]]]
-        ] = {},
+        metadata: Optional[
+            Dict[str, Union[str, int, float, List[str], List[int], List[float]]]
+        ] = None,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 592243d and 0370982.

📒 Files selected for processing (1)
  • snakemake_interface_report_plugins/reporter.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

🪛 Ruff (0.11.9)
snakemake_interface_report_plugins/reporter.py

33-33: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)


53-54: ReporterBase.__post_init__ is an empty method in an abstract base class, but has no abstract decorator

(B027)

🪛 GitHub Actions: CI
snakemake_interface_report_plugins/reporter.py

[error] 46-46: flake8: line too long (115 > 88 characters) (E501)

🔇 Additional comments (4)
snakemake_interface_report_plugins/reporter.py (4)

8-8: LGTM: Import statement properly updated.

The import statement correctly adds the necessary typing components for the metadata interface implementation.


49-49: LGTM: Metadata assignment is correct.

The assignment of the validated metadata to the instance attribute is properly implemented.


60-67: LGTM: Helper function is well-implemented.

The is_valid_flat_value function correctly validates individual values according to the specified type constraints.


69-79: LGTM: Validation function is robust.

The validate_flat_dict function properly validates the dictionary structure, checking both key types and value types using the helper function.

Copy link

@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

♻️ Duplicate comments (2)
snakemake_interface_report_plugins/reporter.py (2)

31-33: Fix mutable default argument to align with past review feedback.

The current implementation uses a mutable default argument, which violates Python best practices and contradicts past review comments requesting a keyword arg with None default.

Apply this diff to fix the mutable default argument:

-        metadata: Optional[
-            Dict[str, Union[str, int, float, List[str], List[int], List[float]]]
-        ] = {},
+        metadata: Optional[
+            Dict[str, Union[str, int, float, List[str], List[int], List[float]]]
+        ] = None,

43-52: Fix line length violation and handle None default.

The validation logic has line length issues and needs to handle the None default case.

Apply this diff to fix both issues:

-        # ensure that metadata is a key value dictionary
-        if not validate_flat_dict(metadata):
-            raise TypeError(
-                (
-                    "Metadata must be single level "
-                    "dict[str, str | int | float | list[str] | list[int] | list[float]]]"
-                )
-            )
-
-        self.metadata = metadata
+        # ensure that metadata is a key value dictionary
+        if metadata is None:
+            metadata = {}
+        if not validate_flat_dict(metadata):
+            raise TypeError(
+                "Metadata must be single level "
+                "dict[str, str | int | float | "
+                "list[str] | list[int] | list[float]]]"
+            )
+
+        self.metadata = metadata
🧹 Nitpick comments (1)
snakemake_interface_report_plugins/reporter.py (1)

56-57: Consider making __post_init__ abstract if subclasses should implement it.

The empty __post_init__ method could be made abstract if subclasses are expected to provide implementations, or add a docstring explaining its purpose as an optional hook.

If subclasses should implement this method:

+    @abstractmethod
     def __post_init__(self):
-        pass
+        ...
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0370982 and e487225.

📒 Files selected for processing (1)
  • snakemake_interface_report_plugins/reporter.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

🪛 Ruff (0.11.9)
snakemake_interface_report_plugins/reporter.py

33-33: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)


56-57: ReporterBase.__post_init__ is an empty method in an abstract base class, but has no abstract decorator

(B027)

🪛 GitHub Actions: CI
snakemake_interface_report_plugins/reporter.py

[error] 48-48: flake8: line too long (89 > 88 characters) (E501)

🔇 Additional comments (2)
snakemake_interface_report_plugins/reporter.py (2)

8-8: LGTM! Import additions are appropriate.

The added typing imports are necessary for the metadata type annotations.


63-82: LGTM! Helper functions are well-implemented.

The validation functions correctly enforce the metadata constraints:

  • is_valid_flat_value properly checks for valid types and lists
  • validate_flat_dict ensures dictionary structure with string keys
  • Logic is comprehensive and handles edge cases appropriately

Copy link

@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

♻️ Duplicate comments (2)
snakemake_interface_report_plugins/reporter.py (2)

31-33: Fix the mutable default argument issue.

The use of {} as a default argument creates a mutable default, which can lead to shared state issues. This was flagged in previous reviews and by static analysis.

Apply this diff to fix the mutable default:

-        metadata: Optional[
-            Dict[str, Union[str, int, float, List[str], List[int], List[float]]]
-        ] = {},
+        metadata: Optional[
+            Dict[str, Union[str, int, float, List[str], List[int], List[float]]]
+        ] = None,

43-51: Handle None default and improve validation logic.

The validation logic doesn't properly handle the None default value that should be used instead of the mutable default. This was identified in previous reviews.

Apply this diff to fix the None handling:

-        # ensure that metadata is a key value dictionary
-        if not validate_flat_dict(metadata):
-            raise TypeError(
-                (
-                    "Metadata must be single level "
-                    "dict[str, str | int | float | "
-                    "list[str] | list[int] | list[float]]]"
-                )
-            )
+        # ensure that metadata is a key value dictionary
+        if metadata is None:
+            metadata = {}
+        if not validate_flat_dict(metadata):
+            raise TypeError(
+                (
+                    "Metadata must be single level "
+                    "dict[str, str | int | float | "
+                    "list[str] | list[int] | list[float]]]"
+                )
+            )
🧹 Nitpick comments (1)
snakemake_interface_report_plugins/reporter.py (1)

57-58: Consider making the empty __post_init__ method abstract.

The empty __post_init__ method in an abstract base class should be decorated with @abstractmethod if subclasses are expected to implement it, or removed if it's not needed.

If subclasses should implement this method, apply this diff:

+    @abstractmethod
     def __post_init__(self):
-        pass
+        ...

If this method is not needed, consider removing it entirely.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e487225 and 214535a.

📒 Files selected for processing (1)
  • snakemake_interface_report_plugins/reporter.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

🪛 Ruff (0.11.9)
snakemake_interface_report_plugins/reporter.py

33-33: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)


57-58: ReporterBase.__post_init__ is an empty method in an abstract base class, but has no abstract decorator

(B027)

🔇 Additional comments (4)
snakemake_interface_report_plugins/reporter.py (4)

8-8: LGTM on the import additions.

The new typing imports are correctly added to support the enhanced type annotations for the metadata parameter.


53-53: LGTM on the metadata assignment.

The assignment is correct and will work properly once the None handling is fixed in the validation logic above.


64-71: LGTM on the value validation helper function.

The is_valid_flat_value function correctly validates individual values and lists of allowed types. The logic properly checks for the supported types (str, int, float) and validates that lists contain only these types.


73-83: LGTM on the dictionary validation helper function.

The validate_flat_dict function correctly validates the entire dictionary structure, ensuring all keys are strings and all values pass the flat value validation. The logic is sound and matches the type constraints defined in the constructor.

@johanneskoester johanneskoester changed the title feat: Add the metadata interface to the reporter class feat: add the metadata interface to the reporter class Jul 29, 2025
@johanneskoester johanneskoester merged commit 447bec4 into snakemake:main Jul 29, 2025
7 checks passed
johanneskoester pushed a commit that referenced this pull request Jul 29, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.2.0](v1.1.2...v1.2.0)
(2025-07-29)


### Features

* add the metadata interface to the reporter class
([#6](#6))
([447bec4](447bec4))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants