cognite-toolkit 0.6.92__py3-none-any.whl → 0.6.93__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.

Potentially problematic release.


This version of cognite-toolkit might be problematic. Click here for more details.

@@ -9,7 +9,14 @@ from rich.console import Console
9
9
  from cognite_toolkit._cdf_tk.client import ToolkitClient
10
10
  from cognite_toolkit._cdf_tk.constants import DATA_MANIFEST_STEM, DATA_RESOURCE_DIR
11
11
  from cognite_toolkit._cdf_tk.exceptions import ToolkitValueError
12
- from cognite_toolkit._cdf_tk.storageio import T_Selector, UploadableStorageIO, are_same_kind, get_upload_io
12
+ from cognite_toolkit._cdf_tk.storageio import (
13
+ AssetFileReaderAdapter,
14
+ AssetIO,
15
+ T_Selector,
16
+ UploadableStorageIO,
17
+ are_same_kind,
18
+ get_upload_io,
19
+ )
13
20
  from cognite_toolkit._cdf_tk.storageio._base import T_WriteCogniteResource, TableUploadableStorageIO, UploadItem
14
21
  from cognite_toolkit._cdf_tk.storageio.selectors import Selector, SelectorAdapter
15
22
  from cognite_toolkit._cdf_tk.tk_warnings import HighSeverityWarning, MediumSeverityWarning
@@ -182,11 +189,18 @@ class UploadCommand(ToolkitCommand):
182
189
  is_table = reader.format in TABLE_READ_CLS_BY_FORMAT
183
190
  if is_table and not isinstance(io, TableUploadableStorageIO):
184
191
  raise ToolkitValueError(f"{selector.display_name} does not support {reader.format!r} files.")
192
+ if isinstance(io, AssetIO):
193
+ # Assets needs to be uploaded from the root asset to the leaves. The specialized reader
194
+ # handles this by iterating over the file n times, where n is the depth of the asset hierarchy.
195
+ reader = AssetFileReaderAdapter(reader)
185
196
  tracker = ProgressTracker[str]([self._UPLOAD])
186
197
  data_name = "row" if is_table else "line"
187
198
  executor = ProducerWorkerExecutor[list[tuple[str, dict[str, JsonVal]]], Sequence[UploadItem]](
188
199
  download_iterable=chunker(
189
- ((f"{data_name} {line_no}", item) for line_no, item in enumerate(reader.read_chunks(), 1)),
200
+ (
201
+ (f"{data_name} {line_no}", item)
202
+ for line_no, item in reader.read_chunks_with_line_numbers()
203
+ ),
190
204
  io.CHUNK_SIZE,
191
205
  ),
192
206
  process=partial(io.rows_to_data, selector=selector)
@@ -5,7 +5,15 @@ from cognite_toolkit._cdf_tk.utils.fileio import COMPRESSION_BY_SUFFIX
5
5
 
6
6
  from ._annotations import FileAnnotationIO
7
7
  from ._applications import CanvasIO, ChartIO
8
- from ._asset_centric import AssetIO, BaseAssetCentricIO, EventIO, FileMetadataIO, HierarchyIO, TimeSeriesIO
8
+ from ._asset_centric import (
9
+ AssetFileReaderAdapter,
10
+ AssetIO,
11
+ BaseAssetCentricIO,
12
+ EventIO,
13
+ FileMetadataIO,
14
+ HierarchyIO,
15
+ TimeSeriesIO,
16
+ )
9
17
  from ._base import (
10
18
  ConfigurableStorageIO,
11
19
  Page,
@@ -45,6 +53,7 @@ def are_same_kind(kind: str, kind_or_path: str | Path, /) -> bool:
45
53
 
46
54
 
47
55
  __all__ = [
56
+ "AssetFileReaderAdapter",
48
57
  "AssetIO",
49
58
  "BaseAssetCentricIO",
50
59
  "CanvasIO",
@@ -1,6 +1,7 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from collections import defaultdict
3
- from collections.abc import Iterable, MutableSequence, Sequence
3
+ from collections.abc import Iterable, Iterator, MutableSequence, Sequence
4
+ from io import TextIOWrapper
4
5
  from typing import ClassVar, Generic
5
6
 
6
7
  from cognite.client.data_classes import (
@@ -48,7 +49,7 @@ from cognite_toolkit._cdf_tk.utils.aggregators import (
48
49
  TimeSeriesAggregator,
49
50
  )
50
51
  from cognite_toolkit._cdf_tk.utils.cdf import metadata_key_counts
51
- from cognite_toolkit._cdf_tk.utils.fileio import SchemaColumn
52
+ from cognite_toolkit._cdf_tk.utils.fileio import FileReader, SchemaColumn
52
53
  from cognite_toolkit._cdf_tk.utils.http_client import (
53
54
  FailedRequestItems,
54
55
  FailedRequestMessage,
@@ -639,3 +640,44 @@ class HierarchyIO(ConfigurableStorageIO[AssetCentricSelector, AssetCentricResour
639
640
 
640
641
  def get_resource_io(self, kind: str) -> BaseAssetCentricIO:
641
642
  return self._io_by_kind[kind]
643
+
644
+
645
+ class AssetFileReaderAdapter(FileReader):
646
+ """Adapter of the FileReader to read asset-centric data.
647
+
648
+ This is used when uploading assets from files to account for the hierarchical structure. It returns the assets
649
+ by the depth in the hierarchy, starting from the root assets and going down to the leaf assets.
650
+
651
+ Args:
652
+ other_reader (FileReader): The underlying FileReader to read data from.
653
+ """
654
+
655
+ def __init__(self, other_reader: FileReader) -> None:
656
+ super().__init__(other_reader.input_file)
657
+ self._other_reader = other_reader
658
+
659
+ def read_chunks(self) -> Iterator[dict[str, JsonVal]]:
660
+ """Reads chunks from the file, yielding each chunk, sorted by asset depth."""
661
+ yield from (item for _, item in self.read_chunks_with_line_numbers())
662
+
663
+ def read_chunks_with_line_numbers(self) -> Iterator[tuple[int, dict[str, JsonVal]]]:
664
+ current_depth = max_depth = 0
665
+ while current_depth <= max_depth:
666
+ for line_number, item in self._other_reader.read_chunks_with_line_numbers():
667
+ try:
668
+ depth = int(item.get("depth")) # type: ignore[arg-type]
669
+ except (TypeError, ValueError):
670
+ if current_depth == 0:
671
+ # If depth is not set, we yield it at depth 0
672
+ yield line_number, item
673
+ continue
674
+ if depth == current_depth:
675
+ yield line_number, item
676
+ elif current_depth == 0:
677
+ max_depth = max(max_depth, depth)
678
+ current_depth += 1
679
+
680
+ def _read_chunks_from_file(self, file: TextIOWrapper) -> Iterator[dict[str, JsonVal]]:
681
+ # This method is not used by AssetFileReaderAdapter as read_chunks is overridden.
682
+ # It is implemented to satisfy the abstract base class, but should not be called.
683
+ raise NotImplementedError(f"{type(self).__name__} does not implement '_read_chunks_from_file'.")
@@ -30,6 +30,10 @@ class FileReader(FileIO, ABC):
30
30
  with compression.open("r") as file:
31
31
  yield from self._read_chunks_from_file(file)
32
32
 
33
+ def read_chunks_with_line_numbers(self) -> Iterator[tuple[int, dict[str, JsonVal]]]:
34
+ """Read chunks from the file, yielding each chunk with its corresponding line number."""
35
+ yield from enumerate(self.read_chunks(), start=1)
36
+
33
37
  @abstractmethod
34
38
  def _read_chunks_from_file(self, file: TextIOWrapper) -> Iterator[dict[str, JsonVal]]:
35
39
  """Read chunks from the file."""
@@ -12,7 +12,7 @@ jobs:
12
12
  environment: dev
13
13
  name: Deploy
14
14
  container:
15
- image: cognite/toolkit:0.6.92
15
+ image: cognite/toolkit:0.6.93
16
16
  env:
17
17
  CDF_CLUSTER: ${{ vars.CDF_CLUSTER }}
18
18
  CDF_PROJECT: ${{ vars.CDF_PROJECT }}
@@ -10,7 +10,7 @@ jobs:
10
10
  environment: dev
11
11
  name: Deploy Dry Run
12
12
  container:
13
- image: cognite/toolkit:0.6.92
13
+ image: cognite/toolkit:0.6.93
14
14
  env:
15
15
  CDF_CLUSTER: ${{ vars.CDF_CLUSTER }}
16
16
  CDF_PROJECT: ${{ vars.CDF_PROJECT }}
@@ -4,7 +4,7 @@ default_env = "<DEFAULT_ENV_PLACEHOLDER>"
4
4
  [modules]
5
5
  # This is the version of the modules. It should not be changed manually.
6
6
  # It will be updated by the 'cdf modules upgrade' command.
7
- version = "0.6.92"
7
+ version = "0.6.93"
8
8
 
9
9
  [alpha_flags]
10
10
  external-libraries = true
@@ -1 +1 @@
1
- __version__ = "0.6.92"
1
+ __version__ = "0.6.93"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cognite_toolkit
3
- Version: 0.6.92
3
+ Version: 0.6.93
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=1OSAvbOeuIrnsczEG2BtGqRP3L3sq0VMPthmugnqCUw,5821
3
- cognite_toolkit/_version.py,sha256=YZ7t39hsVsYWfIrytObsq9bNDMC8cNjBCtEcAsIIKtA,23
3
+ cognite_toolkit/_version.py,sha256=mhDTOECXK-iUdY0_1-p2mAdb1w2FkaLj3EepXd5qWHI,23
4
4
  cognite_toolkit/_cdf_tk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  cognite_toolkit/_cdf_tk/cdf_toml.py,sha256=IjmzNVLxsOV6tsMDgmJmXsy-LQru-8IEQdFzGW5DxVk,8117
6
6
  cognite_toolkit/_cdf_tk/constants.py,sha256=e9XmGvQCqGq7zYQrNoopU5e2KnYZYBPyUC5raGShK7k,6364
@@ -104,7 +104,7 @@ cognite_toolkit/_cdf_tk/commands/_cli_commands.py,sha256=TK6U_rm6VZT_V941kTyHMou
104
104
  cognite_toolkit/_cdf_tk/commands/_download.py,sha256=OBKPM_HGGA1i32th1SAgkQM_81CUFvm39kGqBuOeeTs,6816
105
105
  cognite_toolkit/_cdf_tk/commands/_profile.py,sha256=_4iX3AHAI6eLmRVUlWXCSvVHx1BZW2yDr_i2i9ECg6U,43120
106
106
  cognite_toolkit/_cdf_tk/commands/_purge.py,sha256=RadQHsmkPez3fZ5HCP9b82o2_fBx8P_-bTo7prkvWXU,32525
107
- cognite_toolkit/_cdf_tk/commands/_upload.py,sha256=Y0k0q4Iu4F7g3Ax3slSrpll3AHxmODYNq55waHw4mzc,12473
107
+ cognite_toolkit/_cdf_tk/commands/_upload.py,sha256=iJ5GILjYJfU_vVu-ie8CExxF0rKaZPN0sQ-JcC42JW4,12977
108
108
  cognite_toolkit/_cdf_tk/commands/_utils.py,sha256=UxMJW5QYKts4om5n6x2Tq2ihvfO9gWjhQKeqZNFTlKg,402
109
109
  cognite_toolkit/_cdf_tk/commands/_virtual_env.py,sha256=GFAid4hplixmj9_HkcXqU5yCLj-fTXm4cloGD6U2swY,2180
110
110
  cognite_toolkit/_cdf_tk/commands/auth.py,sha256=N6JgtF0_Qoh-xM8VlBb_IK1n0Lo5I7bIkIHmXm1l7ug,31638
@@ -232,10 +232,10 @@ cognite_toolkit/_cdf_tk/resource_classes/robotics/data_postprocessing.py,sha256=
232
232
  cognite_toolkit/_cdf_tk/resource_classes/robotics/frame.py,sha256=XmDqJ0pAxe_vAP0Dhktba1f9o2zg_ORCJ3Hz8cyJMrk,899
233
233
  cognite_toolkit/_cdf_tk/resource_classes/robotics/location.py,sha256=dbc9HT-bc2Qt15hHoR63SM7pg321BhNuTNjI7HHCwSA,468
234
234
  cognite_toolkit/_cdf_tk/resource_classes/robotics/map.py,sha256=j77z7CzCMiMj8r94BdUKCum9EuZRUjaSlUAy9K9DL_Q,942
235
- cognite_toolkit/_cdf_tk/storageio/__init__.py,sha256=-OhPPhl9z1ynYcFlRVYfOPD246HhQydmn4VzByJh7C0,2355
235
+ cognite_toolkit/_cdf_tk/storageio/__init__.py,sha256=Vx9E1glHeQJ8NzL30uphBvgs-toTjzeBNU72ewr0WHU,2442
236
236
  cognite_toolkit/_cdf_tk/storageio/_annotations.py,sha256=wAMkgM-IpgXuY7_1KbtiTv8VdA555ywKjntD_boOBPk,4647
237
237
  cognite_toolkit/_cdf_tk/storageio/_applications.py,sha256=bhyG1d2_9duPkX-otC2brVcpChvdXSPkYhBHS5T_72g,4343
238
- cognite_toolkit/_cdf_tk/storageio/_asset_centric.py,sha256=taxMxR2uBsCUsaproukSZxYEtly2sy2aZqPhI_-zhPA,28896
238
+ cognite_toolkit/_cdf_tk/storageio/_asset_centric.py,sha256=heh1rlrVnBhnfR_6DijdotoJC7l6_jhAGHhV5-X3nAc,30927
239
239
  cognite_toolkit/_cdf_tk/storageio/_base.py,sha256=NWXPdgzUnpBiav5Hi8XGHkWU9QiMjNzBQTxMcuxF-LA,11017
240
240
  cognite_toolkit/_cdf_tk/storageio/_data_classes.py,sha256=s3TH04BJ1q7rXndRhEbVMEnoOXjxrGg4n-w9Z5uUL-o,3480
241
241
  cognite_toolkit/_cdf_tk/storageio/_instances.py,sha256=_tKOdlo7tMJoh7y-47o7sySfDMRa-G-AFVprmzjn3EQ,9311
@@ -280,7 +280,7 @@ cognite_toolkit/_cdf_tk/utils/validate_access.py,sha256=1puswcpgEDNCwdk91dhLqCBS
280
280
  cognite_toolkit/_cdf_tk/utils/fileio/__init__.py,sha256=ts5kYu_1Ks7xjnM6pIrVUrZe0nkYI6euYXeE4ox34xk,1199
281
281
  cognite_toolkit/_cdf_tk/utils/fileio/_base.py,sha256=MpWaD3lR9vrJ-kGzTiDOtChXhvFD7-xrP-Pzp7vjnLY,756
282
282
  cognite_toolkit/_cdf_tk/utils/fileio/_compression.py,sha256=8BAPgg5OKc3vkEEkqOvYsuyh12iXVNuEmC0omWwyJNQ,2355
283
- cognite_toolkit/_cdf_tk/utils/fileio/_readers.py,sha256=nGfsSfpXDYUncncsFuJD9-xYPJ5635mSFUJfuCyQ3no,13724
283
+ cognite_toolkit/_cdf_tk/utils/fileio/_readers.py,sha256=mBf0-8JFwLfyTGJH8nWpbn89VPTj9UwP3GmZtx8t3A4,13969
284
284
  cognite_toolkit/_cdf_tk/utils/fileio/_writers.py,sha256=ghNGBZjkISAlbxe8o5YWWloLXG9QKOtF_qGA9JkvYss,17712
285
285
  cognite_toolkit/_cdf_tk/utils/http_client/__init__.py,sha256=H1T-cyIoVaPL4MvN1IuG-cHgj-cqB7eszu2kIN939lw,813
286
286
  cognite_toolkit/_cdf_tk/utils/http_client/_client.py,sha256=sN1Sizxv_rAcOSRd-2lKSs0p-SO1rA4eHL8pHMTBx54,11018
@@ -292,13 +292,13 @@ cognite_toolkit/_repo_files/.gitignore,sha256=ip9kf9tcC5OguF4YF4JFEApnKYw0nG0vPi
292
292
  cognite_toolkit/_repo_files/AzureDevOps/.devops/README.md,sha256=OLA0D7yCX2tACpzvkA0IfkgQ4_swSd-OlJ1tYcTBpsA,240
293
293
  cognite_toolkit/_repo_files/AzureDevOps/.devops/deploy-pipeline.yml,sha256=brULcs8joAeBC_w_aoWjDDUHs3JheLMIR9ajPUK96nc,693
294
294
  cognite_toolkit/_repo_files/AzureDevOps/.devops/dry-run-pipeline.yml,sha256=OBFDhFWK1mlT4Dc6mDUE2Es834l8sAlYG50-5RxRtHk,723
295
- cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml,sha256=wEKwRNF7C9cq34yIaQjhQcIANNqWKVXwgESz25Mh8gs,667
296
- cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml,sha256=mV6glTAupf2E-Cci5C56kOG6_bGjGzX29hEpcAX1pJo,2430
297
- cognite_toolkit/_resources/cdf.toml,sha256=lvpWokDF_cDC9TVVer2bgMao9P--Hv0oJSpHl65OQ0Q,487
295
+ cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml,sha256=gGC7ISonjAKg43Y3dqlpKBrIgr8zpx8Qqy8Q1sWvyV8,667
296
+ cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml,sha256=GscUUdSipJkZhn3Q-sxqjm8aB7p65Mty10ZEjYBXgCY,2430
297
+ cognite_toolkit/_resources/cdf.toml,sha256=mXqc38IbnyCiBG9DXm7RHnIWxjFoEdqOy1h0oEiB-hk,487
298
298
  cognite_toolkit/demo/__init__.py,sha256=-m1JoUiwRhNCL18eJ6t7fZOL7RPfowhCuqhYFtLgrss,72
299
299
  cognite_toolkit/demo/_base.py,sha256=6xKBUQpXZXGQ3fJ5f7nj7oT0s2n7OTAGIa17ZlKHZ5U,8052
300
- cognite_toolkit-0.6.92.dist-info/METADATA,sha256=urDOVGuS1ZjJwkVHotxDnAmMSLASTfKRwuy_1ymxEu0,4501
301
- cognite_toolkit-0.6.92.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
302
- cognite_toolkit-0.6.92.dist-info/entry_points.txt,sha256=JlR7MH1_UMogC3QOyN4-1l36VbrCX9xUdQoHGkuJ6-4,83
303
- cognite_toolkit-0.6.92.dist-info/licenses/LICENSE,sha256=CW0DRcx5tL-pCxLEN7ts2S9g2sLRAsWgHVEX4SN9_Mc,752
304
- cognite_toolkit-0.6.92.dist-info/RECORD,,
300
+ cognite_toolkit-0.6.93.dist-info/METADATA,sha256=VXtoYqT3_e-jS49YiM4DwRVAW_2mqtJPGqwFskF6Ai0,4501
301
+ cognite_toolkit-0.6.93.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
302
+ cognite_toolkit-0.6.93.dist-info/entry_points.txt,sha256=JlR7MH1_UMogC3QOyN4-1l36VbrCX9xUdQoHGkuJ6-4,83
303
+ cognite_toolkit-0.6.93.dist-info/licenses/LICENSE,sha256=CW0DRcx5tL-pCxLEN7ts2S9g2sLRAsWgHVEX4SN9_Mc,752
304
+ cognite_toolkit-0.6.93.dist-info/RECORD,,