-
Notifications
You must be signed in to change notification settings - Fork 18
Description
So far, HydPy does not yet provide a way to save the project settings made in module pub. If you need to use the same settings later or, for example, in different scripts, it is currently the best practice to write one Python script that makes these settings, for example:
my_settings.py
from hydpy import HydPy, pub
hp = HydPy('my_project')
pub.timegrids = '2000-01-01', '2001-01-01', '1d'
pub.options.checkseries = False
pub.networkmanager.currentdir = 'my_folder'
Then, you can import these settings in each script (or in the Python Interpreter) as follows:
my_script.py
from my_settings import *
...
The idea is, to improve the string representation of the pub module (which is already the object of the HydPy-class Pub, derived from Module). As always, the string representation should be executable code as far as possible and be applicable to restore the current configuration of the object. To achieve this goal, we would also need to improve the string representations of some other classes (e.g. Options and ControlManager).
An additional method of class Pub to save the string representation directly into a file would be convenient.
We should discuss if we also want to support saving custom settings. For example, one could also use the module pub to save some constants relevant for different scripts. But this would be restricted to using objects already coming with suitable string representations. So, strings and numbers would be fine, but more complex objects probably not. (We could implement a check into method setattr of module Pub, which executes the string representation for each given attribute and compares the old with the new object.)