From 49d96354740cf02b32646bc55e71647437a205e9 Mon Sep 17 00:00:00 2001 From: Manuel Schlund <32543114+schlunma@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:52:54 +0200 Subject: [PATCH] Removed deprecated configuration option `offline` (#2213) --- esmvalcore/_main.py | 12 ---- esmvalcore/config/_config_validators.py | 50 ++------------ tests/integration/test_deprecated_config.py | 76 --------------------- tests/integration/test_main.py | 6 -- 4 files changed, 7 insertions(+), 137 deletions(-) diff --git a/esmvalcore/_main.py b/esmvalcore/_main.py index da5cdd0262..760ec054bd 100755 --- a/esmvalcore/_main.py +++ b/esmvalcore/_main.py @@ -337,7 +337,6 @@ def run(self, max_datasets=None, max_years=None, skip_nonexistent=None, - offline=None, search_esgf=None, diagnostics=None, check_level=None, @@ -365,15 +364,6 @@ def run(self, Maximum number of years to use. skip_nonexistent: bool, optional If True, the run will not fail if some datasets are not available. - offline: bool, optional - If True, the tool will not download missing data from ESGF. - - .. deprecated:: 2.8.0 - This option 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`). These are - exact replacements. search_esgf: str, optional If `never`, disable automatic download of data from the ESGF. If `when_missing`, enable the automatic download of files that are not @@ -405,8 +395,6 @@ def run(self, session['max_datasets'] = max_datasets if max_years is not None: session['max_years'] = max_years - if offline is not None: - session['offline'] = offline if search_esgf is not None: session['search_esgf'] = search_esgf if skip_nonexistent is not None: diff --git a/esmvalcore/config/_config_validators.py b/esmvalcore/config/_config_validators.py index 8f5e47375a..867370ae77 100644 --- a/esmvalcore/config/_config_validators.py +++ b/esmvalcore/config/_config_validators.py @@ -7,7 +7,7 @@ from collections.abc import Callable, Iterable from functools import lru_cache, partial from pathlib import Path -from typing import TYPE_CHECKING, Any, Optional, Union +from typing import Any, Optional, Union from packaging import version @@ -23,9 +23,6 @@ InvalidConfigParameter, ) -if TYPE_CHECKING: - from ._validated_config import ValidatedConfig - logger = logging.getLogger(__name__) @@ -288,7 +285,6 @@ def validate_diagnostics( 'extra_facets_dir': validate_pathtuple, 'log_level': validate_string, 'max_parallel_tasks': validate_int_or_none, - 'offline': validate_bool, 'output_dir': validate_path, 'output_file_type': validate_string, 'profile_diagnostic': validate_bool, @@ -339,44 +335,12 @@ def _handle_deprecation( warnings.warn(deprecation_msg, ESMValCoreDeprecationWarning) -def deprecate_offline( - validated_config: ValidatedConfig, - value: Any, - validated_value: Any, -) -> None: - """Deprecate ``offline`` option. - - Parameters - ---------- - validated_config: ValidatedConfig - ``ValidatedConfig`` instance which will be modified in place. - value: Any - Raw input value for ``offline`` option. - validated_value: Any - Validated value for ``offline`` option. - - """ - option = 'offline' - deprecated_version = '2.8.0' - remove_version = '2.10.0' - more_info = ( - " Please use the options `search_esgf=never` (for `offline=True`) or " - "`search_esgf=when_missing` (for `offline=False`) instead. These are " - "exact replacements." - ) - _handle_deprecation(option, deprecated_version, remove_version, more_info) - if validated_value: - validated_config['search_esgf'] = 'never' - else: - validated_config['search_esgf'] = 'when_missing' - - -_deprecators: dict[str, Callable] = { - 'offline': deprecate_offline, -} +# Example usage: see removed files in +# https://github.com/ESMValGroup/ESMValCore/pull/2213 +_deprecators: dict[str, Callable] = {} # Default values for deprecated options -_deprecated_options_defaults: dict[str, Any] = { - 'offline': True, -} +# Example usage: see removed files in +# https://github.com/ESMValGroup/ESMValCore/pull/2213 +_deprecated_options_defaults: dict[str, Any] = {} diff --git a/tests/integration/test_deprecated_config.py b/tests/integration/test_deprecated_config.py index 71905b53d2..8dec085134 100644 --- a/tests/integration/test_deprecated_config.py +++ b/tests/integration/test_deprecated_config.py @@ -1,8 +1,6 @@ import warnings from pathlib import Path -import pytest - import esmvalcore from esmvalcore.config import CFG, Config from esmvalcore.exceptions import ESMValCoreDeprecationWarning @@ -24,77 +22,3 @@ def test_no_deprecation_user_cfg(): cfg = Config(CFG.copy()) cfg.load_from_file(config_file) cfg.start_session('my_session') - - -def test_offline_default_cfg(): - """Test that ``offline`` is added for backwards-compatibility.""" - assert CFG['search_esgf'] == 'never' - assert CFG['offline'] is True - - -def test_offline_user_cfg(): - """Test that ``offline`` is added for backwards-compatibility.""" - config_file = Path(esmvalcore.__file__).parent / 'config-user.yml' - cfg = Config(CFG.copy()) - cfg.load_from_file(config_file) - assert cfg['search_esgf'] == 'never' - assert cfg['offline'] is True - - -def test_offline_default_session(): - """Test that ``offline`` is added for backwards-compatibility.""" - session = CFG.start_session('my_session') - assert session['search_esgf'] == 'never' - assert session['offline'] is True - - -def test_offline_user_session(): - """Test that ``offline`` is added for backwards-compatibility.""" - config_file = Path(esmvalcore.__file__).parent / 'config-user.yml' - cfg = Config(CFG.copy()) - cfg.load_from_file(config_file) - session = cfg.start_session('my_session') - assert session['search_esgf'] == 'never' - assert session['offline'] is True - - -def test_offline_deprecation_session_setitem(): - """Test that the usage of offline is deprecated.""" - msg = "offline" - session = CFG.start_session('my_session') - session.pop('search_esgf') # test automatic addition of search_esgf - with pytest.warns(ESMValCoreDeprecationWarning, match=msg): - session['offline'] = True - assert session['offline'] is True - assert session['search_esgf'] == 'never' - - -def test_offline_deprecation_session_update(): - """Test that the usage of offline is deprecated.""" - msg = "offline" - session = CFG.start_session('my_session') - session.pop('search_esgf') # test automatic addition of search_esgf - with pytest.warns(ESMValCoreDeprecationWarning, match=msg): - session.update({'offline': False}) - assert session['offline'] is False - assert session['search_esgf'] == 'when_missing' - - -def test_offline_true_deprecation_config(monkeypatch): - """Test that the usage of offline is deprecated.""" - msg = "offline" - monkeypatch.delitem(CFG, 'search_esgf') - with pytest.warns(ESMValCoreDeprecationWarning, match=msg): - monkeypatch.setitem(CFG, 'offline', True) - assert CFG['offline'] is True - assert CFG['search_esgf'] == 'never' - - -def test_offline_false_deprecation_config(monkeypatch): - """Test that the usage of offline is deprecated.""" - msg = "offline" - monkeypatch.delitem(CFG, 'search_esgf') - with pytest.warns(ESMValCoreDeprecationWarning, match=msg): - monkeypatch.setitem(CFG, 'offline', False) - assert CFG['offline'] is False - assert CFG['search_esgf'] == 'when_missing' diff --git a/tests/integration/test_main.py b/tests/integration/test_main.py index 3ea26c56ed..4eb578150d 100644 --- a/tests/integration/test_main.py +++ b/tests/integration/test_main.py @@ -119,12 +119,6 @@ def test_run_with_max_datasets(): run() -@patch('esmvalcore._main.ESMValTool.run', new=wrapper(ESMValTool.run)) -def test_run_with_offline(): - with arguments('esmvaltool', 'run', 'recipe.yml', '--offline'): - run() - - @patch('esmvalcore._main.ESMValTool.run', new=wrapper(ESMValTool.run)) def test_run_with_search_esgf(): with arguments('esmvaltool', 'run', 'recipe.yml', '--search_esgf=always'):