diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 470e9743d..a900e5860 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -28,6 +28,8 @@ E.g. if a new rule becomes available describe how to use it `make test` and in o * Fix the mismatch between buses and x, y locations while creating H2 Stores `PR #1134 `_ +* Enable configfile specification for mock_snakemake `PR #1135 `_ + PyPSA-Earth 0.4.1 ================= diff --git a/scripts/_helpers.py b/scripts/_helpers.py index e3ceb2adf..76bf0268d 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -522,7 +522,9 @@ def get_aggregation_strategies(aggregation_strategies): return bus_strategies, generator_strategies -def mock_snakemake(rulename, root_dir=None, submodule_dir=None, **wildcards): +def mock_snakemake( + rulename, root_dir=None, submodule_dir=None, configfile=None, **wildcards +): """ This function is expected to be executed from the "scripts"-directory of " the snakemake project. It returns a snakemake.script.Snakemake object, @@ -534,6 +536,8 @@ def mock_snakemake(rulename, root_dir=None, submodule_dir=None, **wildcards): ---------- rulename: str name of the rule for which the snakemake object should be generated + configfile: str + path to config file to be used in mock_snakemake wildcards: keyword arguments fixing the wildcards. Only necessary if wildcards are needed. @@ -566,9 +570,17 @@ def mock_snakemake(rulename, root_dir=None, submodule_dir=None, **wildcards): if os.path.exists(p): snakefile = p break + + if isinstance(configfile, str): + with open(configfile, "r") as file: + configfile = yaml.safe_load(file) + workflow = sm.Workflow( - snakefile, overwrite_configfiles=[], rerun_triggers=[] - ) # overwrite_config=config + snakefile, + overwrite_configfiles=[], + rerun_triggers=[], + overwrite_config=configfile, + ) workflow.include(snakefile) workflow.global_resources = {} try: