Skip to content

Commit

Permalink
Old-style "user" section raises a warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacemanPaul committed Nov 1, 2023
1 parent dd5be50 commit ca9dd25
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
11 changes: 10 additions & 1 deletion datacube/cfg/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down
17 changes: 17 additions & 0 deletions tests/test_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ca9dd25

Please sign in to comment.