Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add OutputSettingsLoggerInterface and abstract methods to LogHandlerBase #11

Merged
merged 4 commits into from
Feb 18, 2025

Conversation

cademirch
Copy link
Collaborator

@cademirch cademirch commented Feb 13, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new abstract class for logging settings, enhancing the structure for managing configurations.
    • Added new abstract properties to the logging handler base class to define logging behavior.
  • Refactor

    • Improved internal naming for clarity in logging without affecting current functionality.
    • Updated class and method signatures for better clarity and functionality.

Copy link

coderabbitai bot commented Feb 13, 2025

📝 Walkthrough

Walkthrough

The changes involve modifications to the LoggerPluginRegistry, LogHandlerBase, and the introduction of OutputSettingsLoggerInterface. The LoggerPluginRegistry class's docstring was updated for clarity, and the load_plugin method's parameter was renamed from logger_plugin to log_handler. The LogHandlerBase class was established as an abstract base class with new properties and a constructor check. Additionally, a new abstract class, OutputSettingsLoggerInterface, was introduced to define logging settings. These updates enhance the clarity and structure of the logging framework.

Changes

File(s) Change Summary
src/snakemake_interface_logger_plugins/registry/__init__.py Updated the LoggerPluginRegistry class docstring to clarify it holds registered logger plugins. Changed the load_plugin method parameter from logger_plugin to log_handler. Updated expected attributes from "LoggerPlugin" to "LogHandler".
src/snakemake_interface_logger_plugins/base.py Introduced LogHandlerBase as an abstract base class inheriting from ABC and Handler. Added a common_settings parameter and new abstract properties: writes_to_stream, writes_to_file, has_filter, and has_formatter. Corrected the __post__init method signature.
src/snakemake_interface_logger_plugins/settings.py Added a new abstract class OutputSettingsLoggerInterface inheriting from ABC, defining several logging-related attributes without initialization. The existing LogHandlerSettingsBase class remains unchanged.

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 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. (Beta)
  • @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.

…thods to communicate log plugin behavior

new argument to LogHandlerBase init
@cademirch cademirch changed the title fix: fix plugin init in registry feat: add loggerSettingsInterface and abstract methods to LogHandlerBase Feb 18, 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: 0

🧹 Nitpick comments (2)
src/snakemake_interface_logger_plugins/base.py (1)

18-25: Constructor logic is cohesive.
Storing common_settings and immediately checking for conflicting I/O modes (stream vs. file) is a good design choice. Consider clarifying the error message to guide developers on valid usage or referencing documentation about valid configurations.

src/snakemake_interface_logger_plugins/settings.py (1)

15-23: Interface attributes lacking default values.
Defining these as bare attributes in an ABC is valid. If you need to enforce initialization or specific default behaviors in child classes, consider making them abstract properties or providing constructors in subclasses.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6990931 and 0c1adbe.

📒 Files selected for processing (3)
  • src/snakemake_interface_logger_plugins/base.py (1 hunks)
  • src/snakemake_interface_logger_plugins/registry/__init__.py (2 hunks)
  • src/snakemake_interface_logger_plugins/settings.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/snakemake_interface_logger_plugins/registry/init.py
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Do not try to improve formatting. Do not suggest ...

**/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

  • src/snakemake_interface_logger_plugins/base.py
  • src/snakemake_interface_logger_plugins/settings.py
🪛 GitHub Actions: CI
src/snakemake_interface_logger_plugins/base.py

[error] 1-1: Ruff formatting check failed. Run 'ruff format' to fix code style issues in this file.

🔇 Additional comments (9)
src/snakemake_interface_logger_plugins/base.py (8)

1-1: Address the Ruff formatting error.
The pipeline indicates that a Ruff formatting check has failed. Please run ruff format (or your preferred formatting command) to ensure the file meets the project's code style standards.

🧰 Tools
🪛 Ruff (0.8.2)

1-1: No such file or directory (os error 2)

(E902)

🪛 GitHub Actions: CI

[error] 1-1: Ruff formatting check failed. Run 'ruff format' to fix code style issues in this file.


7-11: Imports look correct.
These imports align well with the usage below and introduce the necessary base interfaces and methods.


