Skip to content

Commit 98a0d39

Browse files
committed
Add env to SupportsRunUdf
related to #197
1 parent fdf43b0 commit 98a0d39

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

openeo_driver/ProcessGraphDeserializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ def run_udf(args: dict, env: EvalEnv):
13561356

13571357
if isinstance(data, SupportsRunUdf) and data.supports_udf(udf=udf, runtime=runtime):
13581358
_log.info(f"run_udf: data of type {type(data)} has direct run_udf support")
1359-
return data.run_udf(udf=udf, runtime=runtime, context=context)
1359+
return data.run_udf(udf=udf, runtime=runtime, context=context, env=env)
13601360

13611361
# TODO #114 add support for DriverVectorCube
13621362
if isinstance(data, AggregatePolygonResult):

openeo_driver/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.52.0a1"
1+
__version__ = "0.53.0a1"

openeo_driver/datacube.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@
2828
log = logging.getLogger(__name__)
2929

3030

31+
class SupportsRunUdf(metaclass=abc.ABCMeta):
32+
"""
33+
Interface/Mixin for cube/result classes that (partially) support `run_udf`
34+
"""
35+
36+
# TODO: as there is quite some duplication between the current methods of this API:
37+
# simplify it by just providing a single method: e.g. `get_udf_runner`,
38+
# which returns None if run_udf is not supported, and returns a callable (to run the udf on the data) when it is supported.
39+
40+
@abc.abstractmethod
41+
def supports_udf(self, udf: str, *, runtime: str = "Python") -> bool:
42+
"""Check if UDF code is supported."""
43+
return False
44+
45+
@abc.abstractmethod
46+
def run_udf(self, udf: str, *, runtime: str = "Python", context: Optional[dict] = None, env: EvalEnv):
47+
...
48+
49+
3150
class DriverDataCube:
3251
"""Base class for "driver" side raster data cubes."""
3352

@@ -491,20 +510,3 @@ def get_model_metadata(self, directory: Union[str, Path]) -> Dict[str, Any]:
491510

492511
def write_assets(self, directory: Union[str, Path]) -> Dict[str, StacAsset]:
493512
raise NotImplementedError
494-
495-
496-
class SupportsRunUdf(metaclass=abc.ABCMeta):
497-
"""
498-
Interface for cube/result classes that (partially) support `run_udf`
499-
"""
500-
501-
@abc.abstractmethod
502-
def supports_udf(self, udf: str, runtime: str = "Python") -> bool:
503-
"""Check if UDF code is supported."""
504-
return False
505-
506-
@abc.abstractmethod
507-
def run_udf(
508-
self, udf: str, runtime: str = "Python", context: Optional[dict] = None
509-
):
510-
...

0 commit comments

Comments
 (0)