helpers: adjust mock_snakemake to be callable with different root dirs

This commit is contained in:
Fabian 2023-10-31 12:09:39 +01:00
parent f35ecbe4a0
commit 75e66be571

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: