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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions src/snakemake_interface_logger_plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,53 @@
__license__ = "MIT"

from typing import Optional
from snakemake_interface_logger_plugins.settings import LogHandlerSettingsBase
from snakemake_interface_logger_plugins.settings import (
LogHandlerSettingsBase,
OutputSettingsLoggerInterface,
)
from abc import ABC, abstractmethod
from logging import Handler


class LogHandlerBase(Handler):
class LogHandlerBase(ABC, Handler):
def __init__(
self,
common_settings: OutputSettingsLoggerInterface,
settings: Optional[LogHandlerSettingsBase],
) -> None:
self.common_settings = common_settings
self.settings = settings
self.__post__init()
self.__post__init__()
if self.writes_to_stream and self.writes_to_file:
raise ValueError("A handler cannot write to both stream and file")

def __post__init(self) -> None:
def __post__init__(self) -> None:
pass

@property
@abstractmethod
def writes_to_stream(self) -> bool:
"""
Whether this plugin writes to stderr/stdout
"""

@property
@abstractmethod
def writes_to_file(self) -> bool:
"""
Whether this plugin writes to a file
"""

@property
@abstractmethod
def has_filter(self) -> bool:
"""
Whether this plugin attaches its own filter
"""

@property
@abstractmethod
def has_formatter(self) -> bool:
"""
Whether this plugin attaches its own formatter
"""
6 changes: 3 additions & 3 deletions src/snakemake_interface_logger_plugins/registry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class LoggerPluginRegistry(PluginRegistryBase):
"""This class is a singleton that holds all registered executor plugins."""
"""This class is a singleton that holds all registered logger plugins."""

@property
def module_prefix(self) -> str:
Expand All @@ -34,7 +34,7 @@ def load_plugin(self, name: str, module: types.ModuleType) -> Plugin:

return Plugin(
_name=name,
logger_plugin=module.LoggerPlugin,
log_handler=module.LogHandler,
_logger_settings_cls=getattr(module, "LogHandlerSettings", None),
)

Expand All @@ -45,7 +45,7 @@ def expected_attributes(self) -> Mapping[str, AttributeType]:
mode=AttributeMode.OPTIONAL,
kind=AttributeKind.CLASS,
),
"LoggerPlugin": AttributeType(
"LogHandler": AttributeType(
cls=LogHandlerBase,
mode=AttributeMode.REQUIRED,
kind=AttributeKind.CLASS,
Expand Down
15 changes: 15 additions & 0 deletions src/snakemake_interface_logger_plugins/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
import snakemake_interface_common.plugin_registry.plugin


from abc import ABC
from typing import Optional, Sequence


class OutputSettingsLoggerInterface(ABC):
printshellcmds: bool
nocolor: bool
quiet: Optional[Sequence]
debug_dag: bool
verbose: bool
show_failed_logs: bool
stdout: bool
dryrun: bool


@dataclass
class LogHandlerSettingsBase(
snakemake_interface_common.plugin_registry.plugin.SettingsBase
Expand Down