ESMValGroup / ESMValTool

ESMValTool: A community diagnostic and performance metrics tool for routine evaluation of Earth system models in CMIP
https://www.esmvaltool.org
Apache License 2.0
217 stars 127 forks source link

config file specification when running ESMValTool #2062

Closed rswamina closed 2 years ago

rswamina commented 3 years ago

Is it possible to --config-file as well as --config_file when running ESMValTool? Seems like they will both work.

@valeriupredoi note: see unreliable command line flags issue here https://github.com/ESMValGroup/ESMValCore/issues/936

valeriupredoi commented 3 years ago

no, the fact that they both seem to work is due to the fact that a wrong command line option does not raise an exception, see https://github.com/ESMValGroup/ESMValCore/issues/797 - this is something either @jvegasbsc or myself should fix, rather sooner than later

schlunma commented 3 years ago

I think they both work, just tested with --config-file, --config_file and --config-fiiiile. The first two runs go just fine, in the third run ESMValTool complains about a missing config file (in the default location):

FileNotFoundError: [Errno 2] No such file or directory: '~/.esmvaltool/config-user.yml'
valeriupredoi commented 3 years ago

be careful what you mean by "work" - only one option (config_user) works in that it grabs the file that you are actually specifying, the others are looking in the default location even if you specify a particular file, the effect of not even running with the command line flag at all

valeriupredoi commented 3 years ago

read @bouweandela 's issue a I linked, the symptoms are clearly described there, we really have to fix this behavior :+1:

schlunma commented 3 years ago

No, both --config-file and --config_file locate the file I'm specifying. I know since my default dir is empty (see error!).

valeriupredoi commented 3 years ago

if your default dir is empty, it'll grab it from the install target location, this thing is like your mum - you'll never win an argument with it, the problem is that you have to be careful that the file you need to be used is actually used

schlunma commented 3 years ago

I swear --- it uses the right one in both cases:

INFO: Using config file ~/config/mymodels.yml

which is definitely not the default dir or the installation location. It also finds my files which are in custom dirs, there's no way it does that with a default file.

When I specify the wrong argument on purpose (so something like --config-fiiiiile) I get:

FileNotFoundError: [Errno 2] No such file or directory: '~/.esmvaltool/config-user.yml'

So yes, both --config-file and --config_file work. I don't know how and why...but they do :laughing:

valeriupredoi commented 3 years ago

I'll be...did Javi sneakily code up AI with that change to fire? It's prob that _ and - are equivalent in whatever text interpreter fire uses, which is probably not safe - @jvegasbsc you know of that?

valeriupredoi commented 3 years ago

also, I do like that config-fiiile - clearly yodeling, we should customize our command line options based on where you are from :grin:

bouweandela commented 3 years ago

It's prob that _ and - are equivalent

In my experience they are, though I would recommend using the version with underscore in documentation and tutorials, because that's the way they are displayed when you run the --help command, e.g.

$ esmvaltool run -- --help
NAME
    esmvaltool run - Execute an ESMValTool recipe.

SYNOPSIS
    esmvaltool run RECIPE <flags>

DESCRIPTION
    `esmvaltool run` executes the given recipe. To see a list of available
    recipes or create a local copy of any of them, use the
    `esmvaltool recipes` command group.

POSITIONAL ARGUMENTS
    RECIPE
        Recipe to run, as either the name of an installed recipe or the path to a non-installed one.

FLAGS
    --config_file=CONFIG_FILE
        Type: Optional[]
        Default: None
        Configuration file to use. If not provided the file ${HOME}/.esmvaltool/config-user.yml will be used.
    --max_datasets=MAX_DATASETS
        Type: Optional[]
        Default: None
        Maximum number of datasets to use.
    --max_years=MAX_YEARS
        Type: Optional[]
        Default: None
        Maximum number of years to use.
    --skip_nonexistent=SKIP_NONEXISTENT
        Default: False
        If True, the run will not fail if some datasets are not available.
    --synda_download=SYNDA_DOWNLOAD
        Default: False
        If True, the tool will try to download missing data using Synda.
    --diagnostics=DIAGNOSTICS
        Type: Optional[]
        Default: None
        Only run the selected diagnostics from the recipe. To provide more than one diagnostic to filter use the syntax 'diag1 diag2/script1' or '("diag1", "diag2/script1")' and pay attention to the quotes.
    --check_level=CHECK_LEVEL
        Default: 'default'
        Configure the sensitivity of the CMOR check. Possible values are: `ignore` (all errors will be reported as warnings), `relaxed` (only fail if there are critical errors), default (fail if there are any errors), strict (fail if there are any warnings).
    Additional flags are accepted.

NOTES
    You can also use flags syntax for POSITIONAL ARGUMENTS

You can read all about fancy ways of using fire in it's documentation: https://google.github.io/python-fire/

An interesting feature is command line tab completion: https://google.github.io/python-fire/using-cli/#completion-flag

valeriupredoi commented 3 years ago

can this be closed @rswamina ? :beer:

egalytska commented 2 years ago

Since the issue is not yet closed I would also like to contribute. I just have recently installed ESMValTool v2.4 and started with running example python recipe as follows:

esmvaltool run examples/recipe_python.yml --config-file /path/to/my/config/file/config-user.yml

and it took quite a long time to figure out that ESMValTool reads the file from ${HOME}/.esmvaltool, but not from the path I specified.

At this point (i) it would be indeed useful if ESMValTool would not let me use a wrong command, or at least notified me that it is not valid; (ii) for some reason under ${HOME}/.esmvaltool there was an old config-user.yml file with options like write_plots, which was surprising since I did an ESMVAlTool v2.4 installation from scratch.

In the end I fixed the issue with esmvaltool config get-config-user --path=/path/to/my/config/file/ from the documentation here.

valeriupredoi commented 2 years ago

@egalytska very good point, and it's been an item on my (extended) to-do list (very extended, mind you :grin: ) - we do have an issue in Core https://github.com/ESMValGroup/ESMValCore/issues/936 for this sort of behavior so I'm going to close this for now :+1:

bouweandela commented 2 years ago

The problem described by @egalytska looks very similar to this issue: https://github.com/ESMValGroup/ESMValCore/issues/797

egalytska commented 2 years ago

Alright, good to know. Thanks for taking care @valeriupredoi