Skip to content

Commit

Permalink
fix: remove raise that limits using --config with dicts (#1341)
Browse files Browse the repository at this point in the history
* Remove raise that limits using --config with dicts

* Added a test case name 'test_dicts_in_config'

Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
  • Loading branch information
lpla and johanneskoester committed Feb 21, 2022
1 parent 8ed0c8c commit bd65057
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 0 additions & 2 deletions snakemake/__init__.py
Expand Up @@ -970,8 +970,6 @@ def unparse_config(config):
raise ValueError("config is not a dict")
items = []
for key, value in config.items():
if isinstance(value, dict):
raise ValueError("config may only be a flat dict")
encoded = "'{}'".format(value) if isinstance(value, str) else value
items.append("{}={}".format(key, encoded))
return items
Expand Down
19 changes: 19 additions & 0 deletions tests/testapi.py
Expand Up @@ -57,3 +57,22 @@ async def main():
async_run(main())
else:
asyncio.run(main())


def test_dicts_in_config():
with tempfile.TemporaryDirectory() as tmpdir:
path = os.path.join(tmpdir, "Snakefile")
with open(path, "w") as f:
print(
dedent(
"""
rule:
output: 'result.txt'
run:
with open(output[0], 'w') as f:
print("hello, this option " + config["this_option"] + "; this test dictionary " + config["test"]["this_dict"], file=f)
"""
),
file=f,
)
snakemake(path, workdir=tmpdir, config={"this_option": "does_not_break", "test": {'this_dict':'shoult_not_either'}})

0 comments on commit bd65057

Please sign in to comment.