Skip to content

Commit

Permalink
fix: various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneskoester committed Sep 26, 2023
1 parent bc2dba6 commit 5f0636f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
10 changes: 8 additions & 2 deletions snakemake_interface_common/plugin_registry/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def get_settings(self, tag: Optional[str] = None) -> SettingsBase:
)
raise WorkflowError(msg)

def __iter__(self):
return iter(self._inner.values())


class PluginBase(ABC):
@property
Expand Down Expand Up @@ -166,6 +169,9 @@ def get_name_and_value(field):
if thefield.metadata.get("required"):
required_args.add(name)

if value is None:
continue

def extract_values(value, thefield, name, tag=None):
# This will only add instantiated values, and
# skip over dataclasses._MISSING_TYPE and similar
Expand Down Expand Up @@ -209,12 +215,12 @@ def check_required(kwargs, tag=None):

# convert into the dataclass
if self.support_tagged_values:
tagged_settings = TaggedSettings()
tagged_settings = TaggedSettings(self.name)
for tag, kwargs in kwargs_tagged.items():
check_required(kwargs, tag=tag)
tagged_settings.register_settings(dc(**kwargs), tag=tag)
try:
check_required(kwargs)
check_required(kwargs_all)
tagged_settings.register_settings(dc(kwargs_all))
except WorkflowError:
# if untagged settings are not complete, do not register them
Expand Down
18 changes: 13 additions & 5 deletions snakemake_interface_common/plugin_registry/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from abc import ABC, abstractmethod
import configargparse

from snakemake_interface_common.plugin_registry.plugin import PluginBase, SettingsBase
from snakemake_interface_common.plugin_registry.plugin import (
PluginBase,
SettingsBase,
TaggedSettings,
)
from snakemake_interface_common.plugin_registry import PluginRegistryBase


Expand Down Expand Up @@ -39,16 +43,20 @@ def test_registry_register_cli_args(self):
prefix = registry.get_plugin(self.get_test_plugin_name()).cli_prefix
for action in parser._actions:
if not action.dest == "help":
assert action.dest.startswith(prefix)
assert action.dest.startswith(
prefix.replace("-", "_")
), f"{prefix} is not a prefix of {action.dest}"

def test_registry_cli_args_to_settings(self):
registry = self.get_registry()

parser = argparse.ArgumentParser()
parser = configargparse.ArgumentParser()
registry.register_cli_args(parser)
args = parser.parse_args([])

plugin = registry.get_plugin(self.get_test_plugin_name())
settings = plugin.get_settings(args)

self.validate_settings(settings, plugin)
if not isinstance(settings, TaggedSettings):
settings = [settings]
for s in settings:
self.validate_settings(s, plugin)

0 comments on commit 5f0636f

Please sign in to comment.