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
Configuration management: Allow for creating / saving / loading configuration on the fly. #23
Conversation
The config module defines a new config class and implements a config object to be shared globally across modules. The .yaml file prototype contains the supported structure (yaml) and variables including defaults.
Constructor now returns empty objects if neither dictionary nor path are provided. The default locations are only searched for and evaluated when the module is first imported.
Include instructions.
Change the config to work as a singelton (module) instead of a class and objects. The config is now really shared among modules, instead only of a copy of the same object.
This reverts commit d67cb2e.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, i have a few comments from a first read-through.
Hmm .. the module variable scheme you are using, means one cannot use two different cutouts with separate config settings (which is probably not necessary).
I have to think about your proposal (and its implications) to use the config path as base directory for all data access.
Thanks for the remarks!
Correct. I was toying for literally a week with different approaches and looking at different best practices.
The choice for the base directory for relative paths was hard, but this makes IMHO most sense, as I would expect users (read: myself) to place a custom configuration if I need it inside the project-directory next to the cutouts and resources like turbine configs. But that was also the idea of implementing the |
After resolving the remaining todo's I will review it a second time and I think it's good to go then. Great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that config.py
became even simpler in the last iteration.
Just a few cosmetic changes and this is good to go!
Changes included. |
After doing some overengineering on the config management, now a adequately pythonic solution.
The
config.py
module provides the module for all other modules viaChanges to objects of the module can either be directly, e.g.
Or via a dictionary update:
Config can be read and written with
config.read(p)
andconfig.save(p)
.The config file is in
yaml
style and a default config is provided.Relative and absolute paths are supported, for this a new auxiliary function is introduced in
utils.py
:construct_filepath(path)
reads a path and - if it is a relative path - returns the corresponding absolute path. Relative paths are considered relative to the directory of the currently in use configuration file viaconfig.config_path
.If this variable is also not set, then the relative file is returned unchanged (i.e. relative to current directory).
Any absolute
path
is immediatley returned unchanged.NB: Need to squash when merging.
Fixes #4.