Skip to content

Commit bb4494e

Browse files
authored
Merge pull request #32 from cedadev/conditional_method
Conditional method
2 parents 27beb74 + 2f4fe79 commit bb4494e

File tree

11 files changed

+233
-184
lines changed

11 files changed

+233
-184
lines changed

docs/_build/doctrees/core.doctree

-135 KB
Binary file not shown.
162 KB
Binary file not shown.
-2.83 KB
Binary file not shown.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
project = "Extraction Methods"
1414
copyright = "2025, Rhys Evans"
1515
author = "Rhys Evans"
16-
release = "1.1.1"
16+
release = "1.1.2"
1717

1818
# -- General configuration ---------------------------------------------------
1919
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extraction_methods/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# encoding: utf-8
2-
"""
3-
4-
"""
2+
""" """
53
# encoding: utf-8
64
"""
75
.. _facet-prefix:

extraction_methods/core/extraction_method.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@
2626
extraction_method_defaults = {}
2727

2828

29+
class ExtractionMethodConf(BaseModel):
30+
"""STAC extraction method model."""
31+
32+
method: str
33+
inputs: Optional[dict[str, Any]] = {}
34+
35+
_extraction_methods: EntryPoints = entry_points(group="extraction_methods")
36+
37+
def __repr__(self) -> str:
38+
return yaml.dump(self.model_dump())
39+
40+
def _run(self, body: dict[str, Any]) -> dict[str, Any]:
41+
extraction_method = self._extraction_methods[self.method].load()
42+
extraction_method = extraction_method(self)
43+
44+
return extraction_method._run(body) # type: ignore[no-any-return]
45+
46+
2947
def update_input(
3048
func: Callable[[Any, dict[str, Any]], Any],
3149
) -> Callable[[Any, dict[str, Any]], Any]:
@@ -46,7 +64,7 @@ def wrapper(self, body: dict[str, Any]) -> Any: # type: ignore[no-untyped-def]
4664
return wrapper
4765

4866

49-
def set_extraction_method_defaults(conf_defaults: dict):
67+
def set_extraction_method_defaults(conf_defaults: dict[str, Any]) -> None:
5068
"""
5169
Function to set global extraction_method_defaults variable.
5270
"""
@@ -62,7 +80,9 @@ class SetInput:
6280
input_class: Any = Input
6381
dummy_input_class: Any = DummyInput
6482

65-
def __init__(self, extraction_method_conf: dict, *args: Any, **kwargs: Any) -> None:
83+
def __init__(
84+
self, extraction_method_conf: ExtractionMethodConf, *args: Any, **kwargs: Any
85+
) -> None:
6686
"""
6787
Set ``input`` attribute to instance of ``dummy_input_class`` with
6888
default values overrided by kwargs.
@@ -180,21 +200,3 @@ def run(self, body: dict[str, Any]) -> Iterator[dict[str, Any]]:
180200
:return: updated body dict
181201
:rtype: dict
182202
"""
183-
184-
185-
class ExtractionMethodConf(BaseModel):
186-
"""STAC extraction method model."""
187-
188-
method: str
189-
inputs: Optional[dict] = {}
190-
191-
_extraction_methods: EntryPoints = entry_points(group="extraction_methods")
192-
193-
def __repr__(self):
194-
return yaml.dump(self.model_dump())
195-
196-
def _run(self, body: dict[str, Any]) -> dict[str, Any]:
197-
extraction_method = self._extraction_methods[self.method].load()
198-
extraction_method = extraction_method(self)
199-
200-
return extraction_method._run(body)

extraction_methods/plugins/assets/backends/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# encoding: utf-8
2-
"""
3-
4-
"""
2+
""" """
53
__author__ = "Richard Smith"
64
__date__ = "03 Jun 2021"
75
__copyright__ = "Copyright 2018 United Kingdom Research and Innovation"

extraction_methods/plugins/conditional.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def run(self, body: dict[str, Any]) -> dict[str, Any]:
8686
for term in self.input.condition.split(" "):
8787

8888
if term[0] == self.input.exists_key:
89-
term = body.get(term[1:], term)
89+
term = body.get(term[1:], None)
9090

9191
if isinstance(term, str):
9292
term = f"'{term}'"

extraction_methods/plugins/header/backends/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# encoding: utf-8
2-
"""
3-
4-
"""
2+
""" """
53
__author__ = "Richard Smith"
64
__date__ = "03 Jun 2021"
75
__copyright__ = "Copyright 2018 United Kingdom Research and Innovation"

poetry.lock

Lines changed: 196 additions & 145 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)