diff --git a/snakemake/parser.py b/snakemake/parser.py index e82da47a4..a293b013b 100644 --- a/snakemake/parser.py +++ b/snakemake/parser.py @@ -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) @@ -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.", @@ -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.", diff --git a/tests/test_github_issue1500/Snakefile b/tests/test_github_issue1500/Snakefile new file mode 100644 index 000000000..8b6d8464b --- /dev/null +++ b/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 diff --git a/tests/test_github_issue1500/config/config.yaml b/tests/test_github_issue1500/config/config.yaml new file mode 100644 index 000000000..7ae63cb9a --- /dev/null +++ b/tests/test_github_issue1500/config/config.yaml @@ -0,0 +1 @@ +test: 1 \ No newline at end of file diff --git a/tests/test_github_issue1500/expected-results/.gitkeep b/tests/test_github_issue1500/expected-results/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_github_issue1500/module-test/Snakefile b/tests/test_github_issue1500/module-test/Snakefile new file mode 100644 index 000000000..1d4cb5d4e --- /dev/null +++ b/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}" \ No newline at end of file diff --git a/tests/tests.py b/tests/tests.py index 515e780fa..b4885dc2e 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -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)