Skip to content

Commit 51781d7

Browse files
committed
Further finetuning of federation extension in Jupyter context #668/#771
1 parent aa6c643 commit 51781d7

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- More extensive band detection for `load_stac` use cases, including the common `bands` metadata introduced with STAC 1.1 ([#699](https://github.com/Open-EO/openeo-python-client/issues/699), [#692](https://github.com/Open-EO/openeo-python-client/issues/692), [#586](https://github.com/Open-EO/openeo-python-client/issues/586)).
13+
- Improved support for Federation Extension in Jupyter notebook context ([#668](https://github.com/Open-EO/openeo-python-client/issues/668))
1314

1415
### Changed
1516

openeo/metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,14 +519,14 @@ class CollectionMetadata(CubeMetadata):
519519
520520
"""
521521

522-
def __init__(self, metadata: dict, dimensions: List[Dimension] = None, federation=None):
522+
def __init__(self, metadata: dict, dimensions: List[Dimension] = None, _federation: Optional[dict] = None):
523523
self._orig_metadata = metadata
524-
self._federation = federation
525524
if dimensions is None:
526525
dimensions = self._parse_dimensions(self._orig_metadata)
527-
528526
super().__init__(dimensions=dimensions)
529527

528+
self._federation = _federation
529+
530530
@classmethod
531531
def _parse_dimensions(cls, spec: dict, complain: Callable[[str], None] = warnings.warn) -> List[Dimension]:
532532
"""

openeo/rest/connection.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
JobListingResponse,
7474
ProcessListingResponse,
7575
ValidationResponse,
76+
federation_extension,
7677
)
7778
from openeo.rest.result import SaveResult
7879
from openeo.rest.service import Service
@@ -776,11 +777,12 @@ def list_file_formats(self) -> dict:
776777
key="file_formats",
777778
load=lambda: self.get('/file_formats', expected_status=200).json()
778779
)
780+
federation_missing = federation_extension.get_federation_missing(data=formats, resource_name="file_formats")
779781
federation = self.capabilities().ext_federation_backend_details()
780782
return VisualDict(
781783
"file-formats",
782784
data=formats,
783-
parameters={"missing": formats.get("federation:missing", None), "federation": federation},
785+
parameters={"missing": federation_missing, "federation": federation},
784786
)
785787

786788
def list_service_types(self) -> dict:
@@ -808,23 +810,20 @@ def list_udf_runtimes(self) -> dict:
808810
federation = self.capabilities().ext_federation_backend_details()
809811
return VisualDict("udf-runtimes", data=runtimes, parameters={"federation": federation})
810812

811-
def list_services(self) -> dict:
813+
def list_services(self) -> list:
812814
"""
813815
Loads all available services of the authenticated user.
814816
815817
:return: data_dict: Dict All available services
816818
"""
817819
# TODO return parsed service objects
818820
services = self.get('/services', expected_status=200).json()["services"]
821+
federation_missing = federation_extension.get_federation_missing(data=services, resource_name="services")
819822
federation = self.capabilities().ext_federation_backend_details()
820823
return VisualList(
821824
"data-table",
822825
data=services,
823-
parameters={
824-
"columns": "services",
825-
"missing": services.get("federation:missing", None),
826-
"federation": federation,
827-
},
826+
parameters={"columns": "services", "missing": federation_missing, "federation": federation},
828827
)
829828

830829
def describe_collection(self, collection_id: str) -> dict:
@@ -896,7 +895,7 @@ def collection_items(
896895
def collection_metadata(self, name) -> CollectionMetadata:
897896
# TODO: duplication with `Connection.describe_collection`: deprecate one or the other?
898897
federation = self.capabilities().ext_federation_backend_details()
899-
return CollectionMetadata(metadata=self.describe_collection(name), federation=federation)
898+
return CollectionMetadata(metadata=self.describe_collection(name), _federation=federation)
900899

901900
def list_processes(self, namespace: Optional[str] = None) -> ProcessListingResponse:
902901
"""
@@ -1530,15 +1529,12 @@ def list_files(self) -> List[UserFile]:
15301529
"""
15311530
data = self.get("/files", expected_status=200).json()
15321531
files = [UserFile.from_metadata(metadata=f, connection=self) for f in data.get("files", [])]
1532+
federation_missing = federation_extension.get_federation_missing(data=data, resource_name="files")
15331533
federation = self.capabilities().ext_federation_backend_details()
15341534
return VisualList(
15351535
"data-table",
15361536
data=files,
1537-
parameters={
1538-
"columns": "files",
1539-
"missing": data.get("federation:missing", None),
1540-
"federation": federation,
1541-
},
1537+
parameters={"columns": "files", "missing": federation_missing, "federation": federation},
15421538
)
15431539

15441540
def get_file(

openeo/rest/models/general.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import functools
44
from dataclasses import dataclass
5-
from typing import List, Optional, Union
5+
from typing import TYPE_CHECKING, List, Optional, Union
66

77
from openeo.internal.jupyter import render_component
88
from openeo.rest.models import federation_extension
99
from openeo.rest.models.logs import LogEntry, normalize_log_level
1010

11+
if TYPE_CHECKING:
12+
from openeo.rest.connection import Connection
1113

1214
@dataclass(frozen=True)
1315
class Link:
@@ -52,12 +54,12 @@ class CollectionListingResponse(list):
5254

5355
__slots__ = ["_data", "_connection"]
5456

55-
def __init__(self, response_data: dict, connection=None):
57+
def __init__(self, response_data: dict, connection: Optional[Connection] = None):
5658
self._data = response_data
57-
self._connection = connection
5859
# Mimic original list of collection metadata dictionaries
5960
super().__init__(response_data["collections"])
6061

62+
self._connection = connection
6163
self.ext_federation_missing(auto_warn=True)
6264

6365
def _repr_html_(self):
@@ -113,12 +115,12 @@ class ProcessListingResponse(list):
113115

114116
__slots__ = ["_data", "_connection"]
115117

116-
def __init__(self, response_data: dict, connection=None):
118+
def __init__(self, response_data: dict, connection: Optional[Connection] = None):
117119
self._data = response_data
118-
self._connection = connection
119120
# Mimic original list of process metadata dictionaries
120121
super().__init__(response_data["processes"])
121122

123+
self._connection = connection
122124
self.ext_federation_missing(auto_warn=True)
123125

124126
def _repr_html_(self):
@@ -177,12 +179,12 @@ class JobListingResponse(list):
177179

178180
__slots__ = ["_data", "_connection"]
179181

180-
def __init__(self, response_data: dict, connection=None):
182+
def __init__(self, response_data: dict, connection: Optional[Connection] = None):
181183
self._data = response_data
182-
self._connection = connection
183184
# Mimic original list of process metadata dictionaries
184185
super().__init__(response_data["jobs"])
185186

187+
self._connection = connection
186188
self.ext_federation_missing(auto_warn=True)
187189

188190
def _repr_html_(self):
@@ -243,9 +245,10 @@ class LogsResponse(list):
243245

244246
__slots__ = ["_data", "_connection"]
245247

246-
def __init__(self, response_data: dict, *, log_level: Optional[str] = None, connection=None):
248+
def __init__(
249+
self, response_data: dict, *, log_level: Optional[str] = None, connection: Optional[Connection] = None
250+
):
247251
self._data = response_data
248-
self._connection = connection
249252

250253
logs = response_data.get("logs", [])
251254
# Extra client-side level filtering (in case the back-end does not support that)
@@ -267,6 +270,7 @@ def accept_level(level: str) -> bool:
267270
# Mimic original list of process metadata dictionaries
268271
super().__init__(logs)
269272

273+
self._connection = connection
270274
self.ext_federation_missing(auto_warn=True)
271275

272276
def _repr_html_(self):

0 commit comments

Comments
 (0)