Skip to content

Commit

Permalink
Merge pull request #771 from PyPSA/mock_snakemake_root_dir
Browse files Browse the repository at this point in the history
helpers: adjust mock_snakemake to be callable with different root directory
  • Loading branch information
fneum authored Nov 2, 2023
2 parents f35ecbe + 71f88fd commit f75e185
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Upcoming Release

* Split configuration to enable SMR and SMR CC.

* The ``mock_snakemake`` function can now be used with a Snakefile from a different directory using the new ``root_dir`` argument.


**Bugs and Compatibility**
Expand Down
9 changes: 7 additions & 2 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def update_to(b=1, bsize=1, tsize=None):
urllib.request.urlretrieve(url, file, reporthook=update_to)


def mock_snakemake(rulename, configfiles=[], **wildcards):
def mock_snakemake(rulename, root_dir=None, configfiles=[], **wildcards):
"""
This function is expected to be executed from the 'scripts'-directory of '
the snakemake project. It returns a snakemake.script.Snakemake object,
Expand All @@ -203,6 +203,8 @@ def mock_snakemake(rulename, configfiles=[], **wildcards):
----------
rulename: str
name of the rule for which the snakemake object should be generated
root_dir: str/path-like
path to the root directory of the snakemake project
configfiles: list, str
list of configfiles to be used to update the config
**wildcards:
Expand All @@ -217,7 +219,10 @@ def mock_snakemake(rulename, configfiles=[], **wildcards):
from snakemake.script import Snakemake

script_dir = Path(__file__).parent.resolve()
root_dir = script_dir.parent
if root_dir is None:
root_dir = script_dir.parent
else:
root_dir = Path(root_dir).resolve()

user_in_script_dir = Path.cwd().resolve() == script_dir
if user_in_script_dir:
Expand Down

0 comments on commit f75e185

Please sign in to comment.