7272 ProcessListingResponse ,
7373 ValidationResponse ,
7474)
75+ from openeo .rest .result import SaveResult
7576from openeo .rest .service import Service
7677from openeo .rest .udp import Parameter , RESTUserDefinedProcess
7778from openeo .rest .userfile import UserFile
@@ -1037,9 +1038,12 @@ def datacube_from_process(self, process_id: str, namespace: Optional[str] = None
10371038 graph = PGNode (process_id , namespace = namespace , arguments = kwargs )
10381039 return DataCube (graph = graph , connection = self )
10391040
1040- def datacube_from_flat_graph (self , flat_graph : dict , parameters : Optional [dict ] = None ) -> DataCube :
1041+ def datacube_from_flat_graph (
1042+ self , flat_graph : dict , parameters : Optional [dict ] = None
1043+ ) -> Union [DataCube , SaveResult ]:
10411044 """
1042- Construct a :py:class:`DataCube` from a flat dictionary representation of a process graph.
1045+ Construct a :py:class:`~openeo.rest.datacube.DataCube`/:py:class:`~openeo.rest.result.SaveResult`
1046+ from the operations encoded in a flat dictionary representation of an openEO process graph.
10431047
10441048 .. seealso:: :ref:`datacube_from_json`, :py:meth:`~openeo.rest.connection.Connection.datacube_from_json`
10451049
@@ -1048,7 +1052,6 @@ def datacube_from_flat_graph(self, flat_graph: dict, parameters: Optional[dict]
10481052 (and optionally parameter metadata under a "parameters" field).
10491053 :param parameters: Optional dictionary mapping parameter names to parameter values
10501054 to use for parameters occurring in the process graph (e.g. as used in user-defined processes)
1051- :return: A :py:class:`DataCube` corresponding with the operations encoded in the process graph
10521055 """
10531056 parameters = parameters or {}
10541057
@@ -1062,18 +1065,26 @@ def datacube_from_flat_graph(self, flat_graph: dict, parameters: Optional[dict]
10621065 flat_graph = flat_graph ["process_graph" ]
10631066
10641067 pgnode = PGNode .from_flat_graph (flat_graph = flat_graph , parameters = parameters or {})
1065- return DataCube (graph = pgnode , connection = self )
10661068
1067- def datacube_from_json (self , src : Union [str , Path ], parameters : Optional [dict ] = None ) -> DataCube :
1069+ # TODO #733: smarter or more dynamic detection of what kind of object to return?
1070+ # TODO #733: rename `datacube_from_flat_graph` to something more general as this is not only about DataCube's anymore?
1071+ if pgnode .process_id == "save_result" :
1072+ return SaveResult (graph = pgnode , connection = self )
1073+ else :
1074+ return DataCube (graph = pgnode , connection = self )
1075+
1076+ def datacube_from_json (
1077+ self , src : Union [str , Path ], parameters : Optional [dict ] = None
1078+ ) -> Union [DataCube , SaveResult ]:
10681079 """
1069- Construct a :py:class:`DataCube` from JSON resource containing (flat) process graph representation.
1080+ Construct a :py:class:`~openeo.rest.datacube.DataCube`/:py:class:`~openeo.rest.result.SaveResult`
1081+ from a JSON resource containing a (flat) openEO process graph representation.
10701082
10711083 .. seealso:: :ref:`datacube_from_json`, :py:meth:`~openeo.rest.connection.Connection.datacube_from_flat_graph`
10721084
10731085 :param src: raw JSON string, URL to JSON resource or path to local JSON file
10741086 :param parameters: Optional dictionary mapping parameter names to parameter values
10751087 to use for parameters occurring in the process graph (e.g. as used in user-defined processes)
1076- :return: A :py:class:`DataCube` corresponding with the operations encoded in the process graph
10771088 """
10781089 return self .datacube_from_flat_graph (load_json_resource (src ), parameters = parameters )
10791090
0 commit comments