Skip to content

Commit

Permalink
Add env to SupportsRunUdf
Browse files Browse the repository at this point in the history
related to #197
  • Loading branch information
soxofaan committed Jun 6, 2023
1 parent fdf43b0 commit 98a0d39
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion openeo_driver/ProcessGraphDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ def run_udf(args: dict, env: EvalEnv):

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

# TODO #114 add support for DriverVectorCube
if isinstance(data, AggregatePolygonResult):
Expand Down
2 changes: 1 addition & 1 deletion openeo_driver/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.52.0a1"
__version__ = "0.53.0a1"
36 changes: 19 additions & 17 deletions openeo_driver/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@
log = logging.getLogger(__name__)


class SupportsRunUdf(metaclass=abc.ABCMeta):
"""
Interface/Mixin for cube/result classes that (partially) support `run_udf`
"""

# TODO: as there is quite some duplication between the current methods of this API:
# simplify it by just providing a single method: e.g. `get_udf_runner`,
# which returns None if run_udf is not supported, and returns a callable (to run the udf on the data) when it is supported.

@abc.abstractmethod
def supports_udf(self, udf: str, *, runtime: str = "Python") -> bool:
"""Check if UDF code is supported."""
return False

@abc.abstractmethod
def run_udf(self, udf: str, *, runtime: str = "Python", context: Optional[dict] = None, env: EvalEnv):
...


class DriverDataCube:
"""Base class for "driver" side raster data cubes."""

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

def write_assets(self, directory: Union[str, Path]) -> Dict[str, StacAsset]:
raise NotImplementedError


class SupportsRunUdf(metaclass=abc.ABCMeta):
"""
Interface for cube/result classes that (partially) support `run_udf`
"""

@abc.abstractmethod
def supports_udf(self, udf: str, runtime: str = "Python") -> bool:
"""Check if UDF code is supported."""
return False

@abc.abstractmethod
def run_udf(
self, udf: str, runtime: str = "Python", context: Optional[dict] = None
):
...

0 comments on commit 98a0d39

Please sign in to comment.