15-15: Marking the class as an abstract base class is appropriate.
Making LogHandlerBase derive from ABC clarifies that subclasses must implement the required abstract methods and properties.


27-27: Utility method for post-initialization.
__post__init__ provides flexibility for subclasses to extend setup logic. Good forward-thinking design.


30-35: Abstract property for stream-writing logic is well-defined.
Ensuring each subclass implements whether it writes to stdout/stderr fosters clarity in the logging pipeline.


37-42: Abstract property for file-writing is well-defined.
Similar to writes_to_stream, this property clarifies log file handling requirements for subclasses.


44-49: Filtering responsibility placed on subclasses.
The has_filter property is a clean way to indicate whether a subclass is responsible for its own log filtering.


51-56: Formatter presence determined by subclass.
The has_formatter property neatly separates concerns, signaling that subclasses can specify custom formatting responsibilities.

src/snakemake_interface_logger_plugins/settings.py (1)

11-13: Additional imports are appropriate.
The ABC import aligns with the creation of an abstract interface, and using Optional and Sequence is valid for these attributes.

@cademirch
Copy link
Collaborator Author

Hi @johanneskoester I've made some changes here to align with changes made in snakemake/snakemake#3107.

I think its worth giving the LogHandlerBase access to Snakemake's OutputSettings, so that LogHandlerPlugins can define their own formatters and filters. Thus I added LoggerSettingsInterface to the settings here, and have OutputSettings inherit from it.

We could just make a LogSettings class in snakemake.setttings.types, but I opted against that since that would require a fair bit more refactoring in snakemake.api since OutputSettings is used and referenced fairly often. The main tradeoff is semantic clarity (OutputSettings vs LogSettings) vs code maintainability.

I've also added some abstract methods to LogHandlerBase so that plugins can communicate their behavior easily and can be added to the main logger accordingly.

Copy link
Contributor

@johanneskoester johanneskoester left a comment

Choose a reason for hiding this comment

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

Nice! Some things below, and please remember to format with ruff.

renamed plugin attributes and settings interface
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

🧹 Nitpick comments (1)
src/snakemake_interface_logger_plugins/base.py (1)

27-28: Document the purpose of the empty post-init method.

Consider adding a docstring to explain why this method exists and when subclasses should override it.

     def __post__init__(self) -> None:
+        """Hook for subclasses to perform additional initialization after __init__.
+
+        This method is called at the end of __init__ and can be overridden by subclasses
+        to perform any necessary setup without having to override __init__.
+        """
         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 0c1adbe and 9c7020d.

📒 Files selected for processing (3)
  • src/snakemake_interface_logger_plugins/base.py (1 hunks)
  • src/snakemake_interface_logger_plugins/registry/__init__.py (3 hunks)
  • src/snakemake_interface_logger_plugins/settings.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/snakemake_interface_logger_plugins/registry/init.py
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Do not try to improve formatting. Do not suggest ...

**/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

  • src/snakemake_interface_logger_plugins/settings.py
  • src/snakemake_interface_logger_plugins/base.py
🔇 Additional comments (3)
src/snakemake_interface_logger_plugins/settings.py (1)

15-24: LGTM!

The interface is well-structured with appropriate type annotations for all attributes. The class follows the naming convention and correctly inherits from ABC.

src/snakemake_interface_logger_plugins/base.py (2)

15-26: LGTM!

The class is well-structured with appropriate inheritance and constructor implementation. The validation check for mutually exclusive behaviors (writes_to_stream and writes_to_file) is a good safeguard.


30-56: LGTM!

The abstract properties are well-defined with clear docstrings and appropriate return type annotations. They effectively communicate the expected behavior of logger plugins.

@cademirch
Copy link
Collaborator Author

Nice! Some things below, and please remember to format with ruff.

Thanks, fixed! And will do - sorry about that.

@johanneskoester johanneskoester changed the title feat: add loggerSettingsInterface and abstract methods to LogHandlerBase feat: add OutputSettingsLoggerInterface and abstract methods to LogHandlerBase Feb 18, 2025
@johanneskoester johanneskoester merged commit f659f82 into main Feb 18, 2025
7 checks passed
@johanneskoester johanneskoester deleted the fix-registry branch February 18, 2025 15:13
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