eodag 4.0.0a3__py3-none-any.whl → 4.0.0a4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
eodag/plugins/manager.py CHANGED
@@ -24,12 +24,8 @@ from typing import TYPE_CHECKING, Any, Iterator, Optional, Union, cast
24
24
 
25
25
  import importlib_metadata
26
26
 
27
- from eodag.config import (
28
- AUTH_TOPIC_KEYS,
29
- PLUGINS_TOPICS_KEYS,
30
- load_config,
31
- merge_configs,
32
- )
27
+ from eodag.api.provider import ProvidersDict
28
+ from eodag.config import AUTH_TOPIC_KEYS, PLUGINS_TOPICS_KEYS, load_config
33
29
  from eodag.plugins.apis.base import Api
34
30
  from eodag.plugins.authentication.base import Authentication
35
31
  from eodag.plugins.base import EODAGPluginMount
@@ -48,7 +44,8 @@ if TYPE_CHECKING:
48
44
  from requests.auth import AuthBase
49
45
 
50
46
  from eodag.api.product import EOProduct
51
- from eodag.config import PluginConfig, ProviderConfig
47
+ from eodag.api.provider import ProviderConfig
48
+ from eodag.config import PluginConfig
52
49
  from eodag.plugins.base import PluginTopic
53
50
 
54
51
 
@@ -67,8 +64,8 @@ class PluginManager:
67
64
  it, and the plugins to use to perform defined actions (search, download,
68
65
  authenticate, crunch).
69
66
 
70
- :param providers_config: The configuration with all information about the providers
71
- supported by ``eodag``
67
+ :param providers: The ProvidersDict instance with all information about the providers
68
+ supported by ``eodag``
72
69
  """
73
70
 
74
71
  supported_topics = set(PLUGINS_TOPICS_KEYS)
@@ -77,9 +74,9 @@ class PluginManager:
77
74
 
78
75
  skipped_plugins: list[str]
79
76
 
80
- def __init__(self, providers_config: dict[str, ProviderConfig]) -> None:
77
+ def __init__(self, providers: ProvidersDict) -> None:
81
78
  self.skipped_plugins = []
82
- self.providers_config = providers_config
79
+ self.providers = providers
83
80
  # Load all the plugins. This will make all plugin classes of a particular
84
81
  # type to be available in the base plugin class's 'plugins' attribute.
85
82
  # For example, by importing module 'eodag.plugins.search.resto', the plugin
@@ -119,19 +116,14 @@ class PluginManager:
119
116
  str(x) for x in dist.locate_file(name).rglob("providers.yml")
120
117
  ]
121
118
  if plugin_providers_config_path:
122
- plugin_providers_config = load_config(
123
- plugin_providers_config_path[0]
124
- )
125
- merge_configs(plugin_providers_config, self.providers_config)
126
- self.providers_config = plugin_providers_config
119
+ plugin_configs = load_config(plugin_providers_config_path[0])
120
+ self.providers.update_from_configs(plugin_configs)
127
121
  self.rebuild()
128
122
 
129
- def rebuild(
130
- self, providers_config: Optional[dict[str, ProviderConfig]] = None
131
- ) -> None:
123
+ def rebuild(self, providers: Optional[ProvidersDict] = None) -> None:
132
124
  """(Re)Build plugin manager mapping and cache"""
133
- if providers_config is not None:
134
- self.providers_config = providers_config
125
+ if providers is not None:
126
+ self.providers = providers
135
127
 
136
128
  self.build_collection_to_provider_config_map()
137
129
  self._built_plugins_cache: dict[tuple[str, str, str], Any] = {}
@@ -139,27 +131,22 @@ class PluginManager:
139
131
  def build_collection_to_provider_config_map(self) -> None:
140
132
  """Build mapping conf between collections and providers"""
141
133
  self.collection_to_provider_config_map = {}
142
- for provider in list(self.providers_config):
143
- provider_config = self.providers_config[provider]
144
- if not hasattr(provider_config, "products") or not provider_config.products:
134
+ for provider in list(self.providers.values()):
135
+ if not provider.collections_config:
145
136
  logger.info(
146
137
  "%s: provider has no product configured and will be skipped",
147
138
  provider,
148
139
  )
149
- self.providers_config.pop(provider)
140
+ del self.providers[provider.name]
150
141
  continue
151
142
 
152
- # provider priority set to lowest if not set
153
- if getattr(provider_config, "priority", None) is None:
154
- self.providers_config[provider].priority = provider_config.priority = 0
155
-
156
- for collection in provider_config.products:
143
+ for collection in provider.collections_config:
157
144
  collection_providers = (
158
145
  self.collection_to_provider_config_map.setdefault( # noqa
159
146
  collection, []
160
147
  )
161
148
  )
162
- collection_providers.append(provider_config)
149
+ collection_providers.append(provider.config)
163
150
  collection_providers.sort(key=attrgetter("priority"), reverse=True)
164
151
 
165
152
  def get_search_plugins(
@@ -203,7 +190,7 @@ class PluginManager:
203
190
  )
204
191
  configs = self.collection_to_provider_config_map[GENERIC_COLLECTION]
205
192
  else:
206
- configs = list(self.providers_config.values())
193
+ configs = list(p.config for p in self.providers.values())
207
194
 
208
195
  if provider:
209
196
  configs = [
@@ -227,7 +214,10 @@ class PluginManager:
227
214
  :param product: The product to get a download plugin for
228
215
  :returns: The download plugin capable of downloading the product
229
216
  """
230
- plugin_conf = self.providers_config[product.provider]
217
+ plugin_conf = self.providers.get_config(product.provider)
218
+ if plugin_conf is None:
219
+ msg = f"Provider {product.provider} not found"
220
+ raise UnsupportedProvider(msg)
231
221
  if download := getattr(plugin_conf, "download", None):
232
222
  plugin_conf.download.priority = plugin_conf.priority
233
223
  plugin = cast(
@@ -322,7 +312,7 @@ class PluginManager:
322
312
  return False
323
313
 
324
314
  # providers configs with given provider at first
325
- sorted_providers_config = deepcopy(self.providers_config)
315
+ sorted_providers_config = deepcopy(self.providers.configs)
326
316
  sorted_providers_config = {
327
317
  provider: sorted_providers_config.pop(provider),
328
318
  **sorted_providers_config,