Skip to content

Commit f659f82

Browse files
authored
feat: add OutputSettingsLoggerInterface and abstract methods to LogHandlerBase (#11)
* fix: fix plugin init in registry * refactor: fix typo in docstring * feat: add LoggerSettingsInterface for shared settings, add abstractmethods to communicate log plugin behavior new argument to LogHandlerBase init * refactor: rename settings interface, rename plugin attritbute renamed plugin attributes and settings interface
1 parent df09b6a commit f659f82

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

src/snakemake_interface_logger_plugins/base.py

+40-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,53 @@
44
__license__ = "MIT"
55

66
from typing import Optional
7-
from snakemake_interface_logger_plugins.settings import LogHandlerSettingsBase
7+
from snakemake_interface_logger_plugins.settings import (
8+
LogHandlerSettingsBase,
9+
OutputSettingsLoggerInterface,
10+
)
11+
from abc import ABC, abstractmethod
812
from logging import Handler
913

1014

11-
class LogHandlerBase(Handler):
15+
class LogHandlerBase(ABC, Handler):
1216
def __init__(
1317
self,
18+
common_settings: OutputSettingsLoggerInterface,
1419
settings: Optional[LogHandlerSettingsBase],
1520
) -> None:
21+
self.common_settings = common_settings
1622
self.settings = settings
17-
self.__post__init()
23+
self.__post__init__()
24+
if self.writes_to_stream and self.writes_to_file:
25+
raise ValueError("A handler cannot write to both stream and file")
1826

19-
def __post__init(self) -> None:
27+
def __post__init__(self) -> None:
2028
pass
29+
30+
@property
31+
@abstractmethod
32+
def writes_to_stream(self) -> bool:
33+
"""
34+
Whether this plugin writes to stderr/stdout
35+
"""
36+
37+
@property
38+
@abstractmethod
39+
def writes_to_file(self) -> bool:
40+
"""
41+
Whether this plugin writes to a file
42+
"""
43+
44+
@property
45+
@abstractmethod
46+
def has_filter(self) -> bool:
47+
"""
48+
Whether this plugin attaches its own filter
49+
"""
50+
51+
@property
52+
@abstractmethod
53+
def has_formatter(self) -> bool:
54+
"""
55+
Whether this plugin attaches its own formatter
56+
"""

src/snakemake_interface_logger_plugins/registry/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
class LoggerPluginRegistry(PluginRegistryBase):
26-
"""This class is a singleton that holds all registered executor plugins."""
26+
"""This class is a singleton that holds all registered logger plugins."""
2727

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

3535
return Plugin(
3636
_name=name,
37-
logger_plugin=module.LoggerPlugin,
37+
log_handler=module.LogHandler,
3838
_logger_settings_cls=getattr(module, "LogHandlerSettings", None),
3939
)
4040

@@ -45,7 +45,7 @@ def expected_attributes(self) -> Mapping[str, AttributeType]:
4545
mode=AttributeMode.OPTIONAL,
4646
kind=AttributeKind.CLASS,
4747
),
48-
"LoggerPlugin": AttributeType(
48+
"LogHandler": AttributeType(
4949
cls=LogHandlerBase,
5050
mode=AttributeMode.REQUIRED,
5151
kind=AttributeKind.CLASS,

src/snakemake_interface_logger_plugins/settings.py

+15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
import snakemake_interface_common.plugin_registry.plugin
99

1010

11+
from abc import ABC
12+
from typing import Optional, Sequence
13+
14+
15+
class OutputSettingsLoggerInterface(ABC):
16+
printshellcmds: bool
17+
nocolor: bool
18+
quiet: Optional[Sequence]
19+
debug_dag: bool
20+
verbose: bool
21+
show_failed_logs: bool
22+
stdout: bool
23+
dryrun: bool
24+
25+
1126
@dataclass
1227
class LogHandlerSettingsBase(
1328
snakemake_interface_common.plugin_registry.plugin.SettingsBase

0 commit comments

Comments
 (0)