ConfigManager class with update_config functionality#78
Conversation
|
@ddundo Let me know what you think of this. I suspect that the current tests would fail right now, since the way the config.yaml file is read in in the test notebooks now needs updating. If I update the notebooks in PyGEM-notebooks and submit a related PR to the |
|
Closes #77 |
|
PyGEM-notebooks PR #12 updates all notebooks to work with the new ConfigManager class reading. |
There was a problem hiding this comment.
Thanks for this @btobers! I made some initial comments but I think more changes will be necessary. I will also think about how to nicely test notebooks on non-main branches. I'll try to do that tomorrow.
Also, we should add tests whenever we add a new functionality. So for example, you could add a new file in pygem/tests called test_config.py which would have tests like this one:
def test_update_config():
updates = {
"sim.nsims": "5",
"user.email": "updated@example.com",
"constants.density_ice": "850"
}
config_manager = ConfigManager() # or whatever needs to go here
config_manager.update_config(updates)
config = config_manager.read_config()
assert config["sim"]["nsims"] == 5
assert config["user"]["email"] == "updated@example.com"
assert config["constants"]["density_ice"] == 850so this tests that the update_config method does what it's supposed to do. And similarly for other methods. Then these will automatically be tested in the CI.
Let me know if I can help with this :)
…oved to clean up the class and remove redundancy
|
Cleaned up |
|
@ddundo if you want to take another look at this, I cleaned up the ConfigManager class a little bit, adding error raising in the update_config function, and also created a simple config test function as you had mentioned. |
Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com>
Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com>
ddundo
left a comment
There was a problem hiding this comment.
Nice! There are still some kinks to work out, but already looks better :) And yeah I'd encourage you to write tests first since that will help you identify bugs too.
|
The expanded tests look nice - although I'm not sure the TypeErrors will be flexible enough given the current format of the configuration file. This is why I only had a few type checks in the |
#63 is now ready for review. When that gets merged, you could temporarily change It's not the best solution, but I think it's fine for now. In the future we can discuss how to best handle this. For example, maybe we could add PyGEM-notebooks as a git submodule (see https://git-scm.com/book/en/v2/Git-Tools-Submodules). |
Great, I'll do this after we Merge branch |
There was a problem hiding this comment.
I left comments, after which I think it will be good to go :) There are a few comments about making some methods private. Private methods are essentially methods that we don't want users to use themselves.
Before addressing the comments, I'd suggest you merge dev into this branch to pick up the latest changes and to resolve the conflict it reports.
Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com>
Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com>
Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com>
Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com>
|
@ddundo all issues resolved. All tests passed, but then once I switched the git clone of PyGEM-notebooks in the notebook tests all fail. Any thoughts on how we should handle this? As of now, until we merge both repo's So the following for PyGEM And then for PyGEM I don't know if there's a way to logic the |
* config.py now object oriented and contains update_config() function * all prior calls to config updated for compatability with new config.ConfigManager class * raise errors, and ensure that dictionary keys are not overwritten * create_config() function created and _prompt_overwrite() function removed to clean up the class and remove redundancy * config test created * update source_config_path Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com> * remove self.package_dir definition * update source path Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com> * rename ruamel.yaml.YAML() as ryaml * call ensure_config() upon __init__ * user config validation, make sure necessary keys exist * ConfigManager.ensure_config() calls removed, now handled on __init__ * bug fix with commit:4fd5493 * more tests added to test_config * more tests and TypeError checks in update_config * test ensure config, no overwrite * remove CLI update_config funcitonality * Handle datatypes in `config.yaml` and expand tests (#79) * clean up imports Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com> * add `advanced_test_tw.ipynb` test * typo fix * add __all__ variable Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com> * cleanup commenting Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com> * cleanup commenting Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com> * more descriptive variable in validate_config * private methods and expanded docstrings * swap PyGEM-Notebooks clone repo back to main branch * clone appropriate PyGEM-notebook brach * comment added --------- Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com>
…nity#78) * config.py now object oriented and contains update_config() function * all prior calls to config updated for compatability with new config.ConfigManager class * raise errors, and ensure that dictionary keys are not overwritten * create_config() function created and _prompt_overwrite() function removed to clean up the class and remove redundancy * config test created * update source_config_path Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com> * remove self.package_dir definition * update source path Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com> * rename ruamel.yaml.YAML() as ryaml * call ensure_config() upon __init__ * user config validation, make sure necessary keys exist * ConfigManager.ensure_config() calls removed, now handled on __init__ * bug fix with commit:4fd5493 * more tests added to test_config * more tests and TypeError checks in update_config * test ensure config, no overwrite * remove CLI update_config funcitonality * Handle datatypes in `config.yaml` and expand tests (PyGEM-Community#79) * clean up imports Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com> * add `advanced_test_tw.ipynb` test * typo fix * add __all__ variable Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com> * cleanup commenting Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com> * cleanup commenting Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com> * more descriptive variable in validate_config * private methods and expanded docstrings * swap PyGEM-Notebooks clone repo back to main branch * clone appropriate PyGEM-notebook brach * comment added --------- Co-authored-by: Davor Dundovic <33790330+ddundo@users.noreply.github.com>
Closes #72.
ConfigManagerclass added toconfig.py, which now includes anupdate_config()function. This will allow for the advanced_test_tw notebook to be run as another test, as theinclude_frontalablationsetting in ~/PyGEM/config.yaml can now be updated programmatically. Need to update all PyGEM-Community/PyGEM-notebooks to match. the new structure.