cognite-toolkit 0.6.106__py3-none-any.whl → 0.6.107__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.
@@ -4,6 +4,7 @@ from typing import Annotated, Any
4
4
 
5
5
  import questionary
6
6
  import typer
7
+ from cognite.client.data_classes import Annotation
7
8
  from cognite.client.data_classes.data_modeling import ContainerId
8
9
 
9
10
  from cognite_toolkit._cdf_tk.client import ToolkitClient
@@ -19,6 +20,7 @@ from cognite_toolkit._cdf_tk.commands._migrate.creators import (
19
20
  )
20
21
  from cognite_toolkit._cdf_tk.commands._migrate.data_mapper import AssetCentricMapper
21
22
  from cognite_toolkit._cdf_tk.commands._migrate.migration_io import (
23
+ AnnotationMigrationIO,
22
24
  AssetCentricMigrationIO,
23
25
  )
24
26
  from cognite_toolkit._cdf_tk.commands._migrate.selectors import (
@@ -31,6 +33,7 @@ from cognite_toolkit._cdf_tk.utils.cli_args import parse_view_str
31
33
  from cognite_toolkit._cdf_tk.utils.interactive_select import (
32
34
  AssetInteractiveSelect,
33
35
  DataModelingSelect,
36
+ FileMetadataInteractiveSelect,
34
37
  ResourceViewMappingInteractiveSelect,
35
38
  )
36
39
  from cognite_toolkit._cdf_tk.utils.useful_types import AssetCentricKind
@@ -49,6 +52,7 @@ class MigrateApp(typer.Typer):
49
52
  self.command("events")(self.events)
50
53
  self.command("timeseries")(self.timeseries)
51
54
  self.command("files")(self.files)
55
+ self.command("annotations")(self.annotations)
52
56
  self.command("canvas")(self.canvas)
53
57
  # Uncomment when infield v2 config migration is ready
54
58
  # self.command("infield-configs")(self.infield_configs)
@@ -694,6 +698,149 @@ class MigrateApp(typer.Typer):
694
698
  )
695
699
  )
696
700
 
701
+ @classmethod
702
+ def annotations(
703
+ cls,
704
+ ctx: typer.Context,
705
+ mapping_file: Annotated[
706
+ Path | None,
707
+ typer.Option(
708
+ "--mapping-file",
709
+ "-m",
710
+ help="Path to the mapping file that contains the mapping from Annotations to CogniteDiagramAnnotation. "
711
+ "This file is expected to have the following columns: [id, space, externalId, ingestionView].",
712
+ ),
713
+ ] = None,
714
+ data_set_id: Annotated[
715
+ str | None,
716
+ typer.Option(
717
+ "--data-set-id",
718
+ "-s",
719
+ help="The data set ID to select for the annotations to migrate. If not provided and the mapping file is not provided, "
720
+ "an interactive selection will be performed to select the data set to migrate annotations from.",
721
+ ),
722
+ ] = None,
723
+ instance_space: Annotated[
724
+ str | None,
725
+ typer.Option(
726
+ "--instance-space",
727
+ "-i",
728
+ help="The instance space to use for the migrated annotations. Required when using --data-set-id.",
729
+ ),
730
+ ] = None,
731
+ asset_annotation_mapping: Annotated[
732
+ str | None,
733
+ typer.Option(
734
+ "--asset-annotation-mapping",
735
+ "-a",
736
+ help="The ingestion mapping to use for asset-linked annotations. If not provided, "
737
+ "the default mapping (cdf_asset_annotations_mapping) will be used.",
738
+ ),
739
+ ] = None,
740
+ file_annotation_mapping: Annotated[
741
+ str | None,
742
+ typer.Option(
743
+ "--file-annotation-mapping",
744
+ "-f",
745
+ help="The ingestion mapping to use for file-linked annotations. If not provided, "
746
+ "the default mapping (cdf_file_annotations_mapping) will be used.",
747
+ ),
748
+ ] = None,
749
+ log_dir: Annotated[
750
+ Path,
751
+ typer.Option(
752
+ "--log-dir",
753
+ "-l",
754
+ help="Path to the directory where logs will be stored. If the directory does not exist, it will be created.",
755
+ ),
756
+ ] = Path(f"migration_logs_{TODAY!s}"),
757
+ dry_run: Annotated[
758
+ bool,
759
+ typer.Option(
760
+ "--dry-run",
761
+ "-d",
762
+ help="If set, the migration will not be executed, but only a report of what would be done is printed.",
763
+ ),
764
+ ] = False,
765
+ verbose: Annotated[
766
+ bool,
767
+ typer.Option(
768
+ "--verbose",
769
+ "-v",
770
+ help="Turn on to get more verbose output when running the command",
771
+ ),
772
+ ] = False,
773
+ ) -> None:
774
+ """Migrate Annotations to CogniteDiagramAnnotation edges in data modeling.
775
+
776
+ Annotations are diagram annotations that link assets or files to other resources. This command
777
+ migrates them to edges in the data modeling space, preserving the relationships and metadata.
778
+ """
779
+ client = EnvironmentVariables.create_from_environment().get_client()
780
+
781
+ if data_set_id is not None and mapping_file is not None:
782
+ raise typer.BadParameter("Cannot specify both data_set_id and mapping_file")
783
+ elif mapping_file is not None:
784
+ selected: AssetCentricMigrationSelector = MigrationCSVFileSelector(
785
+ datafile=mapping_file, kind="Annotations"
786
+ )
787
+ annotation_io = AnnotationMigrationIO(client)
788
+ elif data_set_id is not None:
789
+ if instance_space is None:
790
+ raise typer.BadParameter("--instance-space is required when using --data-set-id")
791
+ selected = MigrateDataSetSelector(data_set_external_id=data_set_id, kind="Annotations")
792
+ annotation_io = AnnotationMigrationIO(
793
+ client,
794
+ instance_space=instance_space,
795
+ default_asset_annotation_mapping=asset_annotation_mapping,
796
+ default_file_annotation_mapping=file_annotation_mapping,
797
+ )
798
+ else:
799
+ # Interactive selection
800
+ selector = FileMetadataInteractiveSelect(client, "migrate")
801
+ selected_data_set_id = selector.select_data_set(allow_empty=False)
802
+ dm_selector = DataModelingSelect(client, "migrate")
803
+ selected_instance_space = dm_selector.select_instance_space(
804
+ multiselect=False,
805
+ message="In which instance space do you want to create the annotations?",
806
+ include_empty=True,
807
+ )
808
+ if selected_instance_space is None:
809
+ raise typer.Abort()
810
+ asset_annotations_selector = ResourceViewMappingInteractiveSelect(client, "migrate asset annotations")
811
+ asset_annotation_mapping = asset_annotations_selector.select_resource_view_mapping(
812
+ resource_type="assetAnnotation",
813
+ ).external_id
814
+ file_annotations_selector = ResourceViewMappingInteractiveSelect(client, "migrate file annotations")
815
+ file_annotation_mapping = file_annotations_selector.select_resource_view_mapping(
816
+ resource_type="fileAnnotation",
817
+ ).external_id
818
+
819
+ selected = MigrateDataSetSelector(data_set_external_id=selected_data_set_id, kind="Annotations")
820
+ annotation_io = AnnotationMigrationIO(
821
+ client,
822
+ instance_space=selected_instance_space,
823
+ default_asset_annotation_mapping=asset_annotation_mapping,
824
+ default_file_annotation_mapping=file_annotation_mapping,
825
+ )
826
+
827
+ dry_run = questionary.confirm("Do you want to perform a dry run?", default=dry_run).ask()
828
+ verbose = questionary.confirm("Do you want verbose output?", default=verbose).ask()
829
+ if any(res is None for res in [dry_run, verbose]):
830
+ raise typer.Abort()
831
+
832
+ cmd = MigrationCommand()
833
+ cmd.run(
834
+ lambda: cmd.migrate(
835
+ selected=selected,
836
+ data=annotation_io,
837
+ mapper=AssetCentricMapper[Annotation](client),
838
+ log_dir=log_dir,
839
+ dry_run=dry_run,
840
+ verbose=verbose,
841
+ )
842
+ )
843
+
697
844
  @staticmethod
