Skip to content

Commit a1e3123

Browse files
feat: add support for env_var specification in ExecutorSettings
1 parent 120beb9 commit a1e3123

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ from snakemake_interface_executor_plugins import ExecutorSettingsBase, CommonSet
1515
# Omit this class if you don't need any.
1616
@dataclass
1717
class ExecutorSettings:
18-
myparam: int=field(default=None, metadata={"help": "Some help text"})
18+
myparam: int=field(
19+
default=None,
20+
metadata={
21+
"help": "Some help text",
22+
# optionally request that argument is also available for specification
23+
# via an environment variable. The variable will be named automatically as
24+
# SNAKEMAKE_<executor-name>_<param-name>, all upper case.
25+
"env_var": True
26+
}
27+
)
1928

2029

2130
# Required:
@@ -36,13 +45,11 @@ class Executor(RemoteExecutor)
3645
def __init__(
3746
self,
3847
workflow: WorkflowExecutorInterface,
39-
dag: DAGExecutorInterface,
4048
logger: LoggerExecutorInterface,
4149

4250
):
4351
super().__init__(
4452
workflow,
45-
dag,
4653
logger,
4754
executor_settings,
4855
# configure behavior of RemoteExecutor below

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ readme = "README.md"
88
version = "1.2.0"
99

1010
[tool.poetry.dependencies]
11-
argparse-dataclass = "^2.0.0"
11+
argparse-dataclass = {git = "https://github.com/johanneskoester/argparse_dataclass.git"}
1212
python = "^3.9"
1313
throttler = "^1.2.2"
1414
snakemake-interface-common = "^1.3.1"

snakemake_interface_executor_plugins/registry/plugin.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
__email__ = "johannes.koester@uni-due.de"
44
__license__ = "MIT"
55

6-
from argparse_dataclass import _add_dataclass_options, fields
6+
from argparse_dataclass import field_to_argument_args, field_to_argument_kwargs, fields
77
from dataclasses import dataclass
88
from typing import Optional, Type
99
import copy
@@ -53,9 +53,15 @@ def register_cli_args(self, argparser):
5353
field.name = prefixed_name
5454
dc.__dataclass_fields__[field.name] = field
5555

56-
# When we get here, we have a namespaced dataclass.
57-
# If there is overlap in snakemake args, it should error
58-
_add_dataclass_options(dc, argparser)
56+
settings = argparser.add_argument_group(f"{self.name} executor settings")
57+
58+
for field in fields(dc):
59+
args = field_to_argument_args(field)
60+
kwargs = field_to_argument_kwargs(field)
61+
62+
if field.metadata.get("env_var"):
63+
kwargs["env_var"] = f"SNAKEMAKE_{prefixed_name.upper()}"
64+
settings.add_argument(*args, **kwargs)
5965

6066
def has_executor_settings(self):
6167
"""Determine if a plugin defines custom executor settings"""

0 commit comments

Comments
 (0)