Skip to content

Commit

Permalink
fix: fix errors occurring when refering to input func via rules.<rule…
Browse files Browse the repository at this point in the history
…name>.input (#1669)

* fix: fix errors occurring when refering to input func via rules.<rulename>.input

* skip win

* fix for cases when a prefix is provided
  • Loading branch information
johanneskoester committed May 20, 2022
1 parent f1ffbf2 commit 28a4795
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
3 changes: 3 additions & 0 deletions snakemake/io.py
Expand Up @@ -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"))
Expand Down
18 changes: 17 additions & 1 deletion snakemake/rules.py
Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions 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
@@ -0,0 +1 @@
C
15 changes: 15 additions & 0 deletions 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} "
5 changes: 5 additions & 0 deletions tests/tests.py
Expand Up @@ -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)
Expand Down

0 comments on commit 28a4795

Please sign in to comment.