Skip to content

Commit 0e363be

Browse files
build: adapt to openapi client update
1 parent 798243b commit 0e363be

File tree

15 files changed

+137
-91
lines changed

15 files changed

+137
-91
lines changed

geoengine/layers.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from enum import auto
1111
from io import StringIO
1212
from typing import Any, Generic, Literal, TypeVar, cast
13-
from uuid import UUID
1413

1514
import geoengine_openapi_client
1615
from strenum import LowercaseStrEnum
@@ -183,7 +182,7 @@ def parse_listing(response: geoengine_openapi_client.CollectionItem) -> Listing:
183182
layer_id_response = cast(geoengine_openapi_client.ProviderLayerId, inner.id)
184183
return LayerListing(
185184
listing_id=LayerId(layer_id_response.layer_id),
186-
provider_id=LayerProviderId(UUID(layer_id_response.provider_id)),
185+
provider_id=LayerProviderId(layer_id_response.provider_id),
187186
name=inner.name,
188187
description=inner.description,
189188
)
@@ -192,7 +191,7 @@ def parse_listing(response: geoengine_openapi_client.CollectionItem) -> Listing:
192191
collection_id_response = cast(geoengine_openapi_client.ProviderLayerCollectionId, inner.id)
193192
return LayerCollectionListing(
194193
listing_id=LayerCollectionId(collection_id_response.collection_id),
195-
provider_id=LayerProviderId(UUID(collection_id_response.provider_id)),
194+
provider_id=LayerProviderId(collection_id_response.provider_id),
196195
name=inner.name,
197196
description=inner.description,
198197
)
@@ -210,7 +209,7 @@ def parse_listing(response: geoengine_openapi_client.CollectionItem) -> Listing:
210209
name=response.name,
211210
description=response.description,
212211
collection_id=LayerCollectionId(response.id.collection_id),
213-
provider_id=LayerProviderId(UUID(response.id.provider_id)),
212+
provider_id=LayerProviderId(response.id.provider_id),
214213
items=items,
215214
)
216215

