Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helpers: adjust mock_snakemake to be callable with different root directory #771

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading