diff --git a/CHANGELOG.md b/CHANGELOG.md index cbc7c4769..98d660c03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `AGENTS.md` with guidance for AI coding agents contributing to this project, including a request to disclose AI assistance in PRs ([#923](https://github.com/Open-EO/openeo-python-client/issues/923)) - Add a `py.typed` to indicate to type checkers that the package contains type annotations. +- Add `DataCube.inspect()` helper for the openEO `inspect` process. ([#795](https://github.com/Open-EO/openeo-python-client/issues/795)) ### Changed diff --git a/openeo/rest/datacube.py b/openeo/rest/datacube.py index ee8fc1744..a9b7f0dec 100644 --- a/openeo/rest/datacube.py +++ b/openeo/rest/datacube.py @@ -137,6 +137,27 @@ def process( graph_add_node = legacy_alias(process, "graph_add_node", since="0.1.1") + def inspect(self, message=_UNSET, code=_UNSET, level=_UNSET) -> DataCube: + """ + Add information to the logs for this data cube. + + :param message: A message to send in addition to the data. + :param code: A label to help identify one or more log entries originating from this process in the list + of all log entries. It can help to group or filter log entries and is usually not unique. + :param level: The severity level of this message, defaults to `info`. + :return: new DataCube instance + + .. versionadded:: 0.51.0 + """ + arguments = {"data": self} + if message is not _UNSET: + arguments["message"] = message + if code is not _UNSET: + arguments["code"] = code + if level is not _UNSET: + arguments["level"] = level + return self.process(process_id="inspect", arguments=arguments) + def process_with_node(self, pg: PGNode, metadata: Optional[CollectionMetadata] = None) -> DataCube: """ Generic helper to create a new DataCube by applying a process (given as process graph node) diff --git a/tests/rest/datacube/test_datacube100.py b/tests/rest/datacube/test_datacube100.py index 5120931e6..3ab5d2e93 100644 --- a/tests/rest/datacube/test_datacube100.py +++ b/tests/rest/datacube/test_datacube100.py @@ -2914,6 +2914,37 @@ def test_custom_process_arguments_namespacd(con100: Connection, test_data): assert res.flat_graph() == expected +def test_inspect(con100: Connection): + cube = con100.load_collection("S2") + res = cube.inspect(message="debug cube", code="Debug", level="warning") + + assert get_download_graph(res, drop_save_result=True, drop_load_collection=True) == { + "inspect1": { + "process_id": "inspect", + "arguments": { + "data": {"from_node": "loadcollection1"}, + "message": "debug cube", + "code": "Debug", + "level": "warning", + }, + }, + } + + +def test_inspect_without_log_fields(con100: Connection): + cube = con100.load_collection("S2") + res = cube.inspect() + + assert get_download_graph(res, drop_save_result=True, drop_load_collection=True) == { + "inspect1": { + "process_id": "inspect", + "arguments": { + "data": {"from_node": "loadcollection1"}, + }, + }, + } + + @pytest.mark.parametrize("api_capabilities", [{"udp": True}]) def test_save_user_defined_process(con100, requests_mock, test_data): requests_mock.get(API_URL + "/processes", json={"processes": [{"id": "add"}]})