diff --git a/snakemake/parser.py b/snakemake/parser.py index 73d5e60b5..51ad77c1f 100644 --- a/snakemake/parser.py +++ b/snakemake/parser.py @@ -248,7 +248,9 @@ class Configfile(GlobalKeywordState): class Pepfile(GlobalKeywordState): - pass + @property + def keyword(self): + return "set_pepfile" class Pepschema(GlobalKeywordState): diff --git a/snakemake/workflow.py b/snakemake/workflow.py index 74d10508e..541552836 100644 --- a/snakemake/workflow.py +++ b/snakemake/workflow.py @@ -1241,19 +1241,18 @@ def workdir(self, workdir): def configfile(self, fp): """Update the global config with data from the given file.""" - global config if not self.modifier.skip_configfile: if os.path.exists(fp): self.configfiles.append(fp) c = snakemake.io.load_configfile(fp) - update_config(config, c) + update_config(self.config, c) if self.overwrite_config: logger.info( "Config file {} is extended by additional config specified via the command line.".format( fp ) ) - update_config(config, self.overwrite_config) + update_config(self.config, self.overwrite_config) elif not self.overwrite_configfiles: raise WorkflowError( "Workflow defines configfile {} but it is not present or accessible.".format( @@ -1261,8 +1260,7 @@ def configfile(self, fp): ) ) - def pepfile(self, path): - global pep + def set_pepfile(self, path): try: import peppy @@ -1270,11 +1268,9 @@ def pepfile(self, path): raise WorkflowError("For PEP support, please install peppy.") self.pepfile = path - pep = peppy.Project(self.pepfile) + self.globals["pep"] = peppy.Project(self.pepfile) def pepschema(self, schema): - global pep - try: import eido except ImportError: @@ -1285,7 +1281,9 @@ def pepschema(self, schema): schema = self.current_basedir.join(schema).get_path_or_uri() if self.pepfile is None: raise WorkflowError("Please specify a PEP with the pepfile directive.") - eido.validate_project(project=pep, schema=schema, exclude_case=True) + eido.validate_project( + project=self.globals["pep"], schema=schema, exclude_case=True + ) def report(self, path): """Define a global report description in .rst format.""" diff --git a/tests/test_modules_peppy/Snakefile b/tests/test_modules_peppy/Snakefile new file mode 100644 index 000000000..a8bcd01a8 --- /dev/null +++ b/tests/test_modules_peppy/Snakefile @@ -0,0 +1,15 @@ +shell.executable("bash") + +configfile: "config/config.yaml" + + +module test: + snakefile: + "module-test/Snakefile" + config: + config + prefix: + "foo" + + +use rule * from test diff --git a/tests/test_modules_peppy/config/config.yaml b/tests/test_modules_peppy/config/config.yaml new file mode 100644 index 000000000..176e04c11 --- /dev/null +++ b/tests/test_modules_peppy/config/config.yaml @@ -0,0 +1,2 @@ +test: 1 +pepfile: "pep/config.yaml" \ No newline at end of file diff --git a/tests/test_modules_peppy/expected-results/foo/results/test.out b/tests/test_modules_peppy/expected-results/foo/results/test.out new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/tests/test_modules_peppy/expected-results/foo/results/test.out @@ -0,0 +1 @@ +1 diff --git a/tests/test_modules_peppy/module-test/Snakefile b/tests/test_modules_peppy/module-test/Snakefile new file mode 100644 index 000000000..40b8fbb81 --- /dev/null +++ b/tests/test_modules_peppy/module-test/Snakefile @@ -0,0 +1,14 @@ +configfile: "config.yaml" # does not exist, but this statement should be ignored on module import +pepfile: config["pepfile"] + +def some_func(): + return 15 + +print(pep) + +rule a: + output: + "results/test.out", + "/tmp/foo.txt" + shell: + "echo {config[test]} > {output[0]}; touch {output[1]}" \ No newline at end of file diff --git a/tests/test_modules_peppy/pep/config.yaml b/tests/test_modules_peppy/pep/config.yaml new file mode 100644 index 000000000..609c7a23e --- /dev/null +++ b/tests/test_modules_peppy/pep/config.yaml @@ -0,0 +1,2 @@ +pep_version: "2.0.0" +sample_table: sample_table.csv diff --git a/tests/test_modules_peppy/pep/sample_table.csv b/tests/test_modules_peppy/pep/sample_table.csv new file mode 100644 index 000000000..49ae2a487 --- /dev/null +++ b/tests/test_modules_peppy/pep/sample_table.csv @@ -0,0 +1,3 @@ +sample_name,protocol +a,test +b,test2 diff --git a/tests/test_peppy/workflow/Snakefile b/tests/test_peppy/Snakefile similarity index 69% rename from tests/test_peppy/workflow/Snakefile rename to tests/test_peppy/Snakefile index 1733c9b1e..936ef6361 100644 --- a/tests/test_peppy/workflow/Snakefile +++ b/tests/test_peppy/Snakefile @@ -1,5 +1,7 @@ pepfile: "pep/config.yaml" -pepschema: "schemas/pep.yaml" +pepfile: "pep/config.yaml" # test overwriting + +pepschema: "workflow/schemas/pep.yaml" rule all: input: diff --git a/tests/test_peppy/expected-results/a.txt b/tests/test_peppy/expected-results/a.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_peppy/expected-results/b.txt b/tests/test_peppy/expected-results/b.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/tests.py b/tests/tests.py index 6248c42af..e2d58a760 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1289,6 +1289,11 @@ def test_modules_prefix(): run(dpath("test_modules_prefix"), targets=["a"]) +@skip_on_windows +def test_modules_peppy(): + run(dpath("test_modules_peppy"), targets=["a"]) + + def test_modules_specific(): run(dpath("test_modules_specific"), targets=["test_a"]) @@ -1427,3 +1432,8 @@ def test_github_issue1384(): ) finally: shutil.rmtree(tmpdir) + + +@skip_on_windows +def test_peppy(): + run(dpath("test_peppy"))