From 92ecdb403a0624c57825f6b0c6f5b68d7da2ffc1 Mon Sep 17 00:00:00 2001 From: Michael Lindner Date: Wed, 7 May 2025 16:56:36 +0200 Subject: [PATCH 1/2] use the onstart directive of snakemake to print a warning --- Snakefile | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Snakefile b/Snakefile index 8ced597b8..88935d102 100644 --- a/Snakefile +++ b/Snakefile @@ -78,6 +78,19 @@ if config["foresight"] == "perfect": include: "rules/solve_perfect.smk" +# Pypsa-DE requires the scenario management by default +onstart: + scenarios_file=Path(config["run"]["scenarios"]["file"]) + manual_file=Path(config["run"]["scenarios"]["manual_file"]) + + if not scenarios_file.exists(): + print(f"\033[91mWARNING: {scenarios_file} does not exist. Please run `snakemake build_scenarios` to create it.\033[0m") + elif manual_file.exists(): + if scenarios_file.stat().st_mtime < manual_file.stat().st_mtime: + print(f"\033[91mWARNING: {manual_file} is newer than {scenarios_file}. Please run `snakemake build_scenarios` to update {scenarios_file}.\033[0m") + else: + print(f"\033[91mWARNING: {manual_file} does not exist. Please create it to use the scenario management.\033[0m") + print(f"Scenario file {scenarios_file} exists and is up to date. Starting workflow.") rule all: input: @@ -149,15 +162,6 @@ rule all: default_target: True -rule create_scenarios: - output: - config["run"]["scenarios"]["file"], - conda: - "envs/environment.yaml" - script: - "config/create_scenarios.py" - - rule purge: run: import builtins From 20c670aa32c7359dff8ce7675bc63378aee16f41 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 May 2025 15:04:49 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Snakefile | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Snakefile b/Snakefile index 88935d102..8bb722361 100644 --- a/Snakefile +++ b/Snakefile @@ -78,19 +78,29 @@ if config["foresight"] == "perfect": include: "rules/solve_perfect.smk" + # Pypsa-DE requires the scenario management by default onstart: - scenarios_file=Path(config["run"]["scenarios"]["file"]) - manual_file=Path(config["run"]["scenarios"]["manual_file"]) + scenarios_file = Path(config["run"]["scenarios"]["file"]) + manual_file = Path(config["run"]["scenarios"]["manual_file"]) if not scenarios_file.exists(): - print(f"\033[91mWARNING: {scenarios_file} does not exist. Please run `snakemake build_scenarios` to create it.\033[0m") + print( + f"\033[91mWARNING: {scenarios_file} does not exist. Please run `snakemake build_scenarios` to create it.\033[0m" + ) elif manual_file.exists(): if scenarios_file.stat().st_mtime < manual_file.stat().st_mtime: - print(f"\033[91mWARNING: {manual_file} is newer than {scenarios_file}. Please run `snakemake build_scenarios` to update {scenarios_file}.\033[0m") + print( + f"\033[91mWARNING: {manual_file} is newer than {scenarios_file}. Please run `snakemake build_scenarios` to update {scenarios_file}.\033[0m" + ) else: - print(f"\033[91mWARNING: {manual_file} does not exist. Please create it to use the scenario management.\033[0m") - print(f"Scenario file {scenarios_file} exists and is up to date. Starting workflow.") + print( + f"\033[91mWARNING: {manual_file} does not exist. Please create it to use the scenario management.\033[0m" + ) + print( + f"Scenario file {scenarios_file} exists and is up to date. Starting workflow." + ) + rule all: input: