Skip to content

Commit 5bdfa0d

Browse files
Add script path provider (take 2) (PyPSA#1997)
* Add script path getter; update all `script` directives * force integration test on windows runner * Revert CI change --------- Co-authored-by: Lukas Trippe <lkstrp@pm.me>
1 parent ac6fd17 commit 5bdfa0d

12 files changed

Lines changed: 142 additions & 115 deletions

Snakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ from scripts._helpers import (
1818
get_scenarios,
1919
get_shadow,
2020
path_provider,
21+
script_path_provider,
2122
)
2223
from scripts.lib.validation.config import validate_config
2324

@@ -43,6 +44,7 @@ exclude_from_shared = run["shared_resources"]["exclude"]
4344
logs = path_provider("logs/", RDIR, shared_resources, exclude_from_shared)
4445
benchmarks = path_provider("benchmarks/", RDIR, shared_resources, exclude_from_shared)
4546
resources = path_provider("resources/", RDIR, shared_resources, exclude_from_shared)
47+
scripts = script_path_provider(Path(workflow.snakefile).parent)
4648

4749
RESULTS = "results/" + RDIR
4850

doc/release_notes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ Release Notes
99
Upcoming Release
1010
================
1111

12+
* Add script path getter helper method to allow for rule inheritance in nested snakefiles.
13+
1214
* Include new storage technologies such as li-ion, vanadium, lfp, lair, pair and iron-air. These technologies can now be configured as either store-link combinations or standalone storage units.
1315
Implemented in both `add_electricity.py` and `prepare_sector_network.py` (https://github.com/PyPSA/pypsa-eur/pull/1961).
1416

1517
* Updated data sources for country-level electricity demand time series. In addition to the OPSD data (``retrieve_electricity_demand_opsd``, demand time series
1618
are now downloaded via the ENTSO-E Transparency Platform API (``retrieve_electricity_demand_entsoe`` environment variable ``ENTSOE_API_KEY`` required)
1719
and from the NESO data portal for Great Britain and Northern Ireland (``retrieve_electricity_demand_neso``).
18-
Manual corrections and gap filling methods have been applied and checked for data until the end of 2025.
20+
Manual corrections and gap filling methods have been applied and checked for data until the end of 2025.
1921
(https://github.com/PyPSA/pypsa-eur/pull/1828).
2022

2123
* Applied scaling of kW and GW to MW for custom_costs as well (https://github.com/PyPSA/pypsa-eur/pull/2023).

rules/build_electricity.smk

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ rule build_electricity_demand:
2929
resources:
3030
mem_mb=5000,
3131
script:
32-
"../scripts/build_electricity_demand.py"
32+
scripts("build_electricity_demand.py")
3333

3434

3535
rule build_powerplants:
@@ -54,7 +54,7 @@ rule build_powerplants:
5454
resources:
5555
mem_mb=7000,
5656
script:
57-
"../scripts/build_powerplants.py"
57+
scripts("build_powerplants.py")
5858

5959

6060
def input_base_network(w):
@@ -106,7 +106,7 @@ rule base_network:
106106
resources:
107107
mem_mb=2000,
108108
script:
109-
"../scripts/base_network.py"
109+
scripts("base_network.py")
110110

111111

112112
rule build_osm_boundaries:
@@ -123,7 +123,7 @@ rule build_osm_boundaries:
123123
resources:
124124
mem_mb=1500,
125125
script:
126-
"../scripts/build_osm_boundaries.py"
126+
scripts("build_osm_boundaries.py")
127127

128128

129129
rule build_bidding_zones:
@@ -148,7 +148,7 @@ rule build_bidding_zones:
148148
resources:
149149
mem_mb=1500,
150150
script:
151-
"../scripts/build_bidding_zones.py"
151+
scripts("build_bidding_zones.py")
152152

153153

154154
rule build_shapes:
@@ -186,7 +186,7 @@ rule build_shapes:
186186
resources:
187187
mem_mb=1500,
188188
script:
189-
"../scripts/build_shapes.py"
189+
scripts("build_shapes.py")
190190

191191

192192
if CUTOUT_DATASET["source"] in ["build"]:
@@ -206,7 +206,7 @@ if CUTOUT_DATASET["source"] in ["build"]:
206206
resources:
207207
mem_mb=config["atlite"].get("nprocesses", 4) * 1000,
208208
script:
209-
"../scripts/build_cutout.py"
209+
scripts("build_cutout.py")
210210

211211

212212
rule build_ship_raster:
@@ -224,7 +224,7 @@ rule build_ship_raster:
224224
benchmark:
225225
benchmarks("build_ship_raster")
226226
script:
227-
"../scripts/build_ship_raster.py"
227+
scripts("build_ship_raster.py")
228228

229229

230230
rule determine_availability_matrix_MD_UA:
@@ -268,7 +268,7 @@ rule determine_availability_matrix_MD_UA:
268268
resources:
269269
mem_mb=config["atlite"].get("nprocesses", 4) * 5000,
270270
script:
271-
"../scripts/determine_availability_matrix_MD_UA.py"
271+
scripts("determine_availability_matrix_MD_UA.py")
272272

273273

274274
# Optional input when having Ukraine (UA) or Moldova (MD) in the countries list
@@ -332,7 +332,7 @@ rule determine_availability_matrix:
332332
resources:
333333
mem_mb=config["atlite"].get("nprocesses", 4) * 5000,
334334
script:
335-
"../scripts/determine_availability_matrix.py"
335+
scripts("determine_availability_matrix.py")
336336

337337

338338
rule build_renewable_profiles:
@@ -367,7 +367,7 @@ rule build_renewable_profiles:
367367
wildcard_constraints:
368368
technology="(?!hydro).*", # Any technology other than hydro
369369
script:
370-
"../scripts/build_renewable_profiles.py"
370+
scripts("build_renewable_profiles.py")
371371

372372

373373
rule build_monthly_prices:
@@ -387,7 +387,7 @@ rule build_monthly_prices:
387387
resources:
388388
mem_mb=5000,
389389
script:
390-
"../scripts/build_monthly_prices.py"
390+
scripts("build_monthly_prices.py")
391391

392392

393393
if COUNTRY_RUNOFF_DATASET["source"] == "build":
@@ -407,7 +407,7 @@ if COUNTRY_RUNOFF_DATASET["source"] == "build":
407407
benchmark:
408408
benchmarks("build_country_runoff")
409409
script:
410-
"../scripts/build_country_runoff.py"
410+
scripts("build_country_runoff.py")
411411

412412

413413
rule build_hydro_profile:
@@ -435,7 +435,7 @@ rule build_hydro_profile:
435435
resources:
436436
mem_mb=5000,
437437
script:
438-
"../scripts/build_hydro_profile.py"
438+
scripts("build_hydro_profile.py")
439439

440440

441441
rule build_line_rating:
@@ -459,7 +459,7 @@ rule build_line_rating:
459459
resources:
460460
mem_mb=config["atlite"].get("nprocesses", 4) * 1000,
461461
script:
462-
"../scripts/build_line_rating.py"
462+
scripts("build_line_rating.py")
463463

464464

465465
rule build_transmission_projects:
@@ -494,7 +494,7 @@ rule build_transmission_projects:
494494
mem_mb=4000,
495495
threads: 1
496496
script:
497-
"../scripts/build_transmission_projects.py"
497+
scripts("build_transmission_projects.py")
498498

499499

500500
rule add_transmission_projects_and_dlr:
@@ -532,7 +532,7 @@ rule add_transmission_projects_and_dlr:
532532
resources:
533533
mem_mb=4000,
534534
script:
535-
"../scripts/add_transmission_projects_and_dlr.py"
535+
scripts("add_transmission_projects_and_dlr.py")
536536

537537

538538
def input_class_regions(w):
@@ -564,7 +564,7 @@ rule build_electricity_demand_base:
564564
resources:
565565
mem_mb=5000,
566566
script:
567-
"../scripts/build_electricity_demand_base.py"
567+
scripts("build_electricity_demand_base.py")
568568

569569

570570
rule build_hac_features:
@@ -587,7 +587,7 @@ rule build_hac_features:
587587
resources:
588588
mem_mb=10000,
589589
script:
590-
"../scripts/build_hac_features.py"
590+
scripts("build_hac_features.py")
591591

592592

593593
rule process_cost_data:
@@ -608,7 +608,7 @@ rule process_cost_data:
608608
resources:
609609
mem_mb=4000,
610610
script:
611-
"../scripts/process_cost_data.py"
611+
scripts("process_cost_data.py")
612612

613613

614614
rule simplify_network:
@@ -643,7 +643,7 @@ rule simplify_network:
643643
resources:
644644
mem_mb=12000,
645645
script:
646-
"../scripts/simplify_network.py"
646+
scripts("simplify_network.py")
647647

648648

649649
# Optional input when using custom busmaps - Needs to be tailored to selected base_network
@@ -720,7 +720,7 @@ rule cluster_network:
720720
resources:
721721
mem_mb=10000,
722722
script:
723-
"../scripts/cluster_network.py"
723+
scripts("cluster_network.py")
724724

725725

726726
def input_profile_tech(w):
@@ -796,7 +796,7 @@ rule add_electricity:
796796
resources:
797797
mem_mb=10000,
798798
script:
799-
"../scripts/add_electricity.py"
799+
scripts("add_electricity.py")
800800

801801

802802
rule prepare_network:
@@ -832,7 +832,7 @@ rule prepare_network:
832832
resources:
833833
mem_mb=4000,
834834
script:
835-
"../scripts/prepare_network.py"
835+
scripts("prepare_network.py")
836836

837837

838838
if (
@@ -880,7 +880,7 @@ if (
880880
resources:
881881
mem_mb=4000,
882882
script:
883-
"../scripts/clean_osm_data.py"
883+
scripts("clean_osm_data.py")
884884

885885
rule build_osm_network:
886886
message:
@@ -917,7 +917,7 @@ if (
917917
resources:
918918
mem_mb=4000,
919919
script:
920-
"../scripts/build_osm_network.py"
920+
scripts("build_osm_network.py")
921921

922922

923923
if config["electricity"]["base_network"] == "tyndp":
@@ -952,4 +952,4 @@ if config["electricity"]["base_network"] == "tyndp":
952952
resources:
953953
mem_mb=4000,
954954
script:
955-
"../scripts/build_tyndp_network.py"
955+
scripts("build_tyndp_network.py")

0 commit comments

Comments
 (0)