From d9ee113f70a2d10717e9e9cd79aa727abeff7a98 Mon Sep 17 00:00:00 2001 From: yerbol-akhmetov Date: Wed, 9 Oct 2024 16:13:35 +0500 Subject: [PATCH 1/4] enable configfile for mock_snakemake --- scripts/_helpers.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index e3ceb2adf..a99776d4c 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -522,7 +522,7 @@ 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 +534,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 +568,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) + else: + configfile = None + 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: From db90f3af587ca3163ca654c1793dee43c946832d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:23:13 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/_helpers.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index a99776d4c..ef20ddb24 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, configfile=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, @@ -570,14 +572,16 @@ def mock_snakemake(rulename, root_dir=None, submodule_dir=None, configfile=None, break if isinstance(configfile, str): - with open(configfile, 'r') as file: + with open(configfile, "r") as file: configfile = yaml.safe_load(file) else: configfile = None workflow = sm.Workflow( - snakefile, overwrite_configfiles=[], rerun_triggers=[], - overwrite_config=configfile + snakefile, + overwrite_configfiles=[], + rerun_triggers=[], + overwrite_config=configfile, ) workflow.include(snakefile) workflow.global_resources = {} From 601e229c43b66a48ff38ce78811746cac3d6044c Mon Sep 17 00:00:00 2001 From: yerbol-akhmetov Date: Wed, 9 Oct 2024 16:24:20 +0500 Subject: [PATCH 3/4] Add release notes --- doc/release_notes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 1ea2f5393..f4c2b8f7a 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -26,6 +26,8 @@ E.g. if a new rule becomes available describe how to use it `make test` and in o * Include a dedicated cutout for Europe in bundle_config.yaml `PR #1125 `_ +* Enable configfile specification for mock_snakemake `PR #1135 `_ + PyPSA-Earth 0.4.1 ================= From 03cbb0b1ca8a3e874989b181b22fb7d5ee2a2f85 Mon Sep 17 00:00:00 2001 From: = Date: Sun, 13 Oct 2024 15:48:44 +0000 Subject: [PATCH 4/4] drop else condition --- scripts/_helpers.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index ef20ddb24..76bf0268d 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -574,8 +574,6 @@ def mock_snakemake( if isinstance(configfile, str): with open(configfile, "r") as file: configfile = yaml.safe_load(file) - else: - configfile = None workflow = sm.Workflow( snakefile,