From bd65057a782355ede86ad0bb912e063ff25a97f5 Mon Sep 17 00:00:00 2001 From: Leopoldo Pla Date: Mon, 21 Feb 2022 08:57:34 +0100 Subject: [PATCH] fix: remove raise that limits using --config with dicts (#1341) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove raise that limits using --config with dicts * Added a test case name 'test_dicts_in_config' Co-authored-by: Johannes Köster --- snakemake/__init__.py | 2 -- tests/testapi.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/snakemake/__init__.py b/snakemake/__init__.py index 95d16e43a..c2667f0a8 100644 --- a/snakemake/__init__.py +++ b/snakemake/__init__.py @@ -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 diff --git a/tests/testapi.py b/tests/testapi.py index 6be11228d..925a21534 100644 --- a/tests/testapi.py +++ b/tests/testapi.py @@ -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'}})