Open seb-wahl opened 4 years ago
YES please....
YES please....
I'll have a go at this soon. I don't know how many hours I wasted by testing with the wrong version of the tools during development, only because .esmtoolsrc
was not up to date.
@seb-wahl: I have a neat idea for this: https://everett.readthedocs.io/en/latest/
It allows you to easily write configuration that looks in multiple places, e.g.:
$XDG_CONFIG_HOME
, or, if this is not set:
/etc/esm_tools/config.yaml
, ${HOME}/.config/esm_tools/config.yaml
$ESM_TOOLS_CONFIG_DIR/config.yaml
ESM_TOOLS_DKRZ_LOGIN
(and others)The preference order can be defined however we want.
The configuration file would look like this:
esm_tools:
read_from_package: False # Set to true to use yaml in the package rather than from disk
function_path: /some/path
namelist_path: /some/path
dkrz:
username: a270077
ollie:
username: pgierz
This translates to the following env variables which would also be used:
$ESM_TOOLS_READ_FROM_PACKAGE
$ESM_TOOLS_FUNCTION_PATH
$ESM_TOOLS_DKRZ_USERNAME
(Note here the namespace seperation via _
)Note also the read from package isn't implemented yet, but I think it would be a nice option (discussion here: https://github.com/esm-tools/esm_tools/pull/84; code is there but not used yet) if we ever want to hide more of the defaults from the users, as we already have confusion (https://github.com/esm-tools/esm_tools/issues/117)
Furthermore, you can easily add documentation for the configuration and options with a Sphinx add-in. Since we anyway use Sphinx for the rest of the documentation, that would add nicely.
I've used this before for another project, see here: https://github.com/pgierz/namelist_diff/blob/master/namelist_diff/config.py and https://namelist-diff.readthedocs.io/en/latest/, specifically https://namelist-diff.readthedocs.io/en/latest/configuration.html (autogenerated from the code)
Especially when working with multiple installations (e.g. in a python venv), the
~/.esmtoolsrc
is always in the way. Given it's content I suggest replaceesm_rcfile
with a simple environment variable$ESM_TOOLS
or similar in the next release (not 4.2 :-) )