From d0a7bf243c5df204136fa1f14706aab793793c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20K=C3=B6ster?= Date: Wed, 17 Nov 2021 15:05:26 +0100 Subject: [PATCH] fix: handle config file extension/overwriting more explicitly (#1251) * handle config file extension/overwriting more explicitly * fmt --- snakemake/__init__.py | 4 +++- snakemake/workflow.py | 21 +++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/snakemake/__init__.py b/snakemake/__init__.py index 917ea12ae..88838c080 100644 --- a/snakemake/__init__.py +++ b/snakemake/__init__.py @@ -1239,7 +1239,9 @@ def get_argument_parser(profile=None): "Specify or overwrite the config file of the workflow (see the docs). " "Values specified in JSON or YAML format are available in the global config " "dictionary inside the workflow. Multiple files overwrite each other in " - "the given order." + "the given order. Thereby missing keys in previous config files are extended by " + "following configfiles. Note that this order also includes a config file defined " + "in the workflow definition itself (which will come first)." ), ) group_exec.add_argument( diff --git a/snakemake/workflow.py b/snakemake/workflow.py index 93121023d..fb4a23159 100644 --- a/snakemake/workflow.py +++ b/snakemake/workflow.py @@ -1238,10 +1238,23 @@ def configfile(self, fp): """Update the global config with data from the given file.""" global config if not self.modifier.skip_configfile: - self.configfiles.append(fp) - c = snakemake.io.load_configfile(fp) - update_config(config, c) - update_config(config, self.overwrite_config) + if os.path.exists(fp): + self.configfiles.append(fp) + c = snakemake.io.load_configfile(fp) + update_config(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) + elif not self.overwrite_configfiles: + raise WorkflowError( + "Workflow defines configfile {} but it is not present or accessible.".format( + fp + ) + ) def pepfile(self, path): global pep