From 29d959d86341aee66e945f216cae41e9c531a4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20K=C3=B6ster?= Date: Mon, 20 Jun 2022 12:48:52 +0200 Subject: [PATCH] fix: improved provenance trigger info (#1720) --- snakemake/workflow.py | 59 ++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/snakemake/workflow.py b/snakemake/workflow.py index 05e522af5..f32892b29 100644 --- a/snakemake/workflow.py +++ b/snakemake/workflow.py @@ -1097,7 +1097,38 @@ def files(items): if not dryrun and not no_hooks: self._onstart(logger.get_logfile()) - success = self.scheduler.schedule() + def log_provenance_info(): + provenance_triggered_jobs = [ + job + for job in dag.needrun_jobs(exclude_finished=False) + if dag.reason(job).is_provenance_triggered() + ] + if provenance_triggered_jobs: + logger.info( + "Some jobs were triggered by provenance information, " + "see 'reason' section in the rule displays above.\n" + "If you prefer that only modification time is used to " + "determine whether a job shall be executed, use the command " + "line option '--rerun-triggers mtime' (also see --help).\n" + "If you are sure that a change for a certain output file (say, ) won't " + "change the result (e.g. because you just changed the formatting of a script " + "or environment definition), you can also wipe its metadata to skip such a trigger via " + "'snakemake --cleanup-metadata '. " + ) + logger.info( + "Rules with provenance triggered jobs: " + + ",".join( + sorted(set(job.rule.name for job in provenance_triggered_jobs)) + ) + ) + logger.info("") + + try: + success = self.scheduler.schedule() + except Exception as e: + if dryrun: + log_provenance_info() + raise e if not immediate_submit and not dryrun and self.mode == Mode.default: dag.cleanup_workdir() @@ -1106,26 +1137,12 @@ def files(items): if dryrun: if len(dag): logger.run_info("\n".join(dag.stats())) - if any( - dag.reason(job).is_provenance_triggered() - for job in dag.needrun_jobs(exclude_finished=False) - ): - logger.info( - "Some jobs were triggered by provenance information, " - "see 'reason' section in the rule displays above.\n" - "If you prefer that only modification time is used to " - "determine whether a job shall be executed, use the command " - "line option '--rerun-triggers mtime' (also see --help).\n" - "If you are sure that a change for a certain output file (say, ) won't " - "change the result (e.g. because you just changed the formatting of a script " - "or environment definition), you can also wipe its metadata to skip such a trigger via " - "'snakemake --cleanup-metadata '." - ) - logger.info("") - logger.info( - "This was a dry-run (flag -n). The order of jobs " - "does not reflect the order of execution." - ) + log_provenance_info() + logger.info("") + logger.info( + "This was a dry-run (flag -n). The order of jobs " + "does not reflect the order of execution." + ) logger.remove_logfile() else: if stats: