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

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

Merged
merged 5 commits into from May 20, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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