Use Pydantic-Settings for improved Config#9
Open
mmaelicke wants to merge 1 commit into
Open
Conversation
mmaelicke
commented
Oct 27, 2024
Author
mmaelicke
left a comment
There was a problem hiding this comment.
short review of changes that I did in addition to the switch to the conf-pydantic settings.
Comment on lines
+53
to
+57
| # EDIT mmaelicke: | ||
| # This file was in the original repo and hardcoded in the script. | ||
| # I move this into the config for reasons of readability and clarity. | ||
| # This file has the merged "megabasins_gdf" in it | ||
| MERIT_BASINS_SHP: str = 'data/shp/basins_level2/merit_hydro_vect_level2.shp' |
Author
There was a problem hiding this comment.
Note this change:
I added this path to the config as it was hard to spot before. On my system the data folder is located somewhere else, thus, I needed to config it.
Comment on lines
-329
to
+335
| merit_basins_shp = 'data/shp/basins_level2/merit_hydro_vect_level2.shp' | ||
| megabasins_gdf = gpd.read_file(merit_basins_shp) | ||
| #merit_basins_shp = 'data/shp/basins_level2/merit_hydro_vect_level2.shp' | ||
| megabasins_gdf = gpd.read_file(conf.MERIT_BASINS_SHP) |
Author
There was a problem hiding this comment.
This is the change I added to get rid of the hardcoded path in the middle of the script. Relates to my last comment
Comment on lines
+743
to
+744
| except Exception as e: | ||
| raise Warning(f"Could not save pickle file to: {pickle_fname}. Message: {str(e)}") |
Author
There was a problem hiding this comment.
here I changed the exception handling a bit to log out a message of the actual error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey there,
Thanks for this great repo!
I rewrote parts to use pedantic-settings over global variables. This way, it's as easy as before to change the config, I also kept all config names as they were. However, with pydantic it is possible to create a config programmatically and even load from environment variables or .env files.
I need this as I run this code in a docker container and there is no easy way to change the config. These changes also help to use the repo additionally more like a library as importing is a bit easier this way.
I hope you like the changes.
Best,
Mirko