Skip to content

Commit

Permalink
Removed deprecated configuration option offline (#2213)
Browse files Browse the repository at this point in the history
  • Loading branch information
schlunma authored Oct 4, 2023
1 parent bd3b9a4 commit 49d9635
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 137 deletions.
12 changes: 0 additions & 12 deletions esmvalcore/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
50 changes: 7 additions & 43 deletions esmvalcore/config/_config_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -23,9 +23,6 @@
InvalidConfigParameter,
)

if TYPE_CHECKING:
from ._validated_config import ValidatedConfig

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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] = {}
76 changes: 0 additions & 76 deletions tests/integration/test_deprecated_config.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'
6 changes: 0 additions & 6 deletions tests/integration/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down

0 comments on commit 49d9635

Please sign in to comment.