Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combined offline and always_search_esgf into a single option search_esgf #1935

Merged
merged 185 commits into from
Mar 1, 2023

Conversation

schlunma
Copy link
Contributor

@schlunma schlunma commented Feb 17, 2023

Description

Deprecation

This PR adds a new config option search_esgf, which replaces the old options offline and always_search_esgf. offline has been deprecated (scheduled for removal in v2.10.0), always_search_esgf is simply removed (has not been included in a release yet). The following table shows the usage of the new option:

Old offline Old always_search_esgf New search_esgf Description
False False 'when_missing' Use local files when possible (regardless of version), otherwise download
False True 'always' Use local files only if latest version is available, otherwise download
True False 'never' Only use local files, never download
True True 'never' Only use local files, never download

In addition, this PR cleans and unifies the code to deprecate configuration options in order to allow changing one configuration option (e.g., search_esgf) based on another (deprecated) option (e.g., offline). In addition, now a deprecation warning is always raised when that option is use. Previously, only a warning was raised when the option was different to the default.

Closes #1931

Link to documentation:


Before you get started

Checklist

It is the responsibility of the author to make sure the pull request is ready to review. The icons indicate whether the item will be subject to the 🛠 Technical or 🧪 Scientific review.


To help with the number pull requests:

- Use configuration from experimental

Output file is now a Path

fx file facets are now correctly set when parsing the recipe, no need to do it in data finder anymore
@schlunma
Copy link
Contributor Author

schlunma commented Feb 28, 2023

Thanks for picking this up @schlunma! When I run the tool with offline: false in config-user.yml, I get the deprecation warning twice:

/home/bandela/src/esmvalgroup/esmvalcore/esmvalcore/config/_config_validators.py:340: ESMValCoreDeprecationWarning: The configuration option or command line argument `offline` has been deprecated in ESMValCore version 2.8.0 and is scheduled for removal in version 2.10.0. Please use the options `search_esgf=never` (for `offline=True`) or `search_esgf=when_missing` (for `offline=False`) instead. These are exact replacements.
  warnings.warn(deprecation_msg, ESMValCoreDeprecationWarning)
