Merge pull request #771 from PyPSA/mock_snakemake_root_dir

helpers: adjust mock_snakemake to be callable with different root directory
This commit is contained in:
Fabian Neumann 2023-11-02 08:18:04 +01:00 committed by GitHub
commit f75e18596d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -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**

View File

@ -191,7 +191,7 @@ def progress_retrieve(url, file, disable=False):
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,
@ -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:
@ -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: