Skip to content

Commit

Permalink
Merge pull request #1058 from ekatef/implement_config_versioning
Browse files Browse the repository at this point in the history
* Read the actual config version form config.default

* Add an import

* Add a check for the configs versions

* Update a version in the config

* Revert changes in a config version

* Move a versions check into helpers

* Revise naming

* Revise an error message

* Add a release note

* Implement Davide's suggestion

Co-authored-by: Davide Fioriti <[email protected]>

* Remove import

---------

Co-authored-by: Davide Fioriti <[email protected]>
  • Loading branch information
ekatef and davide-f authored Jul 17, 2024
1 parent 91a438d commit 11e773a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ from shutil import copyfile, move

from snakemake.remote.HTTP import RemoteProvider as HTTPRemoteProvider

from _helpers import create_country_list, get_last_commit_message
from _helpers import create_country_list, get_last_commit_message, check_config_version
from build_demand_profiles import get_load_paths_gegis
from retrieve_databundle_light import datafiles_retrivedatabundle
from pathlib import Path


HTTP = HTTPRemoteProvider()

if "config" not in globals() or not config: # skip when used as sub-workflow
Expand All @@ -25,6 +26,9 @@ if "config" not in globals() or not config: # skip when used as sub-workflow
configfile: "config.yaml"


check_config_version(config=config)


configfile: "configs/bundle_config.yaml"


Expand Down
2 changes: 2 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ E.g. if a new rule becomes available describe how to use it `snakemake -j1 run_t

* Create files where the code outputs the value of the objective function. `PR #1033 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1033>`__

* Introduce versioning of the configuration files. `PR #1058 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1058>`__

* Fix bug for hydro inflow normalization for gadm regions (alternative clustering). `PR #1057 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/1057>`__

* Minor bug-fixing for s_nom_min. `PR #961 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/961>`__
Expand Down
22 changes: 22 additions & 0 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@
REGIONS_CONFIG = "regions_definition_config.yaml"


def check_config_version(config, fp_config="config.default.yaml"):
"""
Check that a version of the local config.yaml matches to the actual config
version as defined in config.default.yaml.
"""

# using snakemake capabilities to deal with yanl configs
with open(fp_config, "r") as f:
actual_config = yaml.safe_load(f)
actual_config_version = actual_config.get("version")

current_config_version = config.get("version")

if actual_config_version != current_config_version:
logger.error(
f"The current version of 'config.yaml' doesn't match to the code version:\n\r"
f" {current_config_version} provided, {actual_config_version} expected.\n\r"
f"That can lead to weird errors during execution of the workflow.\n\r"
f"Please update 'config.yaml' according to 'config.default.yaml' ."
)


def handle_exception(exc_type, exc_value, exc_traceback):
"""
Customise errors traceback.
Expand Down

0 comments on commit 11e773a

Please sign in to comment.