/home/bandela/src/esmvalgroup/esmvalcore/esmvalcore/_config/__init__.py:13: ESMValCoreDeprecationWarning: The private module `esmvalcore._config` has been deprecated in ESMValCore version 2.8.0 and is scheduled for removal in version 2.9.0. Please use the public module `esmvalcore.config` instead.
  warnings.warn(
/home/bandela/src/esmvalgroup/esmvalcore/esmvalcore/config/_config_validators.py:340: ESMValCoreDeprecationWarning: The configuration option or command line argument `offline` has been deprecated in ESMValCore version 2.8.0 and is scheduled for removal in version 2.10.0. Please use the options `search_esgf=never` (for `offline=True`) or `search_esgf=when_missing` (for `offline=False`) instead. These are exact replacements.
  warnings.warn(deprecation_msg, ESMValCoreDeprecationWarning)

This is weird, I am only getting it once (tested with every combination of offline as config file option and command line argument). Due to the way sessions and configs are created the code that issues the warnings runs more than once, but the default setting of the warnings module is to show warnings just once for each location, so I would only expect this warning once.

However, I also noticed to other problems:

  • The deprecation warnings shown at the very beginning on screen are missing in the log files (regular + debug log). I guess the reasons is that logging is not configured that that stage, but this is really a problem for user who don't use the tool interactively. They will never see this deprecation warning.
  • I get the deprecation warning about use_legacy_supplementaries even though I am not using this in my config file/command line and the recipe does not include fx_variables:. I will investigate this. EDIT: This has been solved in 156884c.

@schlunma
Copy link
Contributor Author

schlunma commented Feb 28, 2023

Thanks for picking this up @schlunma! When I run the tool with offline: false in config-user.yml, I get the deprecation warning twice:

/home/bandela/src/esmvalgroup/esmvalcore/esmvalcore/config/_config_validators.py:340: ESMValCoreDeprecationWarning: The configuration option or command line argument `offline` has been deprecated in ESMValCore version 2.8.0 and is scheduled for removal in version 2.10.0. Please use the options `search_esgf=never` (for `offline=True`) or `search_esgf=when_missing` (for `offline=False`) instead. These are exact replacements.
  warnings.warn(deprecation_msg, ESMValCoreDeprecationWarning)
/home/bandela/src/esmvalgroup/esmvalcore/esmvalcore/_config/__init__.py:13: ESMValCoreDeprecationWarning: The private module `esmvalcore._config` has been deprecated in ESMValCore version 2.8.0 and is scheduled for removal in version 2.9.0. Please use the public module `esmvalcore.config` instead.
  warnings.warn(
/home/bandela/src/esmvalgroup/esmvalcore/esmvalcore/config/_config_validators.py:340: ESMValCoreDeprecationWarning: The configuration option or command line argument `offline` has been deprecated in ESMValCore version 2.8.0 and is scheduled for removal in version 2.10.0. Please use the options `search_esgf=never` (for `offline=True`) or `search_esgf=when_missing` (for `offline=False`) instead. These are exact replacements.
  warnings.warn(deprecation_msg, ESMValCoreDeprecationWarning)

@remi-kazeroni and I found the reason for this! I don't use a user config file called ~/.esmvaltool/config-user.yml, Remi does. I only get this warning once, Remi twice. I guess you have a default config as well @bouweandela?

This has not been introduced with this PR. If you use the main branch you'll also get two deprecation warnings if you use use_legacy_supplementaries in the default config in ~/.esmvaltool/config-user.yml.

I have no idea what's going on there. Since the warning is raised twice from the exact same location, it should only be printed once. If no one has an idea about this, I suggest we simply ignore this. Two warnings is better than no warning.

@bouweandela
Copy link
Member

The warning was issued twice because it is first issued from the esmvalcore.config module when it the config-user.yml file is loaded when the module is loaded, and then from the emvalcore._main module when the config-user.yml file gets loaded there. The default filter prints a warning once for every module that issues it. I just pushed 5eeed56 that should solve the issue.

Maybe you already know about this, but I found the code

import traceback
traceback.print_stack()

very useful to find out from where the function that raised the deprecation warning was getting called.

@bouweandela
Copy link
Member

I found a really simple way to print the warnings issued from loading the configuration file again and added it in a05c7d1. Please feel free to not use that if you find it doesn't do a good job.

@schlunma
Copy link
Contributor Author

The warning was issued twice because it is first issued from the esmvalcore.config module when it the config-user.yml file is loaded when the module is loaded, and then from the emvalcore._main module when the config-user.yml file gets loaded there. The default filter prints a warning once for every module that issues it. I just pushed 5eeed56 that should solve the issue.

Ahh, that makes sense. I missed the part about "once per module" 🤦

Unfortunately, your change didn't work for me. I am still getting two warnings with .esmvaltool/config-user.yml, and now even three warnings when I use a command line argument AND a configuration option.

Maybe we should simply use the filter option "once"?

I found a really simple way to print the warnings issued from loading the configuration file again and added it in a05c7d1. Please feel free to not use that if you find it doesn't do a good job.

That worked great for me! Maybe trying to solve this for all deprecation warnings was overly enthusiastic 😃

@bouweandela
Copy link
Member

Will have another look..

Copy link
Contributor

@valeriupredoi valeriupredoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review of docstrings, and docs, bud

doc/quickstart/configure.rst Outdated Show resolved Hide resolved
doc/quickstart/configure.rst Outdated Show resolved Hide resolved
doc/quickstart/configure.rst Outdated Show resolved Hide resolved
doc/quickstart/configure.rst Outdated Show resolved Hide resolved
doc/quickstart/configure.rst Outdated Show resolved Hide resolved
doc/quickstart/configure.rst Outdated Show resolved Hide resolved
esmvalcore/_main.py Outdated Show resolved Hide resolved
Copy link
Contributor

@valeriupredoi valeriupredoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple more minor comments from me 🍺

setup.py Show resolved Hide resolved
esmvalcore/dataset.py Show resolved Hide resolved
Copy link
Contributor

@valeriupredoi valeriupredoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're a ⭐ Manu! Cheers for all this wonderful work - together with @bouweandela I nominate you guys for the Contributors of the Version Award for 2.8 🏆

@bouweandela
Copy link
Member

Unfortunately, your change didn't work for me. I am still getting two warnings with .esmvaltool/config-user.yml, and now even three warnings when I use a command line argument AND a configuration option.

Maybe we should simply use the filter option "once"?

It only works when you specify no configuration file, i.e. with the command esmvaltool run examples/recipe_python.yml. Unfortunately, I ran out of time to fix this today and I'm not working tomorrow, so please feel free to undo the code changes I made if you think the previous behavior was better.

@schlunma
Copy link
Contributor Author

I suggest we just live with multiple warnings then, I also tried to solve this with action=once but was not succesful.

If there are no further comments I suggest to merge this by noon tomorrow. Thanks everyone for reviewing!!

@valeriupredoi
Copy link
Contributor

aren't the warnings being generated by different, multiple, tasks? I couldn't care less for multiple warning TBF - if at all, show them more often, maybe somebody decides to pay attention to them 😆

@schlunma
Copy link
Contributor Author

I think they are all issues from the same process (all the reading of the config file happens at the very beginning of the run where we only have a single process as far as I am aware).

@remi-kazeroni
Copy link
Contributor

Thanks a lot @schlunma for your nice work and @valeriupredoi and @bouweandela for reviewing it. I would really like to move on with the feature freeze and the release. It looks to me that issue #1931 is fully addressed by this PR. Should you want to improve the handling of the warnings, I would recommend to open an issue based on findings made in this PR to keep track of things.

@remi-kazeroni remi-kazeroni merged commit 40e00e8 into main Mar 1, 2023
@remi-kazeroni remi-kazeroni deleted the search_esgf_option branch March 1, 2023 15:46
@valeriupredoi
Copy link
Contributor

awesome 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Combine offline and always_search_esgf into a single option search_esgf
5 participants