-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for report plugins (#18)
- Loading branch information
1 parent
f7f562b
commit 91da3d3
Showing
8 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from pathlib import Path | ||
from typing import List | ||
|
||
from poetry_snakemake_plugin.common import ScaffoldSnakemakePluginCommandBase | ||
|
||
|
||
class ScaffoldSnakemakeReportPluginCommand(ScaffoldSnakemakePluginCommandBase): | ||
name = "scaffold-snakemake-report-plugin" | ||
description = ( | ||
"Scaffolds a snakemake report plugin by adding recommended " | ||
"dependencies and code snippets." | ||
) | ||
|
||
def get_templates(self, module_path: Path, tests_path: Path) -> List[str]: | ||
return [ | ||
("report-plugins/init.py", module_path / "__init__.py"), | ||
("report-plugins/tests.py", tests_path / "tests.py"), | ||
] | ||
|
||
def get_plugin_type(self) -> str: | ||
return "report" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Optional | ||
|
||
from snakemake_interface_common.exceptions import WorkflowError # noqa: F401 | ||
from snakemake_interface_report_plugins.reporter import ReporterBase | ||
from snakemake_interface_report_plugins.settings import ReportSettingsBase | ||
|
||
|
||
# Optional: | ||
# Define additional settings for your reporter. | ||
# They will occur in the Snakemake CLI as --report-<reporter-name>-<param-name> | ||
# Omit this class if you don't need any. | ||
# Make sure that all defined fields are Optional (or bool) and specify a default value | ||
# of None (or False) or anything else that makes sense in your case. | ||
@dataclass | ||
class ReportSettings(ReportSettingsBase): | ||
myparam: Optional[int] = field( | ||
default=None, | ||
metadata={ | ||
"help": "Some help text", | ||
# Optionally request that setting is also available for specification | ||
# via an environment variable. The variable will be named automatically as | ||
# SNAKEMAKE_REPORT_<reporter-name>_<param-name>, all upper case. | ||
# This mechanism should ONLY be used for passwords and usernames. | ||
# For other items, we rather recommend to let people use a profile | ||
# for setting defaults | ||
# (https://snakemake.readthedocs.io/en/stable/executing/cli.html#profiles). | ||
"env_var": False, | ||
# Optionally specify a function that parses the value given by the user. | ||
# This is useful to create complex types from the user input. | ||
"parse_func": ..., | ||
# If a parse_func is specified, you also have to specify an unparse_func | ||
# that converts the parsed value back to a string. | ||
"unparse_func": ..., | ||
# Optionally specify that setting is required when the reporter is in use. | ||
"required": True, | ||
}, | ||
) | ||
|
||
|
||
# Required: | ||
# Implementation of your reporter | ||
class Reporter(ReporterBase): | ||
def __post_init__(self): | ||
# initialize additional attributes | ||
# Do not overwrite the __init__ method as this is kept in control of the base | ||
# class in order to simplify the update process. | ||
# See https://github.com/snakemake/snakemake-interface-report-plugins/snakemake_interface_report_plugins/reporter.py # noqa: E501 | ||
# for attributes of the base class. | ||
# In particular, the settings of above ReportSettings class are accessible via | ||
# self.settings. | ||
... | ||
|
||
def render(self): | ||
# Render the report, using attributes of the base class. | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from typing import Optional | ||
import snakemake.common.tests | ||
from snakemake_interface_report_plugins.settings import ReportSettingsBase | ||
|
||
|
||
# Check out the base classes found here for all possible options and methods: | ||
# https://github.com/snakemake/snakemake/blob/main/snakemake/common/tests/__init__.py | ||
class TestWorkflowsBase(snakemake.common.tests.TestReportBase): | ||
__test__ = True | ||
|
||
def get_reporter(self) -> str: | ||
return "{{plugin_name}}" | ||
|
||
def get_report_settings(self) -> Optional[ReportSettingsBase]: | ||
# instantiate ReportSettings of this plugin as appropriate | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters