Skip to content

Commit df3c233

Browse files
authored
refactor(ecmwf): simplify ECMWFSearch configuration (#1433)
1 parent 3a9ac6e commit df3c233

File tree

15 files changed

+979
-1087
lines changed

15 files changed

+979
-1087
lines changed

eodag/api/product/metadata_mapping.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ def convert_to_nwse_bounds_str(
367367
)
368368

369369
@staticmethod
370-
def convert_to_geojson(string: str) -> str:
371-
return geojson.dumps(string)
370+
def convert_to_geojson(value: Any) -> str:
371+
return geojson.dumps(value)
372372

373373
@staticmethod
374374
def convert_from_ewkt(ewkt_string: str) -> Union[BaseGeometry, str]:
@@ -496,9 +496,16 @@ def convert_get_group_name(string: str, pattern: str) -> str:
496496
return NOT_AVAILABLE
497497

498498
@staticmethod
499-
def convert_replace_str(string: str, args: str) -> str:
499+
def convert_replace_str(value: Any, args: str) -> str:
500+
if isinstance(value, dict):
501+
value = MetadataFormatter.convert_to_geojson(value)
502+
elif not isinstance(value, str):
503+
raise TypeError(
504+
f"convert_replace_str expects a string or a dict (apply to_geojson). Got {type(value)}"
505+
)
506+
500507
old, new = ast.literal_eval(args)
501-
return re.sub(old, new, string)
508+
return re.sub(old, new, value)
502509

503510
@staticmethod
504511
def convert_recursive_sub_str(

eodag/plugins/apis/ecmwf.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@
3030
from eodag.plugins.apis.base import Api
3131
from eodag.plugins.search import PreparedSearch
3232
from eodag.plugins.search.base import Search
33-
from eodag.plugins.search.build_search_result import (
34-
ECMWF_KEYWORDS,
35-
ECMWFSearch,
36-
keywords_to_mdt,
37-
)
33+
from eodag.plugins.search.build_search_result import ECMWFSearch, ecmwf_mtd
3834
from eodag.utils import (
3935
DEFAULT_DOWNLOAD_TIMEOUT,
4036
DEFAULT_DOWNLOAD_WAIT,
@@ -94,7 +90,7 @@ class EcmwfApi(Api, ECMWFSearch):
9490
def __init__(self, provider: str, config: PluginConfig) -> None:
9591
# init self.config.metadata_mapping using Search Base plugin
9692
config.metadata_mapping = {
97-
**keywords_to_mdt(ECMWF_KEYWORDS, "ecmwf"),
93+
**ecmwf_mtd(),
9894
**config.metadata_mapping,
9995
}
10096
Search.__init__(self, provider, config)

eodag/plugins/search/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def map_product_type(
150150
)
151151

152152
def get_product_type_def_params(
153-
self, product_type: str, **kwargs: Any
153+
self, product_type: str, format_variables: Optional[dict[str, Any]] = None
154154
) -> dict[str, Any]:
155155
"""Get the provider product type definition parameters and specific settings
156156
@@ -171,7 +171,8 @@ def get_product_type_def_params(
171171
return {
172172
k: v
173173
for k, v in format_dict_items(
174-
self.config.products[GENERIC_PRODUCT_TYPE], **kwargs
174+
self.config.products[GENERIC_PRODUCT_TYPE],
175+
**(format_variables or {}),
175176
).items()
176177
if v
177178
}

0 commit comments

Comments
 (0)