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: fixed parsing of subsequent use rule statements directly beneath each other #1548

Merged
merged 2 commits into from Mar 31, 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
8 changes: 4 additions & 4 deletions snakemake/parser.py
Expand Up @@ -162,11 +162,11 @@ def colon(self, token):
def is_block_end(self, token):
return (self.line and self.indent <= 0) or is_eof(token)

def block(self, token):
def block(self, token, force_block_end=False):
if self.lasttoken == "\n" and is_comment(token):
# ignore lines containing only comments
self.line -= 1
if self.is_block_end(token):
if force_block_end or self.is_block_end(token):
yield from self.decorate_end(token)
yield "\n", token
raise StopAutomaton(token)
Expand Down Expand Up @@ -1063,7 +1063,7 @@ def state_modifier(self, token):
)
elif is_newline(token) or is_comment(token) or is_eof(token):
# end of the statement, close block manually
yield from self.block(token)
yield from self.block(token, force_block_end=True)
else:
self.error(
"Expecting either 'as', 'with' or end of line in 'use rule' statement.",
Expand Down Expand Up @@ -1092,7 +1092,7 @@ def state_as(self, token):
yield from ()
elif is_newline(token) or is_comment(token) or is_eof(token):
# end of the statement, close block manually
yield from self.block(token)
yield from self.block(token, force_block_end=True)
else:
self.error(
"Expecting rulename modifying pattern (e.g. modulename_*) after 'as' keyword.",
Expand Down
40 changes: 40 additions & 0 deletions tests/test_github_issue1500/Snakefile
@@ -0,0 +1,40 @@
shell.executable("bash")

configfile: "config/config.yaml"


module test1:
snakefile:
"module-test/Snakefile"
config:
config
replace_prefix:
{"results/": "results/testmodule1/"}




module test2:
snakefile:
"module-test/Snakefile"
config:
config
replace_prefix:
{"results/": "results/testmodule2/"}


use rule * from test1 as test1_*

use rule * from test2 as test2_*



rule all:
default_target: True
input:
rules.test1_a.output,
rules.test2_a.output


assert test1.some_func() == 15
assert test2.some_func() == 15
1 change: 1 addition & 0 deletions tests/test_github_issue1500/config/config.yaml
@@ -0,0 +1 @@
test: 1
Empty file.
12 changes: 12 additions & 0 deletions tests/test_github_issue1500/module-test/Snakefile
@@ -0,0 +1,12 @@
configfile: "config.yaml" # does not exist, but this statement should be ignored on module import


def some_func():
return 15


rule a:
output:
"results/test.out"
shell:
"echo {config[test]} > {output}"
5 changes: 5 additions & 0 deletions tests/tests.py
Expand Up @@ -1582,5 +1582,10 @@ def test_pipe_depend_target_file():
run(dpath("test_pipe_depend"), targets=["test.txt"], shouldfail=True)


@skip_on_windows # platform independent issue
def test_github_issue1500():
run(dpath("test_github_issue1500"), dryrun=True)


def test_github_issue1542():
run(dpath("test_github_issue1542"), dryrun=True)