Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement config versioning #1058

Merged
merged 12 commits into from
Jul 17, 2024

Conversation

ekatef
Copy link
Member

@ekatef ekatef commented Jul 9, 2024

Changes proposed in this Pull Request

Implements a check to ensure that the current local config.yaml is consistent with the version defined in config.default.yaml.

Checklist

  • I consent to the release of this PR's code under the AGPLv3 license and non-code contributions under CC0-1.0 and CC-BY-4.0.
  • I tested my contribution locally and it seems to work fine.
  • Code and workflow changes are sufficiently documented.
  • Newly introduced dependencies are added to envs/environment.yaml and doc/requirements.txt.
  • Changes in configuration options are added in all of config.default.yaml and config.tutorial.yaml.
  • Add a test config or line additions to test/ (note tests are changing the config.tutorial.yaml)
  • Changes in configuration options are also documented in doc/configtables/*.csv and line references are adjusted in doc/configuration.rst and doc/tutorial.rst.
  • A note for the release notes doc/release_notes.rst is amended in the format of previous release notes, including reference to the requested PR.

@ekatef
Copy link
Member Author

ekatef commented Jul 9, 2024

@davide-f have drafted a possible implementation. Could you please have a look?

Have added one more field to the version number to track the changes in the config. Not sure it's the most elegant solution, though.

A possible improvement could be to add a check on the differences between the local config and config.default.yaml. Sometimes, it feels a good idea to have an opportunity to review the recent updates in the configuration options. However, not sure Snakemake traceback is the best place to place results of such a check. Probably, having an additional helper function would be a better idea. What is your feeling about that?

@ekatef ekatef mentioned this pull request Jul 10, 2024
8 tasks
Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great @ekatef :D
Beyond the minor comments, please add a release doc :)

Snakefile Outdated Show resolved Hide resolved
@@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: CC0-1.0

version: 0.3.0
version: 0.3.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: CC0-1.0

version: 0.3.0
version: 0.3.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

@ekatef ekatef force-pushed the implement_config_versioning branch from 39d050c to 41b4b62 Compare July 11, 2024 20:23
@ekatef
Copy link
Member Author

ekatef commented Jul 11, 2024

Great @ekatef :D Beyond the minor comments, please add a release doc :)

Done 🙂 Thanks a lot for the review!

I'm thinking what would be the best way to remind that a release is needed every time, when the config structure gets changed. Adding a point for that to PR template sounds like not a really good idea, but I don't have better ones at the moment. What is your perspective on that?

Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great @ekatef :D

I've added a minor comment. Moreover there is a minor merge conflict to fix.
This PR is ready to go afterwards. If you like to include these minor changes, that would be nice but the functionality is there.
Afterwards, if CI passes, feel free to merge yourself :)

Snakefile Outdated
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later

import sys
import yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop this line? it seems is not needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, have forgotten to remove it. Thanks!

Comment on lines 30 to 39
def check_config_version(config):
"""
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("config.default.yaml", "r") as f:
actual_config = yaml.safe_load(f)
actual_config_version = actual_config.get("version")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd propose to have the file path as parameter here, like:

Suggested change
def check_config_version(config):
"""
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("config.default.yaml", "r") as f:
actual_config = yaml.safe_load(f)
actual_config_version = actual_config.get("version")
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")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, done!

@ekatef
Copy link
Member Author

ekatef commented Jul 17, 2024

Great @ekatef :D

I've added a minor comment. Moreover there is a minor merge conflict to fix. This PR is ready to go afterwards. If you like to include these minor changes, that would be nice but the functionality is there. Afterwards, if CI passes, feel free to merge yourself :)

@davide-f fixed! Thank you 😄 Ok, then I'm merging it.

As a comment, the current implementation writes an error in logs in case the config is outdated, but don't terminate execution. Leaving that for now, while it can be improved further when introducing better management of the configs.

@ekatef ekatef merged commit 11e773a into pypsa-meets-earth:main Jul 17, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants