Skip to content

Commit 2e6ac19

Browse files
authored
feat(conf): split providers.yml file (#2228)
1 parent d567547 commit 2e6ac19

49 files changed

Lines changed: 7815 additions & 7757 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/_static/collections_information.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ EUSTAT_SOIL_SEALING_INDEX,Eurostat,,,,,,,,,,,,available,,,,,,,,,,,,,,,,,,,,,
9393
EUSTAT_SURFACE_TERRESTRIAL_PROTECTED_AREAS,Eurostat,,,,,,,,,,,,available,,,,,,,,,,,,,,,,,,,,,
9494
FIRE_HISTORICAL,CEMS,,,,,,,available,,,,,available,,,,,,,,,,,,,,,,,,,,available,
9595
FIRE_SEASONAL,CEMS,,,,,,,available,,,,,,,,,,,,,,,,,,,,,,,,,,
96-
GENERIC_PRODUCT_TYPE,,,,,,,,,,,,,,,,available,,,,,,,,,,,,,,,,,,
9796
GHS_BUILT_C,Sentinel-2,,,,,,,,available,,,,,,,,,,,,,,,,,,,,,,,,,
9897
GHS_BUILT_H,Sentinel-2,,,,,,,,available,,,,,,,,,,,,,,,,,,,,,,,,,
9998
GHS_BUILT_LAUSTAT,,,,,,,,,available,,,,,,,,,,,,,,,,,,,,,,,,,
@@ -253,7 +252,7 @@ S1_SAR_SLC,SENTINEL1,L1,,,,available,available,,,,available,available,available,
253252
S2_MSI_L1C,SENTINEL2,L1,available,,,available,available,,,,available,available,available,,,,available,available,,,,,available,available,,,,available,,available,,,,available
254253
S2_MSI_L2A,SENTINEL2,L2,available,,,available,available,,,,available,available,available,,,,,,,,,,,,,,available,available,,,,,,available
255254
S2_MSI_L2A_COG,SENTINEL2,L2,,,,,,,,,,,,,,,available,,,,,,,,,,,,,,,,,
256-
S2_MSI_L2A_MAJA,SENTINEL2,L2,,,,,,,,,,,,,,,,,,,,,available,available,,,,,,,,,,
255+
S2_MSI_L2A_MAJA,SENTINEL2,L2,,,,,,,,,,,,,,available,,,,,,,available,available,,,,,,,,,,
257256
S2_MSI_L2B_MAJA_SNOW,SENTINEL2,L2,,,,,,,,,,,,,,,,,,,,,available,available,,,,,,,,,,
258257
S2_MSI_L2B_MAJA_WATER,SENTINEL2,L2,,,,,,,,,,,,,,,,,,,,,available,available,,,,,,,,,,
259258
S3_EFR,SENTINEL3,L1,,,,available,available,,,,available,available,available,,,,,,,,available,,,,,,,available,,,,,,available
@@ -345,5 +344,6 @@ SPACENET_BUILDINGS_DETECTION_V2,SpaceNet,,,,,,,,,,,,available,,,,,,,,,,,,,,,,,,,
345344
SPACENET_OFF_NADIR_BUILDING,SpaceNet,,,,,,,,,,,,available,,,,,,,,,,,,,,,,,,,,,
346345
SPACENET_ROADS_NETWORK_DETECTION,SpaceNet,,,,,,,,,,,,available,,,,,,,,,,,,,,,,,,,,,
347346
SPACENET_ROADS_NETWORK_ROUTE_TRAVEL,SpaceNet,,,,,,,,,,,,available,,,,,,,,,,,,,,,,,,,,,
347+
SUPERSITES,,,,,,,,,,,,,,,,available,,,,,,,,,,,,,,,,,,
348348
TIGGE_CF_SFC,TIGGE,,,,,,,,,,,,,,,,,,available,,,,,,,,,,,,,,,
349349
UERRA_EUROPE_SL,SURFEX,,,,available,,,,,,,,available,,,,,,,,,,,,,,,,,,,,available,

docs/add_collection.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ as ``instruments``, ``processing:level``, ``constellation``, etc.
4242
Add collection to a provider
4343
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4444

45-
In the file ``eodag/resources/providers.yml``, add the collection to the ``products``
46-
entry of a provider:
45+
In the directory ``eodag/resources/providers/``, you will find a YAML file for each provider supported by EODAG.
46+
To make EODAG aware of the new collection, you need to add the collection to the ``products`` entry of a provider:
4747

4848
.. code-block:: yaml
4949

docs/add_provider.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,18 @@ See more details about how to create a new plugin in :ref:`this dedicated sectio
7272
Providers pre-configuration
7373
^^^^^^^^^^^^^^^^^^^^^^^^^^^
7474

75-
All the providers are pre-configured in ``eodag`` in a YAML file.
75+
All the providers are pre-configured in ``eodag`` in YAML files located in the ``eodag/resources/providers/`` directory.
76+
Each file corresponds to a provider and contains the configuration of the plugins used to access this provider.
77+
78+
For example, the file ``aws_eos.yml`` contains the configuration of the provider and associated plugins.
7679
Click on the link below to display its full content.
7780

7881
.. raw:: html
7982

8083
<details>
81-
<summary><a>providers.yml</a></summary>
84+
<summary><a>aws_eos.yml</a></summary>
8285

83-
.. include:: ../eodag/resources/providers.yml
86+
.. include:: ../eodag/resources/providers/aws_eos.yml
8487
:start-line: 17
8588
:code: yaml
8689

docs/getting_started_guide/configure.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ Some EODAG core settings can be overriden using environment variables:
148148
* ``EODAG_LOCS_CFG_FILE`` for defining the desired path to the
149149
`locations <../notebooks/api_user_guide/3_search.ipynb#Locations-search>`_
150150
configuration file in place of `~/.config/eodag/locations.yml`.
151-
* ``EODAG_PROVIDERS_CFG_FILE`` for defining the desired path to the providers configuration file in place of
151+
* ``EODAG_PROVIDERS_CFG_FILE`` **(deprecated)** for defining the desired path to the providers configuration file in place of
152152
`<python-site-packages>/eodag/resources/providers.yml`.
153+
* ``EODAG_PROVIDERS_CFG_DIR`` for defining the desired path to the directory containing providers configuration files in place of
154+
`<python-site-packages>/eodag/resources/providers/`.
153155
* ``EODAG_COLLECTIONS_CFG_FILE`` for defining the desired path to the collections configuration file in place of
154156
`<python-site-packages>/eodag/resources/collections.yml`.
155157
* ``EODAG_EXT_COLLECTIONS_CFG_FILE`` for defining the desired path to the `external collections configuration file\

docs/params_mapping.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ EODAG maps each provider's specific metadata parameters to a common model using
1313
`OGC OpenSearch Extension for Earth Observation <http://docs.opengeospatial.org/is/13-026r9/13-026r9.html>`_.
1414
Extra parameters having no equivalent in this model are mapped as is.
1515

16-
Depending on the provider, some parameters are queryable or not. This is configured in `providers.yml`:
16+
Depending on the provider, some parameters are queryable or not. This is configured in each configuration file located in the ``eodag/resources/providers/`` directory.
1717

1818
* If a parameter metadata-mapping is a list, the first element will help constructing the query \
1919
(using `format() <https://docs.python.org/fr/3/library/string.html#string.Formatter.format>`_), and the 2nd will \

eodag/config.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import logging
2121
import os
22+
import pathlib
23+
import warnings
2224
from importlib.resources import files as res_files
2325
from typing import TYPE_CHECKING, Annotated, Any, Literal, Optional, Union
2426

@@ -682,16 +684,35 @@ def credentials_in_auth(auth_conf: PluginConfig) -> bool:
682684
def load_default_config() -> dict[str, ProviderConfig]:
683685
"""Load the providers configuration into a dictionary.
684686
685-
Load from eodag `resources/providers.yml` or `EODAG_PROVIDERS_CFG_FILE` environment
687+
Load from eodag `resources/providers` files or `EODAG_PROVIDERS_CFG_DIR` environment
686688
variable if exists.
687689
690+
For backwards compatibility, if `EODAG_PROVIDERS_CFG_FILE` environment variable is set, load from it instead of
691+
`EODAG_PROVIDERS_CFG_DIR`.
692+
688693
:returns: The default provider's configuration
689694
"""
690-
eodag_providers_cfg_file = os.getenv("EODAG_PROVIDERS_CFG_FILE") or str(
691-
res_files("eodag") / "resources" / "providers.yml"
692-
)
695+
eodag_providers_cfg_file = os.getenv("EODAG_PROVIDERS_CFG_FILE")
696+
eodag_providers_cfg_dir = os.getenv("EODAG_PROVIDERS_CFG_DIR")
697+
698+
if eodag_providers_cfg_file:
699+
warnings.warn(
700+
"Usage of deprecated environment variable EODAG_PROVIDERS_CFG_FILE. "
701+
"(Please use EODAG_PROVIDERS_CFG_DIR instead)"
702+
" -- Deprecated since v4.5.0",
703+
DeprecationWarning,
704+
stacklevel=3,
705+
)
706+
return load_config(eodag_providers_cfg_file)
693707

694-
return load_config(eodag_providers_cfg_file)
708+
config_dir = eodag_providers_cfg_dir or str(
709+
res_files("eodag") / "resources" / "providers"
710+
)
711+
providers: dict[str, ProviderConfig] = {}
712+
for f in pathlib.Path(config_dir).glob("*.yml"):
713+
if f.is_file():
714+
providers.update(load_config(str(f)))
715+
return dict(sorted(providers.items()))
695716

696717

697718
def load_config(config_path: str) -> dict[str, ProviderConfig]:

eodag/plugins/manager.py

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from __future__ import annotations
1919

2020
import logging
21+
import pathlib
2122
import re
2223
from operator import attrgetter
2324
from typing import TYPE_CHECKING, Any, Iterator, Optional, Union, cast
@@ -108,18 +109,58 @@ def __init__(self, providers: ProvidersDict) -> None:
108109
"Check that the plugin module (%s) is importable",
109110
entry_point.name,
110111
)
111-
if entry_point.dist and entry_point.dist.name != "eodag":
112-
# use plugin providers if any
113-
name = entry_point.dist.name
114-
dist = entry_point.dist
115-
plugin_providers_config_path = [
116-
str(x) for x in dist.locate_file(name).rglob("providers.yml")
117-
]
118-
if plugin_providers_config_path:
119-
plugin_configs = load_config(plugin_providers_config_path[0])
120-
self.providers.update_from_configs(plugin_configs)
112+
plugin_config_paths = self._get_external_provider_config_paths(
113+
entry_point
114+
)
115+
if plugin_config_paths:
116+
plugin_configs: dict[str, ProviderConfig] = {}
117+
for path in plugin_config_paths:
118+
plugin_configs.update(load_config(path.as_posix()))
119+
self.providers.update_from_configs(plugin_configs)
121120
self.rebuild()
122121