@@ -291,7 +290,8 @@ def add_layer(
291290
self,
292291
name: str,
293292
description: str,
294-
workflow: dict[str, Any] | WorkflowBuilderOperator, # TODO: improve type
293+
# TODO: improve type
294+
workflow: dict[str, Any] | WorkflowBuilderOperator,
295295
symbology: Symbology | None,
296296
timeout: int = 60,
297297
) -> LayerId:
@@ -318,7 +318,8 @@ def add_layer_with_permissions(
318318
self,
319319
name: str,
320320
description: str,
321-
workflow: dict[str, Any] | WorkflowBuilderOperator, # TODO: improve type
321+
# TODO: improve type
322+
workflow: dict[str, Any] | WorkflowBuilderOperator,
322323
symbology: Symbology | None,
323324
permission_tuples: list[tuple[RoleId, Permission]] | None = None,
324325
timeout: int = 60,
@@ -397,7 +398,8 @@ def add_existing_collection(
397398
collection_id = existing_collection.listing_id
398399
elif isinstance(existing_collection, LayerCollection):
399400
collection_id = existing_collection.collection_id
400-
elif isinstance(existing_collection, str): # TODO: check for LayerId in Python 3.11+
401+
# TODO: check for LayerId in Python 3.11+
402+
elif isinstance(existing_collection, str):
401403
collection_id = existing_collection
402404
else:
403405
raise InputException("Invalid collection type")
@@ -446,7 +448,7 @@ def search(
446448
with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
447449
layers_api = geoengine_openapi_client.LayersApi(api_client)
448450
layer_collection_response = layers_api.search_handler(
449-
provider=str(self.provider_id),
451+
provider=self.provider_id,
450452
collection=str(self.collection_id),
451453
search_string=search_string,
452454
search_type=geoengine_openapi_client.SearchType(search_type),
@@ -464,7 +466,7 @@ def search(
464466
listings.append(
465467
LayerCollectionListing(
466468
listing_id=LayerCollectionId(inner.id.collection_id),
467-
provider_id=LayerProviderId(UUID(inner.id.provider_id)),
469+
provider_id=LayerProviderId(inner.id.provider_id),
468470
name=inner.name,
469471
description=inner.description,
470472
)
@@ -473,7 +475,7 @@ def search(
473475
listings.append(
474476
LayerListing(
475477
listing_id=LayerId(inner.id.layer_id),
476-
provider_id=LayerProviderId(UUID(inner.id.provider_id)),
478+
provider_id=LayerProviderId(inner.id.provider_id),
477479
name=inner.name,
478480
description=inner.description,
479481
)
@@ -529,7 +531,8 @@ def get_or_create_unique_collection(
529531
if isinstance(res, Layer):
530532
raise TypeError(f"Found a Layer not a Layer collection for {collection_name}")
531533

532-
return cast(LayerCollection, existing_collections[0].load()) # we know that it is a collection since check that
534+
# we know that it is a collection since check that
535+
return cast(LayerCollection, existing_collections[0].load())
533536

534537
def __eq__(self, other):
535538
"""Tests if two layer listings are identical"""
@@ -594,7 +597,7 @@ def from_response(cls, response: geoengine_openapi_client.Layer) -> Layer:
594597
name=response.name,
595598
description=response.description,
596599
layer_id=LayerId(response.id.layer_id),
597-
provider_id=LayerProviderId(UUID(response.id.provider_id)),
600+
provider_id=LayerProviderId(response.id.provider_id),
598601
workflow=response.workflow.to_dict(),
599602
symbology=symbology,
600603
properties=cast(list[Any], response.properties),
@@ -656,7 +659,7 @@ def save_as_dataset(self, timeout: int = 60) -> Task:
656659

657660
with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
658661
layers_api = geoengine_openapi_client.LayersApi(api_client)
659-
response = layers_api.layer_to_dataset(str(self.provider_id), str(self.layer_id), _request_timeout=timeout)
662+
response = layers_api.layer_to_dataset(self.provider_id, str(self.layer_id), _request_timeout=timeout)
660663

661664
return Task(TaskId.from_response(response))
662665

@@ -684,7 +687,7 @@ def as_workflow_id(self, timeout: int = 60) -> WorkflowId:
684687
with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
685688
layers_api = geoengine_openapi_client.LayersApi(api_client)
686689
response = layers_api.layer_to_workflow_id_handler(
687-
str(self.provider_id), self.layer_id, _request_timeout=timeout
690+
self.provider_id, self.layer_id, _request_timeout=timeout
688691
)
689692

690693
return WorkflowId.from_response(response)
@@ -721,11 +724,12 @@ def layer_collection(
721724
page = layers_api.list_root_collections_handler(offset, page_limit, _request_timeout=timeout)
722725
else:
723726
page = layers_api.list_collection_handler(
724-
str(layer_provider_id), layer_collection_id, offset, page_limit, _request_timeout=timeout
727+
layer_provider_id, layer_collection_id, offset, page_limit, _request_timeout=timeout
725728
)
726729

727730
if len(page.items) < page_limit:
728-
if len(pages) == 0 or len(page.items) > 0: # we need at least one page before breaking
731+
# we need at least one page before breaking
732+
if len(pages) == 0 or len(page.items) > 0:
729733
pages.append(page)
730734
break
731735

@@ -744,7 +748,7 @@ def layer(layer_id: LayerId, layer_provider_id: LayerProviderId = LAYER_DB_PROVI
744748

745749
with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
746750
layers_api = geoengine_openapi_client.LayersApi(api_client)
747-
response = layers_api.layer_handler(str(layer_provider_id), str(layer_id), _request_timeout=timeout)
751+
response = layers_api.layer_handler(layer_provider_id, str(layer_id), _request_timeout=timeout)
748752

749753
return Layer.from_response(response)
750754

@@ -799,7 +803,7 @@ def _add_layer_collection_to_collection(
799803
_request_timeout=timeout,
800804
)
801805

802-
return LayerCollectionId(response.id)
806+
return LayerCollectionId(str(response.id))
803807

804808

805809
def _add_existing_layer_collection_to_collection(
@@ -843,7 +847,7 @@ def _add_layer_to_collection(
843847
_request_timeout=timeout,
844848
)
845849

846-
return LayerId(response.id)
850+
return LayerId(str(response.id))
847851

848852

849853
def _add_existing_layer_to_collection(layer_id: LayerId, collection_id: LayerCollectionId, timeout: int = 60) -> None:

geoengine/permissions.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def __str__(self) -> str:
5050
def __repr__(self) -> str:
5151
return repr(self.__role_id)
5252

53+
def to_dict(self) -> UUID:
54+
return self.__role_id
55+
5356

5457
class Role:
5558
"""A wrapper for a role"""
@@ -124,6 +127,9 @@ def __str__(self) -> str:
124127
def __repr__(self) -> str:
125128
return repr(self.__user_id)
126129

130+
def to_dict(self) -> UUID:
131+
return self.__user_id
132+
127133

128134
class PermissionListing:
129135
"""
@@ -230,7 +236,11 @@ def list_permissions(resource: Resource, timeout: int = 60, offset=0, limit=20)
230236
with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
231237
permission_api = geoengine_openapi_client.PermissionsApi(api_client)
232238
res = permission_api.get_resource_permissions_handler(
233-
resource_id=resource.id, resource_type=resource.type, offset=offset, limit=limit, _request_timeout=timeout
239+
resource_id=str(resource.id),
240+
resource_type=resource.type,
241+
offset=offset,
242+
limit=limit,
243+
_request_timeout=timeout,
234244
)
235245

236246
return [PermissionListing.from_response(r) for r in res]
@@ -259,7 +269,7 @@ def remove_role(role: RoleId, timeout: int = 60):
259269

260270
with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
261271
user_api = geoengine_openapi_client.UserApi(api_client)
262-
user_api.remove_role_handler(str(role), _request_timeout=timeout)
272+
user_api.remove_role_handler(role.to_dict(), _request_timeout=timeout)
263273

264274

265275
def assign_role(role: RoleId, user: UserId, timeout: int = 60):
@@ -269,7 +279,7 @@ def assign_role(role: RoleId, user: UserId, timeout: int = 60):
269279

270280
with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
271281
user_api = geoengine_openapi_client.UserApi(api_client)
272-
user_api.assign_role_handler(str(user), str(role), _request_timeout=timeout)
282+
user_api.assign_role_handler(user.to_dict(), role.to_dict(), _request_timeout=timeout)
273283

274284

275285
def revoke_role(role: RoleId, user: UserId, timeout: int = 60):
@@ -279,4 +289,4 @@ def revoke_role(role: RoleId, user: UserId, timeout: int = 60):
279289

280290
with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
281291
user_api = geoengine_openapi_client.UserApi(api_client)
282-
user_api.revoke_role_handler(str(user), str(role), _request_timeout=timeout)
292+
user_api.revoke_role_handler(user.to_dict(), role.to_dict(), _request_timeout=timeout)

geoengine/resource_identifier.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __init__(self, upload_id: UUID) -> None:
8686
@classmethod
8787
def from_response(cls, response: geoengine_openapi_client.IdResponse) -> UploadId:
8888
"""Parse a http response to an `UploadId`"""
89-
return UploadId(UUID(response.id))
89+
return UploadId(response.id)
9090

9191
def __str__(self) -> str:
9292
return str(self.__upload_id)
@@ -109,11 +109,13 @@ def to_api_dict(self) -> geoengine_openapi_client.IdResponse:
109109
class Resource:
110110
"""A wrapper for a resource id"""
111111

112-
id: str
112+
id: str | UUID
113113
type: Literal["dataset", "layer", "layerCollection", "mlModel", "project"]
114114

115115
def __init__(
116-
self, resource_type: Literal["dataset", "layer", "layerCollection", "mlModel", "project"], resource_id: str
116+
self,
117+
resource_type: Literal["dataset", "layer", "layerCollection", "mlModel", "project"],
118+
resource_id: str | UUID,
117119
) -> None:
118120
"""Create a resource id"""
119121
self.type = resource_type

geoengine/tasks.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, task_id: UUID) -> None:
2828
def from_response(cls, response: geoengine_openapi_client.TaskResponse) -> TaskId:
2929
"""Parse a http response to an `TaskId`"""
3030

31-
return TaskId(UUID(response.task_id))
31+
return TaskId(response.task_id)
3232

3333
def __eq__(self, other) -> bool:
3434
"""Checks if two dataset ids are equal"""
@@ -43,6 +43,9 @@ def __str__(self) -> str:
4343
def __repr__(self) -> str:
4444
return repr(self.__task_id)
4545

46+
def to_dict(self) -> UUID:
47+
return self.__task_id
48+
4649

4750
class TaskStatus(Enum):
4851
"""An enum of task status types"""
@@ -260,12 +263,12 @@ def get_status(self, timeout: int = 3600) -> TaskStatusInfo:
260263
"""
261264
session = get_session()
262265

263-
task_id_str = str(self.__task_id)
266+
task_id = self.__task_id.to_dict()
264267

265268
with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
266269
tasks_api = geoengine_openapi_client.TasksApi(api_client)
267-
print(task_id_str)
268-
response = tasks_api.status_handler(task_id_str, _request_timeout=timeout)
270+
print(task_id)
271+
response = tasks_api.status_handler(task_id, _request_timeout=timeout)
269272

270273
return TaskStatusInfo.from_response(response)
271274

@@ -275,11 +278,11 @@ def abort(self, force: bool = False, timeout: int = 3600) -> None:
275278
"""
276279
session = get_session()
277280

278-
task_id_str = str(self.__task_id)
281+
task_id = self.__task_id.to_dict()
279282

280283
with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
281284
tasks_api = geoengine_openapi_client.TasksApi(api_client)
282-
tasks_api.abort_handler(task_id_str, None if force is False else True, _request_timeout=timeout)
285+
tasks_api.abort_handler(task_id, None if force is False else True, _request_timeout=timeout)
283286

284287
def wait_for_finish(
285288
self, check_interval_seconds: float = 5, request_timeout: int = 3600, print_status: bool = True
@@ -311,8 +314,8 @@ async def as_future(self, request_interval: int = 5, print_status=False) -> Task
311314
Returns a future that will be resolved when the task is finished in the backend.
312315
"""
313316

314-
def get_status_inner(tasks_api: geoengine_openapi_client.TasksApi, task_id_str: str, timeout: int = 3600):
315-
return tasks_api.status_handler(task_id_str, _request_timeout=timeout)
317+
def get_status_inner(tasks_api: geoengine_openapi_client.TasksApi, task_id: UUID, timeout: int = 3600):
318+
return tasks_api.status_handler(task_id, _request_timeout=timeout)
316319

317320
session = get_session()
318321
task_id_str = str(self.__task_id)
@@ -346,6 +349,6 @@ def get_task_list(timeout: int = 3600) -> list[tuple[Task, TaskStatusInfo]]:
346349

347350
result = []
348351
for item in response:
349-
result.append((Task(TaskId(UUID(item.task_id))), TaskStatusInfo.from_response(item)))
352+
result.append((Task(TaskId(item.task_id)), TaskStatusInfo.from_response(item)))
350353

351354
return result

geoengine/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ def __init__(self, dataset_id: UUID):
11711171
@classmethod
11721172
def from_response_internal(cls, response: geoengine_openapi_client.InternalDataId) -> InternalDataId:
11731173
"""Parse an http response to a `InternalDataId` object"""
1174-
return InternalDataId(UUID(response.dataset_id))
1174+
return InternalDataId(response.dataset_id)
11751175

11761176
def to_api_dict(self) -> geoengine_openapi_client.DataId:
11771177
return geoengine_openapi_client.DataId(
@@ -1207,7 +1207,7 @@ def __init__(self, provider_id: UUID, layer_id: str):
12071207
def from_response_external(cls, response: geoengine_openapi_client.ExternalDataId) -> ExternalDataId:
12081208
"""Parse an http response to a `ExternalDataId` object"""
12091209

1210-
return ExternalDataId(UUID(response.provider_id), response.layer_id)
1210+
return ExternalDataId(response.provider_id, response.layer_id)
12111211

12121212
def to_api_dict(self) -> geoengine_openapi_client.DataId:
12131213
return geoengine_openapi_client.DataId(

0 commit comments

Comments
 (0)