cognite-toolkit 0.7.21__py3-none-any.whl → 0.7.23__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cognite_toolkit/_cdf_tk/resource_classes/migration.py +8 -17
- cognite_toolkit/_cdf_tk/storageio/_applications.py +47 -7
- cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml +1 -1
- cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml +1 -1
- cognite_toolkit/_resources/cdf.toml +1 -1
- cognite_toolkit/_version.py +1 -1
- {cognite_toolkit-0.7.21.dist-info → cognite_toolkit-0.7.23.dist-info}/METADATA +1 -1
- {cognite_toolkit-0.7.21.dist-info → cognite_toolkit-0.7.23.dist-info}/RECORD +11 -11
- {cognite_toolkit-0.7.21.dist-info → cognite_toolkit-0.7.23.dist-info}/WHEEL +0 -0
- {cognite_toolkit-0.7.21.dist-info → cognite_toolkit-0.7.23.dist-info}/entry_points.txt +0 -0
- {cognite_toolkit-0.7.21.dist-info → cognite_toolkit-0.7.23.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import re
|
|
2
1
|
from typing import Literal
|
|
3
2
|
|
|
4
|
-
from pydantic import Field
|
|
3
|
+
from pydantic import Field
|
|
5
4
|
|
|
6
|
-
from cognite_toolkit._cdf_tk.
|
|
5
|
+
from cognite_toolkit._cdf_tk.constants import INSTANCE_EXTERNAL_ID_PATTERN
|
|
7
6
|
|
|
8
7
|
from .base import ToolkitResource
|
|
9
8
|
from .view_field_definitions import ViewReference
|
|
10
9
|
|
|
11
|
-
JSON_PATH_PATTERN = re.compile(
|
|
12
|
-
r"^([a-zA-Z_][a-zA-Z0-9_]*|\[\d+\])(\.[a-zA-Z_][a-zA-Z0-9_]*|\[\d+\]|\[\'[^\']*\'\]|\[\"[^\"]*\"\])*$"
|
|
13
|
-
)
|
|
14
|
-
|
|
15
10
|
|
|
16
11
|
class ResourceViewMappingYAML(ToolkitResource):
|
|
12
|
+
external_id: str = Field(
|
|
13
|
+
description="External-id of the mapping.",
|
|
14
|
+
min_length=1,
|
|
15
|
+
max_length=256,
|
|
16
|
+
pattern=INSTANCE_EXTERNAL_ID_PATTERN,
|
|
17
|
+
)
|
|
17
18
|
resource_type: Literal["asset", "event", "file", "timeSeries", "sequence", "assetAnnotation", "fileAnnotation"] = (
|
|
18
19
|
Field(
|
|
19
20
|
description="The type of the resource to map to the view.",
|
|
@@ -25,13 +26,3 @@ class ResourceViewMappingYAML(ToolkitResource):
|
|
|
25
26
|
property_mapping: dict[str, str] = Field(
|
|
26
27
|
description="A dictionary mapping from resource property to view property.",
|
|
27
28
|
)
|
|
28
|
-
|
|
29
|
-
@field_validator("property_mapping")
|
|
30
|
-
@classmethod
|
|
31
|
-
def validate_json_paths(cls, value: dict[str, str]) -> dict[str, str]:
|
|
32
|
-
if not isinstance(value, dict):
|
|
33
|
-
return value
|
|
34
|
-
not_matching_keys = [k for k in value.keys() if not re.match(JSON_PATH_PATTERN, k)]
|
|
35
|
-
if not_matching_keys:
|
|
36
|
-
raise ValueError(f"Invalid JSON paths: {humanize_collection(not_matching_keys)}")
|
|
37
|
-
return value
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from collections.abc import Iterable, Sequence
|
|
2
|
+
from typing import Any
|
|
2
3
|
|
|
3
4
|
from cognite_toolkit._cdf_tk.client.data_classes.canvas import (
|
|
4
5
|
IndustrialCanvas,
|
|
@@ -6,7 +7,7 @@ from cognite_toolkit._cdf_tk.client.data_classes.canvas import (
|
|
|
6
7
|
)
|
|
7
8
|
from cognite_toolkit._cdf_tk.client.data_classes.charts import Chart, ChartList, ChartWrite
|
|
8
9
|
from cognite_toolkit._cdf_tk.exceptions import ToolkitNotImplementedError
|
|
9
|
-
from cognite_toolkit._cdf_tk.tk_warnings import MediumSeverityWarning
|
|
10
|
+
from cognite_toolkit._cdf_tk.tk_warnings import HighSeverityWarning, MediumSeverityWarning
|
|
10
11
|
from cognite_toolkit._cdf_tk.utils.collection import chunker_sequence
|
|
11
12
|
from cognite_toolkit._cdf_tk.utils.http_client import HTTPClient, HTTPMessage, SimpleBodyRequest
|
|
12
13
|
from cognite_toolkit._cdf_tk.utils.useful_types import JsonVal
|
|
@@ -218,17 +219,22 @@ class CanvasIO(UploadableStorageIO[CanvasSelector, IndustrialCanvas, IndustrialC
|
|
|
218
219
|
references = dumped.get("containerReferences", [])
|
|
219
220
|
if not isinstance(references, list):
|
|
220
221
|
return dumped
|
|
222
|
+
new_container_references: list[Any] = []
|
|
221
223
|
for container_ref in references:
|
|
222
224
|
if not isinstance(container_ref, dict):
|
|
225
|
+
new_container_references.append(container_ref)
|
|
223
226
|
continue
|
|
224
227
|
sources = container_ref.get("sources", [])
|
|
225
228
|
if not isinstance(sources, list) or len(sources) == 0:
|
|
229
|
+
new_container_references.append(container_ref)
|
|
226
230
|
continue
|
|
227
231
|
source = sources[0]
|
|
228
232
|
if not isinstance(source, dict) or "properties" not in source:
|
|
233
|
+
new_container_references.append(container_ref)
|
|
229
234
|
continue
|
|
230
235
|
properties = source["properties"]
|
|
231
236
|
if not isinstance(properties, dict):
|
|
237
|
+
new_container_references.append(container_ref)
|
|
232
238
|
continue
|
|
233
239
|
reference_type = properties.get("containerReferenceType")
|
|
234
240
|
if (
|
|
@@ -238,9 +244,13 @@ class CanvasIO(UploadableStorageIO[CanvasSelector, IndustrialCanvas, IndustrialC
|
|
|
238
244
|
"dataGrid",
|
|
239
245
|
}
|
|
240
246
|
): # These container reference types are special cases with a resourceId statically set to -1, which is why we skip them
|
|
247
|
+
new_container_references.append(container_ref)
|
|
241
248
|
continue
|
|
242
249
|
resource_id = properties.pop("resourceId", None)
|
|
243
250
|
if not isinstance(resource_id, int):
|
|
251
|
+
HighSeverityWarning(
|
|
252
|
+
f"Invalid resourceId {resource_id!r} in Canvas {canvas.canvas.name}. Skipping."
|
|
253
|
+
).print_warning(console=self.client.console)
|
|
244
254
|
continue
|
|
245
255
|
if reference_type == "asset":
|
|
246
256
|
external_id = self.client.lookup.assets.external_id(resource_id)
|
|
@@ -251,9 +261,16 @@ class CanvasIO(UploadableStorageIO[CanvasSelector, IndustrialCanvas, IndustrialC
|
|
|
251
261
|
elif reference_type == "file":
|
|
252
262
|
external_id = self.client.lookup.files.external_id(resource_id)
|
|
253
263
|
else:
|
|
264
|
+
new_container_references.append(container_ref)
|
|
254
265
|
continue
|
|
255
|
-
if external_id is
|
|
256
|
-
|
|
266
|
+
if external_id is None:
|
|
267
|
+
HighSeverityWarning(
|
|
268
|
+
f"Failed to look-up {reference_type} external ID for resource ID {resource_id!r}. Skipping resource in Canvas {canvas.canvas.name}"
|
|
269
|
+
).print_warning(console=self.client.console)
|
|
270
|
+
continue
|
|
271
|
+
properties["resourceExternalId"] = external_id
|
|
272
|
+
new_container_references.append(container_ref)
|
|
273
|
+
dumped["containerReferences"] = new_container_references
|
|
257
274
|
return dumped
|
|
258
275
|
|
|
259
276
|
def json_chunk_to_data(
|
|
@@ -312,23 +329,30 @@ class CanvasIO(UploadableStorageIO[CanvasSelector, IndustrialCanvas, IndustrialC
|
|
|
312
329
|
return self._load_resource(item_json)
|
|
313
330
|
|
|
314
331
|
def _load_resource(self, item_json: dict[str, JsonVal]) -> IndustrialCanvasApply:
|
|
332
|
+
name = self._get_name(item_json)
|
|
315
333
|
references = item_json.get("containerReferences", [])
|
|
316
334
|
if not isinstance(references, list):
|
|
317
335
|
return IndustrialCanvasApply._load(item_json)
|
|
336
|
+
new_container_references: list[Any] = []
|
|
318
337
|
for container_ref in references:
|
|
319
338
|
if not isinstance(container_ref, dict):
|
|
339
|
+
new_container_references.append(container_ref)
|
|
320
340
|
continue
|
|
321
341
|
sources = container_ref.get("sources", [])
|
|
322
342
|
if not isinstance(sources, list) or len(sources) == 0:
|
|
343
|
+
new_container_references.append(container_ref)
|
|
323
344
|
continue
|
|
324
345
|
source = sources[0]
|
|
325
346
|
if not isinstance(source, dict) or "properties" not in source:
|
|
347
|
+
new_container_references.append(container_ref)
|
|
326
348
|
continue
|
|
327
349
|
properties = source["properties"]
|
|
328
350
|
if not isinstance(properties, dict):
|
|
351
|
+
new_container_references.append(container_ref)
|
|
329
352
|
continue
|
|
330
353
|
resource_external_id = properties.pop("resourceExternalId", None)
|
|
331
354
|
if not isinstance(resource_external_id, str):
|
|
355
|
+
new_container_references.append(container_ref)
|
|
332
356
|
continue
|
|
333
357
|
reference_type = properties.get("containerReferenceType")
|
|
334
358
|
if reference_type == "asset":
|
|
@@ -340,8 +364,24 @@ class CanvasIO(UploadableStorageIO[CanvasSelector, IndustrialCanvas, IndustrialC
|
|
|
340
364
|
elif reference_type == "file":
|
|
341
365
|
resource_id = self.client.lookup.files.id(resource_external_id)
|
|
342
366
|
else:
|
|
367
|
+
new_container_references.append(container_ref)
|
|
343
368
|
continue
|
|
344
|
-
if resource_id is
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
369
|
+
if resource_id is None:
|
|
370
|
+
# Failed look-up, skip the resourceId setting
|
|
371
|
+
HighSeverityWarning(
|
|
372
|
+
f"Failed to look-up {reference_type} ID for external ID {resource_external_id!r}. Skipping resource in Canvas {name}"
|
|
373
|
+
).print_warning(console=self.client.console)
|
|
374
|
+
continue
|
|
375
|
+
properties["resourceId"] = resource_id
|
|
376
|
+
new_container_references.append(container_ref)
|
|
377
|
+
new_item = dict(item_json)
|
|
378
|
+
new_item["containerReferences"] = new_container_references
|
|
379
|
+
|
|
380
|
+
return IndustrialCanvasApply._load(new_item)
|
|
381
|
+
|
|
382
|
+
@classmethod
|
|
383
|
+
def _get_name(cls, item_json: dict[str, JsonVal]) -> str:
|
|
384
|
+
try:
|
|
385
|
+
return item_json["canvas"]["sources"][0]["properties"]["name"] # type: ignore[index,return-value, call-overload]
|
|
386
|
+
except (KeyError, IndexError, TypeError):
|
|
387
|
+
return "<unknown>"
|
cognite_toolkit/_version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.7.
|
|
1
|
+
__version__ = "0.7.23"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cognite_toolkit
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.23
|
|
4
4
|
Summary: Official Cognite Data Fusion tool for project templates and configuration deployment
|
|
5
5
|
Project-URL: Homepage, https://docs.cognite.com/cdf/deploy/cdf_toolkit/
|
|
6
6
|
Project-URL: Changelog, https://github.com/cognitedata/toolkit/releases
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
cognite_toolkit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
cognite_toolkit/_cdf.py,sha256=sefGD2JQuOTBZhEqSj_ECbNZ7nTRN4AwGwX1pSUhoow,5636
|
|
3
|
-
cognite_toolkit/_version.py,sha256=
|
|
3
|
+
cognite_toolkit/_version.py,sha256=JGnAqfJascCxCeW2HUmSEq-6cTv1v4JA85VtarqlsUk,23
|
|
4
4
|
cognite_toolkit/config.dev.yaml,sha256=M33FiIKdS3XKif-9vXniQ444GTZ-bLXV8aFH86u9iUQ,332
|
|
5
5
|
cognite_toolkit/_cdf_tk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
cognite_toolkit/_cdf_tk/cdf_toml.py,sha256=VSWV9h44HusWIaKpWgjrOMrc3hDoPTTXBXlp6-NOrIM,9079
|
|
@@ -216,7 +216,7 @@ cognite_toolkit/_cdf_tk/resource_classes/infield_v1.py,sha256=XtstgUuhYhWgsxSoQ9
|
|
|
216
216
|
cognite_toolkit/_cdf_tk/resource_classes/instance.py,sha256=FdPCDz4LlKZ2SDBGH2-z-JiPN0V53Gg3FrxxjcjrJZc,2935
|
|
217
217
|
cognite_toolkit/_cdf_tk/resource_classes/labels.py,sha256=rh4SV_MBEiS9cjpz1g4_0SAnKGwiIepThD_wR1_bMkY,649
|
|
218
218
|
cognite_toolkit/_cdf_tk/resource_classes/location.py,sha256=C4vhHs_kpLa3abfQIZiotfldnKoEq8YAbU3gvG7XDMA,3221
|
|
219
|
-
cognite_toolkit/_cdf_tk/resource_classes/migration.py,sha256=
|
|
219
|
+
cognite_toolkit/_cdf_tk/resource_classes/migration.py,sha256=ThMKmJSaMx9DKtqkwcY2Y_Y4hY0xk-UzyF7HC49qlnA,903
|
|
220
220
|
cognite_toolkit/_cdf_tk/resource_classes/raw_database_table.py,sha256=2It1o8-zsH1YMCXTnI_KMjjnuN4bnZ_2PS3ZyBUrh0I,538
|
|
221
221
|
cognite_toolkit/_cdf_tk/resource_classes/relationship.py,sha256=tZQvy_ofmxSry0e9BITKOcB-L8fNocQBl56BJjAgThc,2074
|
|
222
222
|
cognite_toolkit/_cdf_tk/resource_classes/search_config.py,sha256=KhHLKs6-tljU7tYaCc2u3qyHXbNDqCXI3OmntSsKW8E,837
|
|
@@ -244,7 +244,7 @@ cognite_toolkit/_cdf_tk/resource_classes/robotics/location.py,sha256=dbc9HT-bc2Q
|
|
|
244
244
|
cognite_toolkit/_cdf_tk/resource_classes/robotics/map.py,sha256=j77z7CzCMiMj8r94BdUKCum9EuZRUjaSlUAy9K9DL_Q,942
|
|
245
245
|
cognite_toolkit/_cdf_tk/storageio/__init__.py,sha256=h5Wr4i7zNIgsslrsRJxmp7ls4bNRKl0uZzQ7GLRMP7g,1920
|
|
246
246
|
cognite_toolkit/_cdf_tk/storageio/_annotations.py,sha256=JI_g18_Y9S7pbc9gm6dZMyo3Z-bCndJXF9C2lOva0bQ,4848
|
|
247
|
-
cognite_toolkit/_cdf_tk/storageio/_applications.py,sha256=
|
|
247
|
+
cognite_toolkit/_cdf_tk/storageio/_applications.py,sha256=ozWeuTqay1_GSFuQZUxXJspsBhLEBIS7EksAi93B8_4,18722
|
|
248
248
|
cognite_toolkit/_cdf_tk/storageio/_asset_centric.py,sha256=TirKLSNPoLqKjczsw0djWAsR0VvopwmU23aUxrBOJN8,32464
|
|
249
249
|
cognite_toolkit/_cdf_tk/storageio/_base.py,sha256=ElvqhIEBnhcz0yY1Ds164wVN0_7CFNK-uT0-z7LcR9U,13067
|
|
250
250
|
cognite_toolkit/_cdf_tk/storageio/_data_classes.py,sha256=s3TH04BJ1q7rXndRhEbVMEnoOXjxrGg4n-w9Z5uUL-o,3480
|
|
@@ -305,13 +305,13 @@ cognite_toolkit/_repo_files/.gitignore,sha256=ip9kf9tcC5OguF4YF4JFEApnKYw0nG0vPi
|
|
|
305
305
|
cognite_toolkit/_repo_files/AzureDevOps/.devops/README.md,sha256=OLA0D7yCX2tACpzvkA0IfkgQ4_swSd-OlJ1tYcTBpsA,240
|
|
306
306
|
cognite_toolkit/_repo_files/AzureDevOps/.devops/deploy-pipeline.yml,sha256=brULcs8joAeBC_w_aoWjDDUHs3JheLMIR9ajPUK96nc,693
|
|
307
307
|
cognite_toolkit/_repo_files/AzureDevOps/.devops/dry-run-pipeline.yml,sha256=OBFDhFWK1mlT4Dc6mDUE2Es834l8sAlYG50-5RxRtHk,723
|
|
308
|
-
cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml,sha256=
|
|
309
|
-
cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml,sha256=
|
|
310
|
-
cognite_toolkit/_resources/cdf.toml,sha256=
|
|
308
|
+
cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml,sha256=9OAOoiEnbwN-vEuPQmI59u7_5bHwKKgJVd2b3wmXZZU,667
|
|
309
|
+
cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml,sha256=vVpoAsIznpwy42v_665Hg5E5N6pbI0i0Q8vQDjHCBeg,2430
|
|
310
|
+
cognite_toolkit/_resources/cdf.toml,sha256=rDE7YGIeaEnxBZX8qUEFV8gr-Gh8wq8YArsxlDEPjIQ,475
|
|
311
311
|
cognite_toolkit/demo/__init__.py,sha256=-m1JoUiwRhNCL18eJ6t7fZOL7RPfowhCuqhYFtLgrss,72
|
|
312
312
|
cognite_toolkit/demo/_base.py,sha256=6xKBUQpXZXGQ3fJ5f7nj7oT0s2n7OTAGIa17ZlKHZ5U,8052
|
|
313
|
-
cognite_toolkit-0.7.
|
|
314
|
-
cognite_toolkit-0.7.
|
|
315
|
-
cognite_toolkit-0.7.
|
|
316
|
-
cognite_toolkit-0.7.
|
|
317
|
-
cognite_toolkit-0.7.
|
|
313
|
+
cognite_toolkit-0.7.23.dist-info/METADATA,sha256=nbev1eMp2ATVbkZUvRaDAlUsUOj5-KKDSdANwZ0gsK4,4501
|
|
314
|
+
cognite_toolkit-0.7.23.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
315
|
+
cognite_toolkit-0.7.23.dist-info/entry_points.txt,sha256=JlR7MH1_UMogC3QOyN4-1l36VbrCX9xUdQoHGkuJ6-4,83
|
|
316
|
+
cognite_toolkit-0.7.23.dist-info/licenses/LICENSE,sha256=CW0DRcx5tL-pCxLEN7ts2S9g2sLRAsWgHVEX4SN9_Mc,752
|
|
317
|
+
cognite_toolkit-0.7.23.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|