122+
def _get_external_provider_config_paths(
123+
self,
124+
entry_point: importlib_metadata.EntryPoint,
125+
) -> list[pathlib.Path]:
126+
"""Return provider config paths exposed by an external plugin distribution."""
127+
config_paths: list[pathlib.Path] = []
128+
dist = entry_point.dist
129+
dist_name = getattr(dist, "name", None)
130+
131+
if not dist or not isinstance(dist_name, str) or dist_name == "eodag":
132+
return config_paths
133+
134+
providers_dir = pathlib.Path(
135+
str(dist.locate_file(pathlib.Path("eodag/providers")))
136+
)
137+
if providers_dir.exists() and providers_dir.is_dir():
138+
config_paths.extend(
139+
path for path in providers_dir.iterdir() if path.is_file()
140+
)
141+
142+
module_name = getattr(entry_point, "module", None)
143+
if isinstance(module_name, str) and module_name:
144+
module_path = pathlib.Path(module_name.replace(".", "/"))
145+
146+
# Check providers/ subdirectory within the module
147+
module_providers_dir = pathlib.Path(
148+
str(dist.locate_file(module_path / "providers"))
149+
)
150+
if module_providers_dir.exists() and module_providers_dir.is_dir():
151+
config_paths.extend(
152+
path for path in module_providers_dir.iterdir() if path.is_file()
153+
)
154+
155+
# Legacy: single providers.yml file at the module root
156+
providers_yml = pathlib.Path(
157+
str(dist.locate_file(module_path / "providers.yml"))
158+
)
159+
if providers_yml.exists() and providers_yml.is_file():
160+
config_paths.append(providers_yml)
161+
162+
return config_paths
163+
123164
def rebuild(self, providers: Optional[ProvidersDict] = None) -> None:
124165
"""(Re)Build plugin manager mapping and cache"""
125166
if providers is not None:

0 commit comments

Comments
 (0)