Skip to content

Commit f6235e1

Browse files
soxofaanPeter Van Bouwel
authored andcommitted
Issue Open-EO#352 add process (target) version to /processes
1 parent 31b161e commit f6235e1

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and start a new "In Progress" section above it.
2222
## In progress
2323

2424
- Add time resolution to date prefix of `generate_unique_id()`
25+
- Add target version of openEO processes to `GET /processes` ([#352](https://github.com/Open-EO/openeo-python-driver/issues/352), [Open-EO/openeo-api#549](https://github.com/Open-EO/openeo-api/pull/549))
2526

2627
## 0.122.0
2728

openeo_driver/ProcessGraphDeserializer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,14 @@
8080
# Set up process registries (version dependent)
8181

8282
# Process registry based on 1.x version of openeo-processes, to be used with api_version 1.0 an 1.1
83-
process_registry_100 = ProcessRegistry(spec_root=SPECS_ROOT / "openeo-processes/1.x", argument_names=["args", "env"])
83+
process_registry_100 = ProcessRegistry(
84+
spec_root=SPECS_ROOT / "openeo-processes/1.x", argument_names=["args", "env"], target_version="1.2.0"
85+
)
8486

8587
# Process registry based on 2.x version of openeo-processes, to be used starting with api_version 1.2
86-
process_registry_2xx = ProcessRegistry(spec_root=SPECS_ROOT / "openeo-processes/2.x", argument_names=["args", "env"])
88+
process_registry_2xx = ProcessRegistry(
89+
spec_root=SPECS_ROOT / "openeo-processes/2.x", argument_names=["args", "env"], target_version="2.0.0-rc.1"
90+
)
8791

8892

8993
def _add_standard_processes(process_registry: ProcessRegistry, process_ids: List[str]):

openeo_driver/processes.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,19 @@ class ProcessRegistry:
105105
Basically a dictionary of process specification dictionaries
106106
"""
107107

108-
def __init__(self, spec_root: Path = SPECS_ROOT / 'openeo-processes/1.x', argument_names: List[str] = None):
108+
def __init__(
109+
self,
110+
spec_root: Path = SPECS_ROOT / "openeo-processes/1.x",
111+
argument_names: List[str] = None,
112+
target_version: Optional[str] = None,
113+
):
109114
self._processes_spec_root = spec_root
110115
# Dictionary (namespace, process_name) -> ProcessData
111116
self._processes: Dict[Tuple[str, str], ProcessData] = {}
112117
# Expected argument names that process function signature should start with
113118
self._argument_names = argument_names
119+
# openeo-processes version targeted by this collection of specs (per https://github.com/Open-EO/openeo-api/pull/549)
120+
self.target_version = target_version
114121

115122
def __repr__(self):
116123
return "<{c} {n} processes>".format(c=self.__class__.__name__, n=len(self._processes))

openeo_driver/views.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,13 @@ def processes():
730730
exclusion_list = get_backend_config().processes_exclusion_list
731731
processes = _filter_by_id(processes, exclusion_list)
732732

733-
return jsonify({'processes': processes, 'links': []})
733+
return jsonify(
734+
{
735+
"version": process_registry.target_version,
736+
"processes": processes,
737+
"links": [],
738+
}
739+
)
734740

735741
@api_endpoint
736742
@blueprint.route('/processes/<namespace>', methods=['GET'])
@@ -741,6 +747,7 @@ def processes_from_namespace(namespace):
741747
# TODO: convention for user namespace? use '@' instead of "u:"
742748
# TODO: unify with `/processes` endpoint?
743749
full = smart_bool(request.args.get("full", False))
750+
target_version = None
744751
if namespace.startswith("u:") and backend_implementation.user_defined_processes:
745752
user_id = namespace.partition("u:")[-1]
746753
user_udps = [p for p in backend_implementation.user_defined_processes.get_for_user(user_id) if p.public]
@@ -749,6 +756,7 @@ def processes_from_namespace(namespace):
749756
process_registry = backend_implementation.processing.get_process_registry(
750757
api_version=requested_api_version()
751758
)
759+
target_version = process_registry.target_version
752760
processes = process_registry.get_specs(namespace=namespace)
753761
if not full:
754762
# Strip some fields
@@ -759,7 +767,13 @@ def processes_from_namespace(namespace):
759767
else:
760768
raise OpenEOApiException("Could not handle namespace {n!r}".format(n=namespace))
761769
# TODO: pagination links?
762-
return jsonify({'processes': processes, 'links': []})
770+
return jsonify(
771+
{
772+
"version": target_version,
773+
"processes": processes,
774+
"links": [],
775+
}
776+
)
763777

764778
@api_endpoint
765779
@blueprint.route('/processes/<namespace>/<process_id>', methods=['GET'])

tests/test_views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def test_file_formats(self, api100):
521521
"/processes",
522522
"/processes/backend"
523523
])
524-
def test_processes(self, api, endpoint):
524+
def test_processes(self, api_version, api, endpoint):
525525
resp = api.get(endpoint).assert_status_code(200).json
526526
processes = resp["processes"]
527527
process_ids = set(p['id'] for p in processes)
@@ -530,6 +530,9 @@ def test_processes(self, api, endpoint):
530530
for process in processes:
531531
assert all(k in process for k in expected_keys)
532532

533+
expected_version = "2.0.0-rc.1" if ComparableVersion(api_version) >= "1.2" else "1.2.0"
534+
assert resp["version"] == expected_version
535+
533536
@pytest.mark.parametrize("backend_config_overrides", [{"processes_exclusion_list": {"1.0.0":["merge_cubes"]}}])
534537
def test_processes_exclusion(self, api, backend_config_overrides):
535538
resp = api.get('/processes').assert_status_code(200).json
@@ -3396,6 +3399,7 @@ def test_public_udp(self, api100, udp_store):
33963399
{"id": "evi", "parameters": [{"name": "red"}]}
33973400
],
33983401
"links": [],
3402+
"version": None,
33993403
}
34003404

34013405
def test_public_udp_link(self, api100, udp_store):

0 commit comments

Comments
 (0)