Skip to content

Commit 92ecdb4

Browse files
committed
use the onstart directive of snakemake to print a warning
1 parent 765a126 commit 92ecdb4

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Snakefile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ if config["foresight"] == "perfect":
7878

7979
include: "rules/solve_perfect.smk"
8080

81+
# Pypsa-DE requires the scenario management by default
82+
onstart:
83+
scenarios_file=Path(config["run"]["scenarios"]["file"])
84+
manual_file=Path(config["run"]["scenarios"]["manual_file"])
85+
86+
if not scenarios_file.exists():
87+
print(f"\033[91mWARNING: {scenarios_file} does not exist. Please run `snakemake build_scenarios` to create it.\033[0m")
88+
elif manual_file.exists():
89+
if scenarios_file.stat().st_mtime < manual_file.stat().st_mtime:
90+
print(f"\033[91mWARNING: {manual_file} is newer than {scenarios_file}. Please run `snakemake build_scenarios` to update {scenarios_file}.\033[0m")
91+
else:
92+
print(f"\033[91mWARNING: {manual_file} does not exist. Please create it to use the scenario management.\033[0m")
93+
print(f"Scenario file {scenarios_file} exists and is up to date. Starting workflow.")
8194

8295
rule all:
8396
input:
@@ -149,15 +162,6 @@ rule all:
149162
default_target: True
150163

151164

152-
rule create_scenarios:
153-
output:
154-
config["run"]["scenarios"]["file"],
155-
conda:
156-
"envs/environment.yaml"
157-
script:
158-
"config/create_scenarios.py"
159-
160-
161165
rule purge:
162166
run:
163167
import builtins

0 commit comments

Comments
 (0)