Skip to content

Commit

Permalink
Issue #366 update to parameter/options change in spec
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Feb 7, 2025
1 parent e2e83c0 commit 3aaa270
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ and start a new "In Progress" section above it.

- Add STAC collections conformance class ([#195](https://github.com/Open-EO/openeo-python-driver/issues/195))
- update openeo_driver/specs/openeo-api/1.x submodule to tag `1.2.0` ([#195](https://github.com/Open-EO/openeo-python-driver/issues/195))
- Extract job option defaults from UDPs and remote process descriptions ([#366](https://github.com/Open-EO/openeo-python-driver/issues/366), based on Process Parameter Extension: [Open-EO/openeo-api#471](https://github.com/Open-EO/openeo-api/pull/471))
- Extract job option defaults from UDPs and remote process descriptions ([#366](https://github.com/Open-EO/openeo-python-driver/issues/366), [Process Parameter Extension](https://github.com/Open-EO/openeo-api/tree/draft/extensions/processing-parameters))


## 0.125.0
Expand Down
2 changes: 2 additions & 0 deletions openeo_driver/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ class OpenEoBackendImplementation:
"https://api.openeo.org/1.2.0",
# Support the "remote process definition" extension (originally known as the "remote-udp" extension)
"https://api.openeo.org/extensions/remote-process-definition/0.1.0",
# Processing Parameters extension
"https://api.openeo.org/extensions/processing-parameters/0.1.0",
# STAC API conformance classes
# "https://api.stacspec.org/v1.0.0/core", # TODO #363 can we claim this conformance class already?
"https://api.stacspec.org/v1.0.0/collections",
Expand Down
27 changes: 11 additions & 16 deletions openeo_driver/processgraph.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import dataclasses
import logging
from typing import List, NamedTuple, Optional, Union

import requests
from typing import NamedTuple, List, Optional, Union

from openeo_driver.errors import OpenEOApiException
from openeo_driver.util.http import is_http_url

Expand Down Expand Up @@ -28,7 +31,8 @@ class ProcessGraphFlatDict(dict):
pass


class ProcessDefinition(NamedTuple):
@dataclasses.dataclass(frozen=True)
class ProcessDefinition:
"""
Like `UserDefinedProcessMetadata`, but with different defaults
(e.g. process graph and parameters are required).
Expand All @@ -43,8 +47,8 @@ class ProcessDefinition(NamedTuple):
# Definition what the process returns
returns: Optional[dict] = None

# TODO: official naming of these "processing parameter" related properties is undecided at the moment.
# see https://github.com/Open-EO/openeo-api/pull/471#discussion_r1904253964
# Default processing options as defined by the Processing Parameters Extension
# (conformance class https://api.openeo.org/extensions/processing-parameters/0.1.0)
default_job_options: Optional[dict] = None
default_synchronous_options: Optional[dict] = None

Expand Down Expand Up @@ -111,18 +115,9 @@ def _get_process_definition_from_url(process_id: str, url: str) -> ProcessDefini
message=f"No valid process definition for {process_id!r} found at {url!r}.",
)

# TODO: official property name for these "processing parameters" is undecided at the moment.
# see https://github.com/Open-EO/openeo-api/pull/471#discussion_r1904253964
if "default_job_parameters" in spec:
_log.warning("Extracting experimental 'default_job_parameters' from process definition.")
default_job_options = spec["default_job_parameters"]
else:
default_job_options = None
if "default_synchronous_parameters" in spec:
_log.warning("Extracting experimental 'default_synchronous_parameters' from process definition.")
default_synchronous_options = spec["default_synchronous_parameters"]
else:
default_synchronous_options = None
# Support for fields from Processing Parameters Extension
default_job_options = spec.get("default_job_options", None)
default_synchronous_options = spec.get("default_synchronous_options", None)

return ProcessDefinition(
id=process_id,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_processgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ def test_extract_default_job_options_from_process_graph(requests_mock):
json={
"id": "add3",
"process_graph": {
"add": {"process_id": "add", "arguments": {"x": {"from_parameter": "x", "y": 3}, "result": True}}
"add": {"process_id": "add", "arguments": {"x": {"from_parameter": "x"}, "y": 3}, "result": True}
},
"parameters": [
{"name": "x", "schema": {"type": "number"}},
],
"returns": {"schema": {"type": "number"}},
"default_job_parameters": {
"default_job_options": {
"memory": "2GB",
"cpu": "yellow",
},
"default_synchronous_parameters": {
"default_synchronous_options": {
"cpu": "green",
},
},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ def test_create_job_100_with_job_options_and_defaults_from_remote_process_defini
"returns": {"schema": {"type": "number"}},
}
if default_job_options is not None:
process_definition["default_job_parameters"] = default_job_options
process_definition["default_job_options"] = default_job_options
requests_mock.get("https://share.test/add3.json", json=process_definition)

pg = {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_views_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4707,7 +4707,7 @@ def test_synchronous_processing_job_options_and_defaults_from_remote_process_def
"returns": {"schema": {"type": "number"}},
}
if default_job_options is not None:
process_definition["default_synchronous_parameters"] = default_job_options
process_definition["default_synchronous_options"] = default_job_options
requests_mock.get("https://share.test/add3.json", json=process_definition)

actual_job_options = []
Expand Down

0 comments on commit 3aaa270

Please sign in to comment.