From 12cdc961c86541d5c50533a6b8ff5df0cb6fd7d1 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Wed, 21 Sep 2022 19:53:45 +1000 Subject: [PATCH] fix: allow script directive to take pathlib Path (#1869) ### Description This PR allows the `script` directive to accept a `pathlib.Path` object. ### QC * [x] The PR contains a test case for the changes or the changes are already covered by an existing test case. * [ ] The documentation (`docs/`) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake). --- snakemake/script.py | 2 ++ tests/test_script/Snakefile | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/snakemake/script.py b/snakemake/script.py index ada0768d6..df2bb6df1 100644 --- a/snakemake/script.py +++ b/snakemake/script.py @@ -1498,6 +1498,8 @@ def script( """ Load a script from the given basedir + path and execute it. """ + if isinstance(path, Path): + path = str(path) path, source, language, is_local = get_source( path, SourceCache(runtime_sourcecache_path), basedir, wildcards, params diff --git a/tests/test_script/Snakefile b/tests/test_script/Snakefile index e0500d355..69b83bd29 100644 --- a/tests/test_script/Snakefile +++ b/tests/test_script/Snakefile @@ -1,3 +1,5 @@ +from pathlib import Path + configfile: "config.yaml" @@ -28,7 +30,7 @@ rule: output: "test.in" script: - "scripts/test.py" + Path("scripts/test.py") rule: output: