esm-tools / esm_rcfile

GNU General Public License v2.0
1 stars 0 forks source link

Suggestion: Get rid of .esmtoolsrc #1

Open seb-wahl opened 4 years ago

seb-wahl commented 4 years ago

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 replace esm_rcfile with a simple environment variable $ESM_TOOLS or similar in the next release (not 4.2 :-) )

pgierz commented 4 years ago

YES please....

seb-wahl commented 4 years ago

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.

pgierz commented 4 years ago

@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.:

  1. XDG-Standard Conform configuration directories: if $XDG_CONFIG_HOME, or, if this is not set: /etc/esm_tools/config.yaml, ${HOME}/.config/esm_tools/config.yaml
  2. Environmental Variable for directory: $ESM_TOOLS_CONFIG_DIR/config.yaml
  3. Environmental Variable for specific settings: 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:

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)