Skip to content

Commit

Permalink
Issue #352 add process version to /processes
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Jan 8, 2025
1 parent f3f4b6b commit f18c47d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
8 changes: 6 additions & 2 deletions openeo_driver/ProcessGraphDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@
# Set up process registries (version dependent)

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

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


def _add_standard_processes(process_registry: ProcessRegistry, process_ids: List[str]):
Expand Down
9 changes: 8 additions & 1 deletion openeo_driver/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,19 @@ class ProcessRegistry:
Basically a dictionary of process specification dictionaries
"""

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

def __repr__(self):
return "<{c} {n} processes>".format(c=self.__class__.__name__, n=len(self._processes))
Expand Down
18 changes: 16 additions & 2 deletions openeo_driver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,13 @@ def processes():
exclusion_list = get_backend_config().processes_exclusion_list
processes = _filter_by_id(processes, exclusion_list)

return jsonify({'processes': processes, 'links': []})
return jsonify(
{
"version": process_registry.target_version,
"processes": processes,
"links": [],
}
)

@api_endpoint
@blueprint.route('/processes/<namespace>', methods=['GET'])
Expand All @@ -741,6 +747,7 @@ def processes_from_namespace(namespace):
# TODO: convention for user namespace? use '@' instead of "u:"
# TODO: unify with `/processes` endpoint?
full = smart_bool(request.args.get("full", False))
target_version = None
if namespace.startswith("u:") and backend_implementation.user_defined_processes:
user_id = namespace.partition("u:")[-1]
user_udps = [p for p in backend_implementation.user_defined_processes.get_for_user(user_id) if p.public]
Expand All @@ -749,6 +756,7 @@ def processes_from_namespace(namespace):
process_registry = backend_implementation.processing.get_process_registry(
api_version=requested_api_version()
)
target_version = process_registry.target_version
processes = process_registry.get_specs(namespace=namespace)
if not full:
# Strip some fields
Expand All @@ -759,7 +767,13 @@ def processes_from_namespace(namespace):
else:
raise OpenEOApiException("Could not handle namespace {n!r}".format(n=namespace))
# TODO: pagination links?
return jsonify({'processes': processes, 'links': []})
return jsonify(
{
"version": target_version,
"processes": processes,
"links": [],
}
)

@api_endpoint
@blueprint.route('/processes/<namespace>/<process_id>', methods=['GET'])
Expand Down
5 changes: 4 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def test_file_formats(self, api100):
"/processes",
"/processes/backend"
])
def test_processes(self, api, endpoint):
def test_processes(self, api_version, api, endpoint):
resp = api.get(endpoint).assert_status_code(200).json
processes = resp["processes"]
process_ids = set(p['id'] for p in processes)
Expand All @@ -530,6 +530,9 @@ def test_processes(self, api, endpoint):
for process in processes:
assert all(k in process for k in expected_keys)

expected_version = "2.0.0-rc.1" if ComparableVersion(api_version) >= "1.2" else "1.2.0"
assert resp["version"] == expected_version

@pytest.mark.parametrize("backend_config_overrides", [{"processes_exclusion_list": {"1.0.0":["merge_cubes"]}}])
def test_processes_exclusion(self, api, backend_config_overrides):
resp = api.get('/processes').assert_status_code(200).json
Expand Down

0 comments on commit f18c47d

Please sign in to comment.