From 0279181e7878749ebe2ee891fa124b51d70ccbeb Mon Sep 17 00:00:00 2001 From: James Hadfield Date: Wed, 20 Sep 2023 15:58:23 +1200 Subject: [PATCH] Fix snakemake rule existence checks We use the existence of certain rules to control the DAG and the way rules are stored internally changed in snakemake 7.32.1 This functionality is (probably?) only used for internal nextstrain builds where we use the `auspice_config` rule to programmatically generate the config. --- workflow/snakemake_rules/main_workflow.smk | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/workflow/snakemake_rules/main_workflow.smk b/workflow/snakemake_rules/main_workflow.smk index 93501d367..9d1c97145 100644 --- a/workflow/snakemake_rules/main_workflow.smk +++ b/workflow/snakemake_rules/main_workflow.smk @@ -1394,6 +1394,14 @@ rule build_description: with open(output.description, "w", encoding = "utf-8") as o: o.write(template.safe_substitute(context)) +def rule_exists(name): + # Some versions of Snakemake throw a WorkflowError even with the + # three-arg getattr(), so catch any error and assume non-existence. + try: + return bool(getattr(rules, name, None)) + except: + return False + def get_auspice_config(w): """ Auspice configs are chosen via this heirarchy: @@ -1403,7 +1411,7 @@ def get_auspice_config(w): """ if "auspice_config" in config["builds"].get(w.build_name, {}): return config["builds"][w.build_name]["auspice_config"] - if "auspice_config" in rules.__dict__: + if rule_exists("auspice_config"): return rules.auspice_config.output return config["files"]["auspice_config"]