• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geo-engine / geoengine-python / 16367912334

18 Jul 2025 10:06AM UTC coverage: 76.934% (+0.1%) from 76.806%
16367912334

push

github

web-flow
ci: use Ruff as new formatter and linter (#233)

* wip

* pycodestyle

* update dependencies

* skl2onnx

* use ruff

* apply formatter

* apply lint auto fixes

* manually apply lints

* change check

* ruff ci from branch

2805 of 3646 relevant lines covered (76.93%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.07
geoengine/resource_identifier.py
1
"""Types that identify a ressource in the Geo Engine"""
2

3
from __future__ import annotations
1✔
4

5
from typing import Any, Literal, NewType
1✔
6
from uuid import UUID
1✔
7

8
import geoengine_openapi_client
1✔
9

10
LayerId = NewType("LayerId", str)
1✔
11
LayerCollectionId = NewType("LayerCollectionId", str)
1✔
12
LayerProviderId = NewType("LayerProviderId", UUID)
1✔
13

14
LAYER_DB_PROVIDER_ID = LayerProviderId(UUID("ce5e84db-cbf9-48a2-9a32-d4b7cc56ea74"))
1✔
15
LAYER_DB_ROOT_COLLECTION_ID = LayerCollectionId("05102bb3-a855-4a37-8a8a-30026a91fef1")
1✔
16

17

18
class MlModelName:
1✔
19
    """A wrapper for an MlModel name"""
20

21
    __ml_model_name: str
1✔
22

23
    def __init__(self, ml_model_name: str) -> None:
1✔
24
        self.__ml_model_name = ml_model_name
1✔
25

26
    @classmethod
1✔
27
    def from_response(cls, response: geoengine_openapi_client.models.MlModelNameResponse) -> MlModelName:
1✔
28
        """Parse a http response to an `DatasetName`"""
29
        return MlModelName(response.ml_model_name)
1✔
30

31
    def __str__(self) -> str:
1✔
32
        return self.__ml_model_name
1✔
33

34
    def __repr__(self) -> str:
1✔
35
        return str(self)
×
36

37
    def __eq__(self, other) -> bool:
1✔
38
        """Checks if two dataset names are equal"""
39
        if not isinstance(other, self.__class__):
×
40
            return False
×
41

42
        return self.__ml_model_name == other.__ml_model_name  # pylint: disable=protected-access
×
43

44
    def to_api_dict(self) -> geoengine_openapi_client.models.MlModelNameResponse:
1✔
45
        return geoengine_openapi_client.models.MlModelNameResponse(ml_model_name=str(self.__ml_model_name))
×
46

47

48
class DatasetName:
1✔
49
    """A wrapper for a dataset name"""
50

51
    __dataset_name: str
1✔
52

53
    def __init__(self, dataset_name: str) -> None:
1✔
54
        self.__dataset_name = dataset_name
1✔
55

56
    @classmethod
1✔
57
    def from_response(cls, response: geoengine_openapi_client.DatasetNameResponse) -> DatasetName:
1✔
58
        """Parse a http response to an `DatasetName`"""
59
        return DatasetName(response.dataset_name)
1✔
60

61
    def __str__(self) -> str:
1✔
62
        return self.__dataset_name
1✔
63

64
    def __repr__(self) -> str:
1✔
65
        return str(self)
×
66

67
    def __eq__(self, other) -> bool:
1✔
68
        """Checks if two dataset names are equal"""
69
        if not isinstance(other, self.__class__):
1✔
70
            return False
1✔
71

72
        return self.__dataset_name == other.__dataset_name  # pylint: disable=protected-access
1✔
73

74
    def to_api_dict(self) -> geoengine_openapi_client.DatasetNameResponse:
1✔
75
        return geoengine_openapi_client.DatasetNameResponse(dataset_name=str(self.__dataset_name))
×
76

77

78
class UploadId:
1✔
79
    """A wrapper for an upload id"""
80

81
    __upload_id: UUID
1✔
82

83
    def __init__(self, upload_id: UUID) -> None:
1✔
84
        self.__upload_id = upload_id
1✔
85

86
    @classmethod
1✔
87
    def from_response(cls, response: geoengine_openapi_client.IdResponse) -> UploadId:
1✔
88
        """Parse a http response to an `UploadId`"""
89
        return UploadId(UUID(response.id))
1✔
90

91
    def __str__(self) -> str:
1✔
92
        return str(self.__upload_id)
1✔
93

94
    def __repr__(self) -> str:
1✔
95
        return str(self)
×
96

97
    def __eq__(self, other) -> bool:
1✔
98
        """Checks if two upload ids are equal"""
99
        if not isinstance(other, self.__class__):
1✔
100
            return False
1✔
101

102
        return self.__upload_id == other.__upload_id  # pylint: disable=protected-access
1✔
103

104
    def to_api_dict(self) -> geoengine_openapi_client.IdResponse:
1✔
105
        """Converts the upload id to a dict for the api"""
106
        return geoengine_openapi_client.IdResponse(id=str(self.__upload_id))
×
107

108

109
class Resource:
1✔
110
    """A wrapper for a resource id"""
111

112
    id: str
1✔
113
    type: Literal["dataset", "layer", "layerCollection", "mlModel", "project"]
1✔
114

115
    def __init__(
1✔
116
        self, resource_type: Literal["dataset", "layer", "layerCollection", "mlModel", "project"], resource_id: str
117
    ) -> None:
118
        """Create a resource id"""
119
        self.type = resource_type
1✔
120
        self.id = resource_id
1✔
121

122
    @classmethod
1✔
123
    def from_layer_id(cls, layer_id: LayerId) -> Resource:
1✔
124
        """Create a resource id from a layer id"""
125
        return Resource("layer", str(layer_id))
1✔
126

127
    @classmethod
1✔
128
    def from_layer_collection_id(cls, layer_collection_id: LayerCollectionId) -> Resource:
1✔
129
        """Create a resource id from a layer collection id"""
130
        return Resource("layerCollection", str(layer_collection_id))
1✔
131

132
    @classmethod
1✔
133
    def from_dataset_name(cls, dataset_name: DatasetName | str) -> Resource:
1✔
134
        """Create a resource id from a dataset name"""
135
        if isinstance(dataset_name, DatasetName):
1✔
136
            dataset_name = str(dataset_name)
1✔
137
        return Resource("dataset", dataset_name)
1✔
138

139
    @classmethod
1✔
140
    def from_ml_model_name(cls, ml_model_name: MlModelName | str) -> Resource:
1✔
141
        """Create a resource from an ml model name"""
142
        if isinstance(ml_model_name, MlModelName):
1✔
143
            ml_model_name = str(ml_model_name)
1✔
144
        return Resource("mlModel", ml_model_name)
1✔
145

146
    def to_api_dict(self) -> geoengine_openapi_client.Resource:
1✔
147
        """Convert to a dict for the API"""
148
        inner: Any = None
1✔
149

150
        if self.type == "layer":
1✔
151
            inner = geoengine_openapi_client.LayerResource(type="layer", id=self.id)
1✔
152
        elif self.type == "layerCollection":
1✔
153
            inner = geoengine_openapi_client.LayerCollectionResource(type="layerCollection", id=self.id)
1✔
154
        elif self.type == "project":
1✔
155
            inner = geoengine_openapi_client.ProjectResource(type="project", id=self.id)
×
156
        elif self.type == "dataset":
1✔
157
            inner = geoengine_openapi_client.DatasetResource(type="dataset", id=self.id)
1✔
158
        elif self.type == "mlModel":
1✔
159
            inner = geoengine_openapi_client.MlModelResource(type="mlModel", id=self.id)
1✔
160
        else:
161
            raise KeyError(f"Unknown resource type: {self.type}")
×
162

163
        return geoengine_openapi_client.Resource(inner)
1✔
164

165
    @classmethod
1✔
166
    def from_response(cls, response: geoengine_openapi_client.Resource) -> Resource:
1✔
167
        """Convert to a dict for the API"""
168
        inner: Resource
169
        if isinstance(response.actual_instance, geoengine_openapi_client.LayerResource):
1✔
170
            inner = Resource("layer", response.actual_instance.id)
1✔
171
        elif isinstance(response.actual_instance, geoengine_openapi_client.LayerCollectionResource):
1✔
172
            inner = Resource("layerCollection", response.actual_instance.id)
1✔
173
        elif isinstance(response.actual_instance, geoengine_openapi_client.ProjectResource):
1✔
174
            inner = Resource("project", response.actual_instance.id)
×
175
        elif isinstance(response.actual_instance, geoengine_openapi_client.DatasetResource):
1✔
176
            inner = Resource("dataset", response.actual_instance.id)
1✔
177
        elif isinstance(response.actual_instance, geoengine_openapi_client.MlModelResource):
1✔
178
            inner = Resource("mlModel", response.actual_instance.id)
1✔
179
        else:
180
            raise KeyError(f"Unknown resource type from API: {response.actual_instance}")
×
181
        return inner
1✔
182

183
    def __repr__(self):
1✔
184
        return "id: " + repr(self.id) + ", type: " + repr(self.type)
×
185

186
    def __eq__(self, value):
1✔
187
        """Checks if two listings are equal"""
188
        if not isinstance(value, self.__class__):
1✔
189
            return False
×
190
        return self.id == value.id and self.type == value.type
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc