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
9 changes: 7 additions & 2 deletions eodag/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from eodag.api.provider import Provider, ProvidersDict
from eodag.api.search_result import SearchResult
from eodag.config import (
EXT_COLLECTIONS_CONF_URI,
PLUGINS_TOPICS_KEYS,
EODAGSettings,
PluginConfig,
Expand Down Expand Up @@ -554,13 +555,17 @@ def fetch_collections_list(self, provider: Optional[str] = None) -> None:
already_fetched = False

if not already_fetched:
is_conf_customized = (
self.settings.ext_collections_cfg_uri != EXT_COLLECTIONS_CONF_URI
)

# get ext_collections conf
ext_collections_conf = get_ext_collections_conf(
self.settings.ext_collections_cfg_uri
)

if not ext_collections_conf:
# empty ext_collections conf
if not is_conf_customized and not ext_collections_conf:
# empty ext_collections conf and URI untouched by the user
ext_collections_conf = (
self.discover_collections(provider=provider) or {}
)
Expand Down
20 changes: 18 additions & 2 deletions eodag/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
import yaml.parser
from annotated_types import Gt
from jsonpath_ng import JSONPath
from pydantic import BeforeValidator, Field, computed_field, model_validator
from pydantic import (
AliasChoices,
BeforeValidator,
Field,
computed_field,
model_validator,
)
from pydantic_settings import BaseSettings, SettingsConfigDict
from typing_extensions import TypedDict

Expand Down Expand Up @@ -133,7 +139,10 @@ class EODAGSettings(BaseSettings):

ext_collections_cfg_uri: str = Field(
default=EXT_COLLECTIONS_CONF_URI,
validation_alias="EODAG_EXT_COLLECTIONS_CFG_FILE",
validation_alias=AliasChoices(
"EODAG_EXT_COLLECTIONS_CFG_URI",
"EODAG_EXT_COLLECTIONS_CFG_FILE",
),
description=(
"URI of the external collections configuration. "
"Supports HTTP(S), ``file://`` URIs and local filesystem paths."
Expand Down Expand Up @@ -186,6 +195,13 @@ def warn_deprecated_settings(self) -> Self:
DeprecationWarning,
stacklevel=5,
)
if "EODAG_EXT_COLLECTIONS_CFG_FILE" in os.environ:
warnings.warn(
"EODAG_EXT_COLLECTIONS_CFG_FILE is deprecated. "
"Use EODAG_EXT_COLLECTIONS_CFG_URI instead.",
DeprecationWarning,
stacklevel=5,
)
return self


Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ addopts = "--doctest-modules --disable-socket --allow-unix-socket"
log_cli = false
filterwarnings = [
"""ignore:
.*(Call to deprecated eodag|locations_conf_path|user_conf_file_path|EODAG_PROVIDERS_CFG_FILE).*:
.*(Call to deprecated eodag|locations_conf_path|user_conf_file_path|EODAG_PROVIDERS_CFG_FILE|\
EODAG_EXT_COLLECTIONS_CFG_FILE).*:
DeprecationWarning""",
]
22 changes: 22 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,28 @@ def test_load_default_config(self):
# priority is set to 0 for all providers
self.assertEqual(value.priority, 0)

def test_ext_collections_config_uri_environment_variables(self):
"""Both current and deprecated environment variable names are supported."""
try:
os.environ["EODAG_EXT_COLLECTIONS_CFG_URI"] = "new-uri"
self.assertEqual(config.EODAGSettings().ext_collections_cfg_uri, "new-uri")

os.environ.pop("EODAG_EXT_COLLECTIONS_CFG_URI")
os.environ["EODAG_EXT_COLLECTIONS_CFG_FILE"] = "deprecated-uri"
with self.assertWarnsRegex(
DeprecationWarning,
"EODAG_EXT_COLLECTIONS_CFG_FILE is deprecated",
):
self.assertEqual(
config.EODAGSettings().ext_collections_cfg_uri, "deprecated-uri"
)

os.environ["EODAG_EXT_COLLECTIONS_CFG_URI"] = "new-uri"
self.assertEqual(config.EODAGSettings().ext_collections_cfg_uri, "new-uri")
finally:
os.environ.pop("EODAG_EXT_COLLECTIONS_CFG_URI", None)
os.environ.pop("EODAG_EXT_COLLECTIONS_CFG_FILE", None)

def test_load_provider_configs_file_precedence(self):
"""load_provider_configs must prioritize providers_cfg_file over providers_cfg_dir."""
providers_cfg_file_override = (
Expand Down
7 changes: 3 additions & 4 deletions tests/units/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,11 +1558,11 @@ def test_fetch_collections_list_updated_system_conf(

mock_get_ext_collections_conf.return_value = {}

# an empty configured URI still falls back to discovery
# disabled collections discovery
self.dag.settings.ext_collections_cfg_uri = ""
self.dag.fetch_collections_list()
mock_get_ext_collections_conf.assert_called_with("")
mock_discover_collections.assert_called_once_with(self.dag, provider=None)
mock_discover_collections.assert_not_called()

mock_discover_collections.reset_mock()

Expand All @@ -1589,7 +1589,7 @@ def test_fetch_collections_list_disabled(self, mock_discover_collections):

# default settings still fall back to discover_collections
self.dag.fetch_collections_list()
mock_discover_collections.assert_called_once_with(self.dag, provider=None)
mock_discover_collections.assert_not_called()

mock_discover_collections.reset_mock()

Expand All @@ -1611,7 +1611,6 @@ def test_fetch_collections_list_disabled(self, mock_discover_collections):
self.assertEqual(
mock_discover_collections.call_args_list,
[
mock.call(self.dag, provider=None),
mock.call(self.dag, provider="earth_search"),
mock.call(self.dag, provider="foo_provider"),
],
Expand Down
Loading