Skip to content

Commit 4d9d376

Browse files
committed
Draft support for the federation extension in Jupyter visual outputs #668
1 parent 238c8a6 commit 4d9d376

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

openeo/rest/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ def list_collections(self) -> CollectionListingResponse:
713713
# TODO: add caching #383, but reset cache on auth change #254
714714
# TODO #677 add pagination support?
715715
data = self.get("/collections", expected_status=200).json()
716-
return CollectionListingResponse(response_data=data)
716+
return CollectionListingResponse(response_data=data, connection=self)
717717

718718
def list_collection_ids(self) -> List[str]:
719719
"""
@@ -870,7 +870,7 @@ def list_processes(self, namespace: Optional[str] = None) -> ProcessListingRespo
870870
)
871871
else:
872872
response = self.get("/processes/" + namespace, expected_status=200).json()
873-
return ProcessListingResponse(response_data=response)
873+
return ProcessListingResponse(response_data=response, connection=self)
874874

875875
def describe_process(self, id: str, namespace: Optional[str] = None) -> dict:
876876
"""
@@ -912,7 +912,7 @@ def list_jobs(self, limit: Union[int, None] = 100) -> JobListingResponse:
912912
# TODO: Parse the result so that Job classes returned?
913913
# TODO: when pagination is enabled: how to expose link to next page?
914914
resp = self.get("/jobs", params={"limit": limit}, expected_status=200).json()
915-
return JobListingResponse(response_data=resp)
915+
return JobListingResponse(response_data=resp, connection=self)
916916

917917
def assert_user_defined_process_support(self):
918918
"""

openeo/rest/models/general.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,33 @@ class CollectionListingResponse(list):
4343
but now also provides methods/properties to access additional response data.
4444
4545
:param response_data: response data from a ``GET /collections`` request
46+
:param connection: optional connection object to use for federation extension
4647
4748
.. seealso:: :py:meth:`openeo.rest.connection.Connection.list_collections()`
4849
4950
.. versionadded:: 0.38.0
5051
"""
5152

52-
__slots__ = ["_data"]
53+
__slots__ = ["_data", "_connection"]
5354

54-
def __init__(self, response_data: dict):
55+
def __init__(self, response_data: dict, connection = None):
5556
self._data = response_data
57+
self._connection = connection
5658
# Mimic original list of collection metadata dictionaries
5759
super().__init__(response_data["collections"])
5860

5961
self.ext_federation_missing(auto_warn=True)
6062

6163
def _repr_html_(self):
62-
return render_component(component="collections", data=self)
64+
federation = self._connection.capabilities().ext_federation_backend_details() if self._connection else None
65+
return render_component(
66+
component="collections",
67+
data=self,
68+
parameters={
69+
"missing": self.ext_federation_missing(),
70+
"federation": federation,
71+
}
72+
)
6373

6474
@property
6575
def links(self) -> List[Link]:
@@ -94,24 +104,34 @@ class ProcessListingResponse(list):
94104
but now also provides methods/properties to access additional response data.
95105
96106
:param response_data: response data from a ``GET /processes`` request
107+
:param connection: optional connection object to use for federation extension
97108
98109
.. seealso:: :py:meth:`openeo.rest.connection.Connection.list_processes()`
99110
100111
.. versionadded:: 0.38.0
101112
"""
102113

103-
__slots__ = ["_data"]
114+
__slots__ = ["_data", "_connection"]
104115

105-
def __init__(self, response_data: dict):
116+
def __init__(self, response_data: dict, connection = None):
106117
self._data = response_data
118+
self._connection = connection
107119
# Mimic original list of process metadata dictionaries
108120
super().__init__(response_data["processes"])
109121

110122
self.ext_federation_missing(auto_warn=True)
111123

112124
def _repr_html_(self):
125+
federation = self._connection.capabilities().ext_federation_backend_details() if self._connection else None
113126
return render_component(
114-
component="processes", data=self, parameters={"show-graph": True, "provide-download": False}
127+
component="processes",
128+
data=self,
129+
parameters={
130+
"show-graph": True,
131+
"provide-download": False,
132+
"missing": self.ext_federation_missing(),
133+
"federation": federation,
134+
}
115135
)
116136

117137
@property
@@ -148,23 +168,34 @@ class JobListingResponse(list):
148168
but now also provides methods/properties to access additional response data.
149169
150170
:param response_data: response data from a ``GET /jobs`` request
171+
:param connection: optional connection object to use for federation extension
151172
152173
.. seealso:: :py:meth:`openeo.rest.connection.Connection.list_jobs()`
153174
154175
.. versionadded:: 0.38.0
155176
"""
156177

157-
__slots__ = ["_data"]
178+
__slots__ = ["_data", "_connection"]
158179

159-
def __init__(self, response_data: dict):
180+
def __init__(self, response_data: dict, connection = None):
160181
self._data = response_data
182+
self._connection = connection
161183
# Mimic original list of process metadata dictionaries
162184
super().__init__(response_data["jobs"])
163185

164186
self.ext_federation_missing(auto_warn=True)
165187

166188
def _repr_html_(self):
167-
return render_component(component="data-table", data=self, parameters={"columns": "jobs"})
189+
federation = self._connection.capabilities().ext_federation_backend_details() if self._connection else None
190+
return render_component(
191+
component="data-table",
192+
data=self,
193+
parameters={
194+
"columns": "jobs",
195+
"missing": self.ext_federation_missing(),
196+
"federation": federation,
197+
}
198+
)
168199

169200
@property
170201
def links(self) -> List[Link]:

0 commit comments

Comments
 (0)