From 28a47959bca2d135f82f9d8901b2b0aa228f30cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20K=C3=B6ster?= Date: Fri, 20 May 2022 10:30:42 +0200 Subject: [PATCH] fix: fix errors occurring when refering to input func via rules..input (#1669) * fix: fix errors occurring when refering to input func via rules..input * skip win * fix for cases when a prefix is provided --- snakemake/io.py | 3 +++ snakemake/rules.py | 18 +++++++++++++++++- tests/test_module_input_func/Snakefile | 14 ++++++++++++++ .../expected-results/test/results/C.txt | 1 + tests/test_module_input_func/module1/Snakefile | 15 +++++++++++++++ tests/tests.py | 5 +++++ 6 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/test_module_input_func/Snakefile create mode 100644 tests/test_module_input_func/expected-results/test/results/C.txt create mode 100644 tests/test_module_input_func/module1/Snakefile diff --git a/snakemake/io.py b/snakemake/io.py index 182b1d1d0..ffd144e78 100755 --- a/snakemake/io.py +++ b/snakemake/io.py @@ -1443,6 +1443,9 @@ def git_content(git_file): def strip_wildcard_constraints(pattern): """Return a string that does not contain any wildcard constraints.""" + if is_callable(pattern): + # do not apply on e.g. input functions + return pattern def strip_constraint(match): return "{{{}}}".format(match.group("name")) diff --git a/snakemake/rules.py b/snakemake/rules.py index 151b36a95..0e2891b54 100644 --- a/snakemake/rules.py +++ b/snakemake/rules.py @@ -1270,7 +1270,23 @@ def output(self): @lazy_property def input(self): - return self.rule.input._stripped_constraints() + def modify_callable(item): + if is_callable(item): + # For callables ensure that the rule's original path modifier is applied as well. + + def inner(wildcards): + return self.rule.apply_path_modifier( + item(wildcards), self.rule.input_modifier, property="input" + ) + + return inner + else: + # For strings, the path modifier has been already applied. + return item + + return InputFiles( + toclone=self.rule.input, strip_constraints=True, custom_map=modify_callable + ) @lazy_property def params(self): diff --git a/tests/test_module_input_func/Snakefile b/tests/test_module_input_func/Snakefile new file mode 100644 index 000000000..0b2e8fb10 --- /dev/null +++ b/tests/test_module_input_func/Snakefile @@ -0,0 +1,14 @@ +module mod1: + snakefile: + "module1/Snakefile" + prefix: + "test/" + + +use rule * from mod1 as mod1_* + + +rule all: + input: + rules.mod1_all.input, + default_target: True diff --git a/tests/test_module_input_func/expected-results/test/results/C.txt b/tests/test_module_input_func/expected-results/test/results/C.txt new file mode 100644 index 000000000..3cc58df83 --- /dev/null +++ b/tests/test_module_input_func/expected-results/test/results/C.txt @@ -0,0 +1 @@ +C diff --git a/tests/test_module_input_func/module1/Snakefile b/tests/test_module_input_func/module1/Snakefile new file mode 100644 index 000000000..cdd7386ba --- /dev/null +++ b/tests/test_module_input_func/module1/Snakefile @@ -0,0 +1,15 @@ +def txt_output(wildcards): + return ["results/C.txt"] + + +rule all: + input: + txt_output + + +rule txt: + output: + "results/C.txt" + shell: + "echo 'C' " + ">{output} " diff --git a/tests/tests.py b/tests/tests.py index 82ec9052b..a5bd71143 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1646,6 +1646,11 @@ def test_retries(): run(dpath("test_retries")) +@skip_on_windows # OS agnostic +def test_module_input_func(): + run(dpath("test_module_input_func")) + + @skip_on_windows # the testcase only has a linux-64 pin file def test_conda_pin_file(): run(dpath("test_conda_pin_file"), use_conda=True)