Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions doc/quickstart/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,6 @@ Within a directory, files are sorted lexicographically, and later files (e.g.,
files (like the old ``config-developer.yml`` files) will lead to errors.
Make sure to move these files to a different directory.

.. deprecated:: 2.12.0

If a single configuration file is present at its deprecated location
``~/.esmvaltool/config-user.yml`` or specified via the deprecated command
line argument ``--config_file``, all potentially available new configuration
files at ``~/.config/esmvaltool/`` and/or the location specified via
``--config_dir`` are ignored.
This ensures full backwards-compatibility.
To switch to the new configuration system outlined here, move your old
configuration file to ``~/.config/esmvaltool/`` or to the location specified
via ``--config_dir``, remove ``~/.esmvaltool/config-user.yml``, and omit the
command line argument ``--config_file``.
Alternatively, specifying the environment variable ``ESMVALTOOL_CONFIG_DIR``
will also force the usage of the new configuration system regardless of the
presence of any potential old configuration files.
Support for the deprecated configuration will be removed in version 2.14.0.

To get a copy of the default configuration file, you can run

.. code-block:: bash
Expand Down
79 changes: 19 additions & 60 deletions esmvalcore/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@
import logging
import os
import sys
import warnings
from importlib.metadata import entry_points
from pathlib import Path

import fire

from esmvalcore.config._config import warn_if_old_extra_facets_exist
from esmvalcore.exceptions import ESMValCoreDeprecationWarning

# set up logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -401,7 +399,6 @@ def run(self, recipe, **kwargs):

"""
from .config import CFG
from .config._dask import warn_if_old_dask_config_exists
from .exceptions import InvalidConfigParameter

cli_config_dir = kwargs.pop("config_dir", None)
Expand All @@ -413,38 +410,6 @@ def run(self, recipe, **kwargs):
f"existing directory"
)
raise NotADirectoryError(msg)

# TODO: remove in v2.14.0
# At this point, --config_file is already parsed if a valid file has
# been given (see
# https://github.com/ESMValGroup/ESMValCore/issues/2280), but no error
# has been raised if the file does not exist. Thus, reload the file
# here with `load_from_file` to make sure a proper error is raised.
if "config_file" in kwargs:
if os.environ.get("ESMVALTOOL_CONFIG_DIR"):
deprecation_msg = (
"Usage of a single configuration file specified via CLI "
"argument `--config_file` has been deprecated in "
"ESMValCore version 2.12.0 and is scheduled for removal "
"in version 2.14.0. Since the environment variable "
"ESMVALTOOL_CONFIG_DIR is set, old configuration files "
"present at ~/.esmvaltool/config-user.yml and/or "
"specified via `--config_file` are currently ignored. To "
"silence this warning, omit CLI argument `--config_file`."
)
warnings.warn(
deprecation_msg,
ESMValCoreDeprecationWarning,
stacklevel=2,
)
kwargs.pop("config_file")
else:
cli_config_dir = kwargs["config_file"]
CFG.load_from_file(kwargs["config_file"])

# New in v2.12.0: read additional configuration directory given by CLI
# argument
if CFG.get("config_file") is None and cli_config_dir is not None:
try:
CFG.update_from_dirs([cli_config_dir])
except InvalidConfigParameter as exc:
Expand Down Expand Up @@ -475,7 +440,6 @@ def run(self, recipe, **kwargs):
CFG.update_from_dirs([cli_config_dir])
CFG.nested_update(kwargs)

warn_if_old_dask_config_exists()
warn_if_old_extra_facets_exist()

@staticmethod
Expand Down Expand Up @@ -577,35 +541,24 @@ def _get_recipe(recipe) -> Path:
@staticmethod
def _get_config_info(cli_config_dir):
"""Get information about config files for logging."""
from .config import CFG
from .config._config_object import (
DEFAULT_CONFIG_DIR,
_get_all_config_dirs,
_get_all_config_sources,
)

# TODO: remove in v2.14.0
if CFG.get("config_file") is not None:
config_info = [
(DEFAULT_CONFIG_DIR, "defaults"),
(CFG["config_file"], "single configuration file [deprecated]"),
]

# New in v2.12.0
else:
config_dirs = []
for path in _get_all_config_dirs(cli_config_dir):
if not path.is_dir():
config_dirs.append(f"{path} [NOT AN EXISTING DIRECTORY]")
else:
config_dirs.append(str(path))
config_info = list(
zip(
config_dirs,
_get_all_config_sources(cli_config_dir),
strict=False,
),
)
config_dirs = []
for path in _get_all_config_dirs(cli_config_dir):
if not path.is_dir():
config_dirs.append(f"{path} [NOT AN EXISTING DIRECTORY]")
else:
config_dirs.append(str(path))
config_info = list(
zip(
config_dirs,
_get_all_config_sources(cli_config_dir),
strict=False,
),
)

return "\n".join(f"{i[0]} ({i[1]})" for i in config_info)

Expand All @@ -623,6 +576,12 @@ def _log_header(self, log_files, cli_config_dir):
"Reading configuration files from:\n%s",
self._get_config_info(cli_config_dir),
)
old_config_file = Path.home() / ".esmvaltool" / "config-user.yml"
if old_config_file.exists():
logger.warning(
"Ignoring old configuration file at %s",
old_config_file,
)
logger.info("Writing program log files to:\n%s", "\n".join(log_files))


Expand Down
Loading