From ca9dd25ba67ef562ca9de9d971e4a68004437072 Mon Sep 17 00:00:00 2001 From: Paul Haesler Date: Wed, 1 Nov 2023 14:52:54 +1100 Subject: [PATCH] Old-style "user" section raises a warning. --- datacube/cfg/api.py | 11 ++++++++++- tests/test_cfg.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/datacube/cfg/api.py b/datacube/cfg/api.py index 23e6ee907..231548669 100644 --- a/datacube/cfg/api.py +++ b/datacube/cfg/api.py @@ -95,7 +95,12 @@ def __init__( self.allow_envvar_overrides = text is None and raw_dict is None if raw_dict is None and text is None: - text = find_config(paths) + # No explict config passed in. Check for ODC_CONFIG environmnet variables + if os.environ.get("ODC_CONFIG"): + text = os.environ["ODC_CONFIG"] + else: + # Read config text from config file + text = find_config(paths) self.raw_text = text self.raw_config = raw_dict @@ -209,6 +214,10 @@ def __init__(self, self._allow_envvar_overrides: bool = allow_env_overrides self._normalised: dict[str, Any] = {} + if name == "user" and "default_environment" in raw: + warnings.warn("The 'default_environment' setting in the 'user' section is no longer supported - " + "please refer to the documentation for more information") + # Aliases are handled here, the alias OptionHandler is a place-holder. if "alias" in self._raw: alias = self._raw['alias'] diff --git a/tests/test_cfg.py b/tests/test_cfg.py index 21729114f..1ac0e2165 100644 --- a/tests/test_cfg.py +++ b/tests/test_cfg.py @@ -186,6 +186,23 @@ def test_invalid_env(): """) +def test_oldstyle_cfg(): + from datacube.cfg.api import ODCConfig, ConfigException + with pytest.warns(UserWarning, match=r'default_environment.*no longer supported'): + cfg = ODCConfig(text=""" +default: + index_driver: memory +env2: + index_driver: memory +env3: + index_driver: memory +user: + default_environment: env3 +""" + ) + assert cfg[None]._name == 'default' + + def test_invalid_option(): from datacube.cfg.opt import ODCOptionHandler, ConfigException mockenv = MagicMock()