698
845
  def canvas(
699
846
  ctx: typer.Context,
@@ -25,7 +25,7 @@ from cognite_toolkit._cdf_tk.exceptions import ToolkitValueError
25
25
  from cognite_toolkit._cdf_tk.storageio._base import T_Selector, T_WriteCogniteResource
26
26
  from cognite_toolkit._cdf_tk.utils import humanize_collection
27
27
  from cognite_toolkit._cdf_tk.utils.useful_types import (
28
- T_AssetCentricResource,
28
+ T_AssetCentricResourceExtended,
29
29
  )
30
30
 
31
31
 
@@ -57,7 +57,7 @@ class DataMapper(Generic[T_Selector, T_CogniteResource, T_WriteCogniteResource],
57
57
 
58
58
 
59
59
  class AssetCentricMapper(
60
- DataMapper[AssetCentricMigrationSelector, AssetCentricMapping[T_AssetCentricResource], InstanceApply]
60
+ DataMapper[AssetCentricMigrationSelector, AssetCentricMapping[T_AssetCentricResourceExtended], InstanceApply]
61
61
  ):
62
62
  def __init__(self, client: ToolkitClient) -> None:
63
63
  self.client = client
@@ -87,7 +87,7 @@ class AssetCentricMapper(
87
87
  )
88
88
 
89
89
  def map(
90
- self, source: Sequence[AssetCentricMapping[T_AssetCentricResource]]
90
+ self, source: Sequence[AssetCentricMapping[T_AssetCentricResourceExtended]]
91
91
  ) -> Sequence[tuple[InstanceApply | None, ConversionIssue]]:
92
92
  """Map a chunk of asset-centric data to InstanceApplyList format."""
93
93
  # We update the direct relation cache in bulk for all resources in the chunk.
@@ -99,7 +99,7 @@ class AssetCentricMapper(
99
99
  return output
100
100
 
101
101
  def _map_single_item(
102
- self, item: AssetCentricMapping[T_AssetCentricResource]
102
+ self, item: AssetCentricMapping[T_AssetCentricResourceExtended]
103
103
  ) -> tuple[NodeApply | EdgeApply | None, ConversionIssue]:
104
104
  mapping = item.mapping
105
105
  ingestion_view = mapping.get_ingestion_view()
@@ -235,14 +235,14 @@ class AnnotationMigrationIO(
235
235
  self,
236
236
  client: ToolkitClient,
237
237
  instance_space: str | None = None,
238
- default_asset_annotation_mapping: str = ASSET_ANNOTATIONS_ID,
239
- default_file_annotation_mapping: str = FILE_ANNOTATIONS_ID,
238
+ default_asset_annotation_mapping: str | None = None,
239
+ default_file_annotation_mapping: str | None = None,
240
240
  ) -> None:
241
241
  super().__init__(client)
242
242
  self.annotation_io = AnnotationIO(client)
243
243
  self.instance_space = instance_space
244
- self.default_asset_annotation_mapping = default_asset_annotation_mapping
245
- self.default_file_annotation_mapping = default_file_annotation_mapping
244
+ self.default_asset_annotation_mapping = default_asset_annotation_mapping or ASSET_ANNOTATIONS_ID
245
+ self.default_file_annotation_mapping = default_file_annotation_mapping or FILE_ANNOTATIONS_ID
246
246
 
247
247
  def as_id(self, item: AssetCentricMapping[Annotation]) -> str:
248
248
  return f"Annotation_{item.mapping.id}"
@@ -12,7 +12,7 @@ jobs:
12
12
  environment: dev
13
13
  name: Deploy
14
14
  container:
15
- image: cognite/toolkit:0.6.106
15
+ image: cognite/toolkit:0.6.107
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.106
13
+ image: cognite/toolkit:0.6.107
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.106"
7
+ version = "0.6.107"
8
8
 
9
9
  [alpha_flags]
10
10
  external-libraries = true
@@ -1 +1 @@
1
- __version__ = "0.6.106"
1
+ __version__ = "0.6.107"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cognite_toolkit
3
- Version: 0.6.106
3
+ Version: 0.6.107
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=0abeQr1Tfk4lkGaoXyrnFC28wDSlR_8UGrh10noGduQ,6085
3
- cognite_toolkit/_version.py,sha256=Yr4MUMyngYF8CK8gD1i_5CFjzdbc9C-zEFAB5ViLDNk,24
3
+ cognite_toolkit/_version.py,sha256=lu-o5QGcXmrHU8tes3QjIxzRHr_63kClROn7Lrtlq6s,24
4
4
  cognite_toolkit/_cdf_tk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  cognite_toolkit/_cdf_tk/cdf_toml.py,sha256=VSWV9h44HusWIaKpWgjrOMrc3hDoPTTXBXlp6-NOrIM,9079
6
6
  cognite_toolkit/_cdf_tk/constants.py,sha256=Gi7iGGzdUrOnBeIK6ix3XiBieHIwzLJO5BWjDI3a6l4,7082
@@ -19,7 +19,7 @@ cognite_toolkit/_cdf_tk/apps/_dev_app.py,sha256=q8DBr4BAK33AwsHW3gAWZWSjSaQRuCis
19
19
  cognite_toolkit/_cdf_tk/apps/_download_app.py,sha256=Io7mW3DhYpLiDrqJfThSQThHDWrXN9c8huu9zYd0u7E,19408
20
20
  cognite_toolkit/_cdf_tk/apps/_dump_app.py,sha256=Ec0aEqbKwCkxni09i06rfY31qZUyOVwbbvo7MHh4cf8,39056
21
21
  cognite_toolkit/_cdf_tk/apps/_landing_app.py,sha256=HxzSln3fJXs5NzulfQGUMropXcwMobUYpyePrCrQTQs,1502
22
- cognite_toolkit/_cdf_tk/apps/_migrate_app.py,sha256=xkXo1h3eQ14D5uQ0qQdq01etS1FV_fg6ZnvxMt8H-os,30580
22
+ cognite_toolkit/_cdf_tk/apps/_migrate_app.py,sha256=JuzY1t5pkW94Dyygr-mT2lheluR7cL8AmD2MfaXhc8Y,37093
23
23
  cognite_toolkit/_cdf_tk/apps/_modules_app.py,sha256=95_H2zccRJl2mWn0oQ5mjCaEDnG63sPKOkB81IgWcIk,7637
24
24
  cognite_toolkit/_cdf_tk/apps/_profile_app.py,sha256=vSRJW54bEvIul8_4rOqyOYA7ztXx7TFOvZRZWZTxMbg,7007
25
25
  cognite_toolkit/_cdf_tk/apps/_purge.py,sha256=e8IgDK2Fib2u30l71Q2trbJ1az90zSLWr5TViTINmL0,15415
@@ -130,11 +130,11 @@ cognite_toolkit/_cdf_tk/commands/_migrate/command.py,sha256=jNoqqq81lbdfDTAQ5w2c
130
130
  cognite_toolkit/_cdf_tk/commands/_migrate/conversion.py,sha256=Ew9JRYrd-Ol9G9csTzpnhXAgCFnX67MwDYOTsdJLP3E,16803
131
131
  cognite_toolkit/_cdf_tk/commands/_migrate/creators.py,sha256=FTu7w3G8KyPY8pagG3KdPpOmpLcjehaAg2auEy6iM7A,9605
132
132
  cognite_toolkit/_cdf_tk/commands/_migrate/data_classes.py,sha256=_vMS_qAPj4yup1VnmmojPVigAZtyPQH7PM0Raby5tao,10619
133
- cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py,sha256=Q1K-zuRe04AyKHm8nYp5qVxB4eeHC0poKT3Ob1pNL-c,5646
133
+ cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py,sha256=Y7MrE6FGa15uvboBjNyWNlslsBv4FpeP5WsrFsooxsA,5678
134
134
  cognite_toolkit/_cdf_tk/commands/_migrate/data_model.py,sha256=i1eUsNX6Dueol9STIEwyksBnBsWUk13O8qHIjW964pM,7860
135
135
  cognite_toolkit/_cdf_tk/commands/_migrate/default_mappings.py,sha256=ERn3qFrJFXdtXaMjHq3Gk7MxH03MGFk3FrtWCOBJQts,5544
136
136
  cognite_toolkit/_cdf_tk/commands/_migrate/issues.py,sha256=lWSnuS3CfRDbA7i1g12gJ2reJnQcLmZWxHDK19-Wxkk,5772
137
- cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py,sha256=UtmfXMjajSM-oNu8ORNPCVnAHtZBmvT92i-ebYvuB-Q,16247
137
+ cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py,sha256=wrdBH5P6NgiZQSYLR0iJ3ZvqfQ5fY-_Ne2yKv9E1g4o,16277
138
138
  cognite_toolkit/_cdf_tk/commands/_migrate/prepare.py,sha256=RfqaNoso5CyBwc-p6ckwcYqBfZXKhdJgdGIyd0TATaI,2635
139
139
  cognite_toolkit/_cdf_tk/commands/_migrate/selectors.py,sha256=N1H_-rBpPUD6pbrlcofn1uEK1bA694EUXEe1zIXeqyo,2489
140
140
  cognite_toolkit/_cdf_tk/cruds/__init__.py,sha256=kxiB8gZo0Y4TyttWHGTLPCW5R1DUkN1uTZewTvaZRjo,6298
@@ -300,13 +300,13 @@ cognite_toolkit/_repo_files/.gitignore,sha256=ip9kf9tcC5OguF4YF4JFEApnKYw0nG0vPi
300
300
  cognite_toolkit/_repo_files/AzureDevOps/.devops/README.md,sha256=OLA0D7yCX2tACpzvkA0IfkgQ4_swSd-OlJ1tYcTBpsA,240
301
301
  cognite_toolkit/_repo_files/AzureDevOps/.devops/deploy-pipeline.yml,sha256=brULcs8joAeBC_w_aoWjDDUHs3JheLMIR9ajPUK96nc,693
302
302
  cognite_toolkit/_repo_files/AzureDevOps/.devops/dry-run-pipeline.yml,sha256=OBFDhFWK1mlT4Dc6mDUE2Es834l8sAlYG50-5RxRtHk,723
303
- cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml,sha256=1jeTnCHshDXK-_BpeGjx-DcYIyJXP4JobQOsrd1YdIg,668
304
- cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml,sha256=2uWDnr4F_8dy6F2dwTwae5_pkKMF9pUB4tMeV8BsN7Y,2431
305
- cognite_toolkit/_resources/cdf.toml,sha256=C8EeKYvi8E10kX1WeG0difC8zHWuFseZo4vy6-bt1rI,488
303
+ cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml,sha256=7ijoHGa5OFuDD3hYSllkChA4MU_iJgAnXmUX4sTlDkg,668
304
+ cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml,sha256=5yngla4gklkissfZ1vVMphWbfMfYmFs2gt3HnckqJrI,2431
305
+ cognite_toolkit/_resources/cdf.toml,sha256=CkbioMspsFNI5FwfptPthjPiQiln-5d7B6Tm1eWW_YY,488
306
306
  cognite_toolkit/demo/__init__.py,sha256=-m1JoUiwRhNCL18eJ6t7fZOL7RPfowhCuqhYFtLgrss,72
307
307
  cognite_toolkit/demo/_base.py,sha256=6xKBUQpXZXGQ3fJ5f7nj7oT0s2n7OTAGIa17ZlKHZ5U,8052
308
- cognite_toolkit-0.6.106.dist-info/METADATA,sha256=KvtAg2Al4AexHjxlR3MsdRVkqApWm7BWVxSbuQCdYI4,4502
309
- cognite_toolkit-0.6.106.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
310
- cognite_toolkit-0.6.106.dist-info/entry_points.txt,sha256=JlR7MH1_UMogC3QOyN4-1l36VbrCX9xUdQoHGkuJ6-4,83
311
- cognite_toolkit-0.6.106.dist-info/licenses/LICENSE,sha256=CW0DRcx5tL-pCxLEN7ts2S9g2sLRAsWgHVEX4SN9_Mc,752
312
- cognite_toolkit-0.6.106.dist-info/RECORD,,
308
+ cognite_toolkit-0.6.107.dist-info/METADATA,sha256=jKo4OnTtq7P4OwIRv8ku2Exp5ZlhakpRrUtmHwbYWKM,4502
309
+ cognite_toolkit-0.6.107.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
310
+ cognite_toolkit-0.6.107.dist-info/entry_points.txt,sha256=JlR7MH1_UMogC3QOyN4-1l36VbrCX9xUdQoHGkuJ6-4,83
311
+ cognite_toolkit-0.6.107.dist-info/licenses/LICENSE,sha256=CW0DRcx5tL-pCxLEN7ts2S9g2sLRAsWgHVEX4SN9_Mc,752
312
+ cognite_toolkit-0.6.107.dist-info/RECORD,,