cognite-toolkit 0.6.97__py3-none-any.whl → 0.7.30__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.
Files changed (136) hide show
  1. cognite_toolkit/_cdf.py +16 -17
  2. cognite_toolkit/_cdf_tk/apps/__init__.py +2 -0
  3. cognite_toolkit/_cdf_tk/apps/_core_app.py +13 -5
  4. cognite_toolkit/_cdf_tk/apps/_data_app.py +1 -1
  5. cognite_toolkit/_cdf_tk/apps/_dev_app.py +86 -0
  6. cognite_toolkit/_cdf_tk/apps/_download_app.py +692 -24
  7. cognite_toolkit/_cdf_tk/apps/_dump_app.py +43 -101
  8. cognite_toolkit/_cdf_tk/apps/_landing_app.py +18 -4
  9. cognite_toolkit/_cdf_tk/apps/_migrate_app.py +249 -9
  10. cognite_toolkit/_cdf_tk/apps/_modules_app.py +0 -3
  11. cognite_toolkit/_cdf_tk/apps/_purge.py +15 -43
  12. cognite_toolkit/_cdf_tk/apps/_run.py +11 -0
  13. cognite_toolkit/_cdf_tk/apps/_upload_app.py +45 -6
  14. cognite_toolkit/_cdf_tk/builders/__init__.py +2 -2
  15. cognite_toolkit/_cdf_tk/builders/_base.py +28 -42
  16. cognite_toolkit/_cdf_tk/cdf_toml.py +20 -1
  17. cognite_toolkit/_cdf_tk/client/_toolkit_client.py +23 -3
  18. cognite_toolkit/_cdf_tk/client/api/extended_functions.py +6 -9
  19. cognite_toolkit/_cdf_tk/client/api/infield.py +93 -1
  20. cognite_toolkit/_cdf_tk/client/api/migration.py +175 -1
  21. cognite_toolkit/_cdf_tk/client/api/streams.py +84 -0
  22. cognite_toolkit/_cdf_tk/client/api/three_d.py +50 -0
  23. cognite_toolkit/_cdf_tk/client/data_classes/base.py +25 -1
  24. cognite_toolkit/_cdf_tk/client/data_classes/canvas.py +46 -3
  25. cognite_toolkit/_cdf_tk/client/data_classes/charts.py +3 -3
  26. cognite_toolkit/_cdf_tk/client/data_classes/charts_data.py +95 -213
  27. cognite_toolkit/_cdf_tk/client/data_classes/infield.py +32 -18
  28. cognite_toolkit/_cdf_tk/client/data_classes/migration.py +10 -2
  29. cognite_toolkit/_cdf_tk/client/data_classes/streams.py +90 -0
  30. cognite_toolkit/_cdf_tk/client/data_classes/three_d.py +47 -0
  31. cognite_toolkit/_cdf_tk/client/testing.py +18 -2
  32. cognite_toolkit/_cdf_tk/commands/__init__.py +6 -6
  33. cognite_toolkit/_cdf_tk/commands/_changes.py +3 -42
  34. cognite_toolkit/_cdf_tk/commands/_download.py +21 -11
  35. cognite_toolkit/_cdf_tk/commands/_migrate/__init__.py +0 -2
  36. cognite_toolkit/_cdf_tk/commands/_migrate/command.py +22 -20
  37. cognite_toolkit/_cdf_tk/commands/_migrate/conversion.py +133 -91
  38. cognite_toolkit/_cdf_tk/commands/_migrate/data_classes.py +73 -22
  39. cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py +311 -43
  40. cognite_toolkit/_cdf_tk/commands/_migrate/default_mappings.py +5 -5
  41. cognite_toolkit/_cdf_tk/commands/_migrate/issues.py +33 -0
  42. cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py +157 -8
  43. cognite_toolkit/_cdf_tk/commands/_migrate/selectors.py +9 -4
  44. cognite_toolkit/_cdf_tk/commands/_purge.py +27 -28
  45. cognite_toolkit/_cdf_tk/commands/_questionary_style.py +16 -0
  46. cognite_toolkit/_cdf_tk/commands/_upload.py +109 -86
  47. cognite_toolkit/_cdf_tk/commands/about.py +221 -0
  48. cognite_toolkit/_cdf_tk/commands/auth.py +19 -12
  49. cognite_toolkit/_cdf_tk/commands/build_cmd.py +15 -61
  50. cognite_toolkit/_cdf_tk/commands/clean.py +63 -16
  51. cognite_toolkit/_cdf_tk/commands/deploy.py +20 -17
  52. cognite_toolkit/_cdf_tk/commands/dump_resource.py +6 -4
  53. cognite_toolkit/_cdf_tk/commands/init.py +225 -3
  54. cognite_toolkit/_cdf_tk/commands/modules.py +20 -44
  55. cognite_toolkit/_cdf_tk/commands/pull.py +6 -19
  56. cognite_toolkit/_cdf_tk/commands/resources.py +179 -0
  57. cognite_toolkit/_cdf_tk/constants.py +20 -1
  58. cognite_toolkit/_cdf_tk/cruds/__init__.py +19 -5
  59. cognite_toolkit/_cdf_tk/cruds/_base_cruds.py +14 -70
  60. cognite_toolkit/_cdf_tk/cruds/_data_cruds.py +8 -17
  61. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/__init__.py +4 -1
  62. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/agent.py +11 -9
  63. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/auth.py +4 -14
  64. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/classic.py +44 -43
  65. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/configuration.py +4 -11
  66. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/data_organization.py +4 -13
  67. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/datamodel.py +205 -66
  68. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/extraction_pipeline.py +5 -17
  69. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/fieldops.py +116 -27
  70. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/file.py +6 -27
  71. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/function.py +9 -28
  72. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/hosted_extractors.py +12 -30
  73. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/industrial_tool.py +3 -7
  74. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/location.py +3 -15
  75. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/migration.py +4 -12
  76. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/raw.py +4 -10
  77. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/relationship.py +3 -8
  78. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/robotics.py +15 -44
  79. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/streams.py +94 -0
  80. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/three_d_model.py +3 -7
  81. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/timeseries.py +5 -15
  82. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/transformation.py +39 -31
  83. cognite_toolkit/_cdf_tk/cruds/_resource_cruds/workflow.py +20 -40
  84. cognite_toolkit/_cdf_tk/cruds/_worker.py +24 -36
  85. cognite_toolkit/_cdf_tk/feature_flags.py +16 -36
  86. cognite_toolkit/_cdf_tk/plugins.py +2 -1
  87. cognite_toolkit/_cdf_tk/resource_classes/__init__.py +4 -0
  88. cognite_toolkit/_cdf_tk/resource_classes/capabilities.py +12 -0
  89. cognite_toolkit/_cdf_tk/resource_classes/functions.py +3 -1
  90. cognite_toolkit/_cdf_tk/resource_classes/infield_cdm_location_config.py +109 -0
  91. cognite_toolkit/_cdf_tk/resource_classes/migration.py +8 -17
  92. cognite_toolkit/_cdf_tk/resource_classes/streams.py +29 -0
  93. cognite_toolkit/_cdf_tk/storageio/__init__.py +9 -21
  94. cognite_toolkit/_cdf_tk/storageio/_annotations.py +19 -16
  95. cognite_toolkit/_cdf_tk/storageio/_applications.py +338 -26
  96. cognite_toolkit/_cdf_tk/storageio/_asset_centric.py +67 -104
  97. cognite_toolkit/_cdf_tk/storageio/_base.py +61 -29
  98. cognite_toolkit/_cdf_tk/storageio/_datapoints.py +276 -20
  99. cognite_toolkit/_cdf_tk/storageio/_file_content.py +436 -0
  100. cognite_toolkit/_cdf_tk/storageio/_instances.py +34 -2
  101. cognite_toolkit/_cdf_tk/storageio/_raw.py +26 -0
  102. cognite_toolkit/_cdf_tk/storageio/selectors/__init__.py +62 -4
  103. cognite_toolkit/_cdf_tk/storageio/selectors/_base.py +14 -2
  104. cognite_toolkit/_cdf_tk/storageio/selectors/_canvas.py +14 -0
  105. cognite_toolkit/_cdf_tk/storageio/selectors/_charts.py +14 -0
  106. cognite_toolkit/_cdf_tk/storageio/selectors/_datapoints.py +23 -3
  107. cognite_toolkit/_cdf_tk/storageio/selectors/_file_content.py +164 -0
  108. cognite_toolkit/_cdf_tk/tk_warnings/other.py +4 -0
  109. cognite_toolkit/_cdf_tk/tracker.py +2 -2
  110. cognite_toolkit/_cdf_tk/utils/dtype_conversion.py +9 -3
  111. cognite_toolkit/_cdf_tk/utils/fileio/__init__.py +2 -0
  112. cognite_toolkit/_cdf_tk/utils/fileio/_base.py +5 -1
  113. cognite_toolkit/_cdf_tk/utils/fileio/_readers.py +112 -20
  114. cognite_toolkit/_cdf_tk/utils/fileio/_writers.py +15 -15
  115. cognite_toolkit/_cdf_tk/utils/http_client/_client.py +284 -18
  116. cognite_toolkit/_cdf_tk/utils/http_client/_data_classes.py +50 -4
  117. cognite_toolkit/_cdf_tk/utils/http_client/_data_classes2.py +187 -0
  118. cognite_toolkit/_cdf_tk/utils/interactive_select.py +9 -14
  119. cognite_toolkit/_cdf_tk/utils/sql_parser.py +2 -3
  120. cognite_toolkit/_cdf_tk/utils/useful_types.py +6 -2
  121. cognite_toolkit/_cdf_tk/validation.py +79 -1
  122. cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml +1 -1
  123. cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml +1 -1
  124. cognite_toolkit/_resources/cdf.toml +5 -4
  125. cognite_toolkit/_version.py +1 -1
  126. cognite_toolkit/config.dev.yaml +13 -0
  127. {cognite_toolkit-0.6.97.dist-info → cognite_toolkit-0.7.30.dist-info}/METADATA +24 -24
  128. {cognite_toolkit-0.6.97.dist-info → cognite_toolkit-0.7.30.dist-info}/RECORD +153 -143
  129. cognite_toolkit-0.7.30.dist-info/WHEEL +4 -0
  130. {cognite_toolkit-0.6.97.dist-info → cognite_toolkit-0.7.30.dist-info}/entry_points.txt +1 -0
  131. cognite_toolkit/_cdf_tk/commands/_migrate/canvas.py +0 -201
  132. cognite_toolkit/_cdf_tk/commands/dump_data.py +0 -489
  133. cognite_toolkit/_cdf_tk/commands/featureflag.py +0 -27
  134. cognite_toolkit/_cdf_tk/utils/table_writers.py +0 -434
  135. cognite_toolkit-0.6.97.dist-info/WHEEL +0 -4
  136. cognite_toolkit-0.6.97.dist-info/licenses/LICENSE +0 -18
@@ -7,13 +7,7 @@ from cognite.client.data_classes.data_modeling import DataModelId, ViewId
7
7
  from rich import print
8
8
 
9
9
  from cognite_toolkit._cdf_tk.client.data_classes.search_config import ViewId as SearchConfigViewId
10
- from cognite_toolkit._cdf_tk.commands import DumpDataCommand, DumpResourceCommand
11
- from cognite_toolkit._cdf_tk.commands.dump_data import (
12
- AssetFinder,
13
- EventFinder,
14
- FileMetadataFinder,
15
- TimeSeriesFinder,
16
- )
10
+ from cognite_toolkit._cdf_tk.commands import DumpResourceCommand
17
11
  from cognite_toolkit._cdf_tk.commands.dump_resource import (
18
12
  AgentFinder,
19
13
  DataModelFinder,
@@ -32,45 +26,32 @@ from cognite_toolkit._cdf_tk.commands.dump_resource import (
32
26
  from cognite_toolkit._cdf_tk.exceptions import ToolkitRequiredValueError
33
27
  from cognite_toolkit._cdf_tk.feature_flags import Flags
34
28
  from cognite_toolkit._cdf_tk.utils.auth import EnvironmentVariables
35
- from cognite_toolkit._cdf_tk.utils.interactive_select import (
36
- AssetInteractiveSelect,
37
- EventInteractiveSelect,
38
- FileMetadataInteractiveSelect,
39
- TimeSeriesInteractiveSelect,
40
- )
41
29
 
42
30
 
43
31
  class DumpApp(typer.Typer):
44
32
  def __init__(self, *args: Any, **kwargs: Any) -> None:
45
33
  super().__init__(*args, **kwargs)
46
34
  self.callback(invoke_without_command=True)(self.dump_main)
47
- if Flags.DUMP_DATA.is_enabled():
48
- self.add_typer(DumpDataApp(*args, **kwargs), name="data")
49
- self.add_typer(DumpConfigApp(*args, **kwargs), name="config")
50
- else:
51
- self.command("datamodel")(DumpConfigApp.dump_datamodel_cmd)
35
+ self.command("datamodel")(DumpConfigApp.dump_datamodel_cmd)
52
36
 
53
- self.command("asset")(DumpDataApp.dump_asset_cmd)
54
- self.command("timeseries")(DumpDataApp.dump_timeseries_cmd)
37
+ self.command("asset")(DumpDataApp.dump_asset_cmd)
38
+ self.command("timeseries")(DumpDataApp.dump_timeseries_cmd)
55
39
 
56
- self.command("workflow")(DumpConfigApp.dump_workflow)
57
- self.command("transformation")(DumpConfigApp.dump_transformation)
58
- self.command("group")(DumpConfigApp.dump_group)
59
- self.command("node")(DumpConfigApp.dump_node)
60
- self.command("spaces")(DumpConfigApp.dump_spaces)
40
+ self.command("workflow")(DumpConfigApp.dump_workflow)
41
+ self.command("transformation")(DumpConfigApp.dump_transformation)
42
+ self.command("group")(DumpConfigApp.dump_group)
43
+ self.command("node")(DumpConfigApp.dump_node)
44
+ self.command("spaces")(DumpConfigApp.dump_spaces)
61
45
 
62
- if Flags.DUMP_EXTENDED.is_enabled():
63
- self.command("location-filter")(DumpConfigApp.dump_location_filters)
64
- self.command("extraction-pipeline")(DumpConfigApp.dump_extraction_pipeline)
65
- self.command("functions")(DumpConfigApp.dump_functions)
66
- self.command("datasets")(DumpConfigApp.dump_datasets)
67
- self.command("streamlit")(DumpConfigApp.dump_streamlit)
46
+ self.command("location-filter")(DumpConfigApp.dump_location_filters)
47
+ self.command("extraction-pipeline")(DumpConfigApp.dump_extraction_pipeline)
48
+ self.command("functions")(DumpConfigApp.dump_functions)
49
+ self.command("datasets")(DumpConfigApp.dump_datasets)
50
+ self.command("streamlit")(DumpConfigApp.dump_streamlit)
68
51
 
69
- if Flags.AGENTS.is_enabled():
70
- self.command("agents")(DumpConfigApp.dump_agents)
52
+ self.command("agents")(DumpConfigApp.dump_agents)
71
53
 
72
- if Flags.SEARCH_CONFIG.is_enabled():
73
- self.command("search-config")(DumpConfigApp.dump_search_config)
54
+ self.command("search-config")(DumpConfigApp.dump_search_config)
74
55
 
75
56
  @staticmethod
76
57
  def dump_main(ctx: typer.Context) -> None:
@@ -91,18 +72,13 @@ class DumpConfigApp(typer.Typer):
91
72
  self.command("group")(self.dump_group)
92
73
  self.command("node")(self.dump_node)
93
74
  self.command("spaces")(self.dump_spaces)
94
- if Flags.DUMP_EXTENDED.is_enabled():
95
- self.command("location-filters")(self.dump_location_filters)
96
- self.command("extraction-pipeline")(self.dump_extraction_pipeline)
97
- self.command("datasets")(DumpConfigApp.dump_datasets)
98
- self.command("functions")(self.dump_functions)
99
- self.command("streamlit")(DumpConfigApp.dump_streamlit)
100
-
101
- if Flags.AGENTS.is_enabled():
102
- self.command("agents")(self.dump_agents)
103
-
104
- if Flags.SEARCH_CONFIG.is_enabled():
105
- self.command("search-config")(self.dump_search_config)
75
+ self.command("location-filters")(self.dump_location_filters)
76
+ self.command("extraction-pipeline")(self.dump_extraction_pipeline)
77
+ self.command("datasets")(DumpConfigApp.dump_datasets)
78
+ self.command("functions")(self.dump_functions)
79
+ self.command("streamlit")(DumpConfigApp.dump_streamlit)
80
+ self.command("agents")(self.dump_agents)
81
+ self.command("search-config")(self.dump_search_config)
106
82
 
107
83
  @staticmethod
108
84
  def dump_config_main(ctx: typer.Context) -> None:
@@ -862,21 +838,11 @@ class DumpDataApp(typer.Typer):
862
838
  ] = False,
863
839
  ) -> None:
864
840
  """This command will dump the selected assets in the selected format to the folder specified, defaults to /tmp."""
865
- cmd = DumpDataCommand()
866
- client = EnvironmentVariables.create_from_environment().get_client()
867
- if hierarchy is None and data_set is None:
868
- hierarchy, data_set = AssetInteractiveSelect(client, "dump").select_hierarchies_and_data_sets()
869
-
870
- cmd.run(
871
- lambda: cmd.dump_table(
872
- AssetFinder(client, hierarchy or [], data_set or []),
873
- output_dir,
874
- clean,
875
- limit,
876
- format_,
877
- verbose,
841
+ if Flags.v08:
842
+ raise ValueError(
843
+ "The `cdf dump data asset` command has been removed. Please use `cdf data download assets` instead."
878
844
  )
879
- )
845
+ print("[bold yellow]Warning:[/] This command has been removed. Please use `cdf data download assets` instead.")
880
846
 
881
847
  @staticmethod
882
848
  def dump_files_cmd(
@@ -940,21 +906,12 @@ class DumpDataApp(typer.Typer):
940
906
  ] = False,
941
907
  ) -> None:
942
908
  """This command will dump the selected events to the selected format in the folder specified, defaults to /tmp."""
943
- cmd = DumpDataCommand()
944
- cmd.validate_directory(output_dir, clean)
945
- client = EnvironmentVariables.create_from_environment().get_client()
946
- if hierarchy is None and data_set is None:
947
- hierarchy, data_set = FileMetadataInteractiveSelect(client, "dump").select_hierarchies_and_data_sets()
948
- cmd.run(
949
- lambda: cmd.dump_table(
950
- FileMetadataFinder(client, hierarchy or [], data_set or []),
951
- output_dir,
952
- clean,
953
- limit,
954
- format_,
955
- verbose,
909
+ if Flags.v08:
910
+ raise ValueError(
911
+ "The `cdf dump data files-metadata` command has been removed. Please use `cdf data download files` instead."
956
912
  )
957
- )
913
+ print("[bold yellow]Warning:[/] This command has been removed. Please use `cdf data download files` instead.")
914
+ return None
958
915
 
959
916
  @staticmethod
960
917
  def dump_timeseries_cmd(
@@ -1018,20 +975,14 @@ class DumpDataApp(typer.Typer):
1018
975
  ] = False,
1019
976
  ) -> None:
1020
977
  """This command will dump the selected timeseries to the selected format in the folder specified, defaults to /tmp."""
1021
- cmd = DumpDataCommand()
1022
- client = EnvironmentVariables.create_from_environment().get_client()
1023
- if hierarchy is None and data_set is None:
1024
- hierarchy, data_set = TimeSeriesInteractiveSelect(client, "dump").select_hierarchies_and_data_sets()
1025
- cmd.run(
1026
- lambda: cmd.dump_table(
1027
- TimeSeriesFinder(client, hierarchy or [], data_set or []),
1028
- output_dir,
1029
- clean,
1030
- limit,
1031
- format_,
1032
- verbose,
978
+ if Flags.v08:
979
+ raise ValueError(
980
+ "The `cdf dump data timeseries` command has been removed. Please use `cdf data download timeseries` instead."
1033
981
  )
982
+ print(
983
+ "[bold yellow]Warning:[/] This command has been removed. Please use `cdf data download timeseries` instead."
1034
984
  )
985
+ return None
1035
986
 
1036
987
  @staticmethod
1037
988
  def dump_event_cmd(
@@ -1095,18 +1046,9 @@ class DumpDataApp(typer.Typer):
1095
1046
  ] = False,
1096
1047
  ) -> None:
1097
1048
  """This command will dump the selected events to the selected format in the folder specified, defaults to /tmp."""
1098
- cmd = DumpDataCommand()
1099
- cmd.validate_directory(output_dir, clean)
1100
- client = EnvironmentVariables.create_from_environment().get_client()
1101
- if hierarchy is None and data_set is None:
1102
- hierarchy, data_set = EventInteractiveSelect(client, "dump").select_hierarchies_and_data_sets()
1103
- cmd.run(
1104
- lambda: cmd.dump_table(
1105
- EventFinder(client, hierarchy or [], data_set or []),
1106
- output_dir,
1107
- clean,
1108
- limit,
1109
- format_,
1110
- verbose,
1049
+ if Flags.v08:
1050
+ raise ValueError(
1051
+ "The `cdf dump data event` command has been removed. Please use `cdf data download events` instead."
1111
1052
  )
1112
- )
1053
+ print("[bold yellow]Warning:[/] This command has been removed. Please use `cdf data download events` instead.")
1054
+ return None
@@ -1,3 +1,5 @@
1
+ from typing import Annotated
2
+
1
3
  import typer
2
4
 
3
5
  from cognite_toolkit._cdf_tk.commands import InitCommand
@@ -6,9 +8,21 @@ from cognite_toolkit._cdf_tk.commands import InitCommand
6
8
  class LandingApp(typer.Typer):
7
9
  def __init__(self, *args, **kwargs) -> None: # type: ignore
8
10
  super().__init__(*args, **kwargs)
9
- self.command()(self.main_init)
10
11
 
11
- def main_init(self) -> None:
12
- """Guidance on how to get started"""
12
+ def main_init(
13
+ self,
14
+ dry_run: Annotated[
15
+ bool,
16
+ typer.Option(
17
+ "--dry-run",
18
+ "-r",
19
+ help="Whether to do a dry-run, do dry-run if present.",
20
+ ),
21
+ ] = False,
22
+ ) -> None:
23
+ """Getting started checklist"""
13
24
  cmd = InitCommand()
14
- cmd.run(cmd.execute)
25
+ # Tracking command with the usual lambda run construct
26
+ # is intentionally left out because we don't want to expose the user to the warning
27
+ # before they've had the chance to opt in (which is something they'll do later using this command).
28
+ cmd.execute(dry_run=dry_run)
@@ -4,21 +4,20 @@ 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
10
- from cognite_toolkit._cdf_tk.commands import (
11
- MigrationCanvasCommand,
12
- MigrationPrepareCommand,
13
- )
11
+ from cognite_toolkit._cdf_tk.commands import MigrationPrepareCommand
14
12
  from cognite_toolkit._cdf_tk.commands._migrate import MigrationCommand
15
13
  from cognite_toolkit._cdf_tk.commands._migrate.creators import (
16
14
  InfieldV2ConfigCreator,
17
15
  InstanceSpaceCreator,
18
16
  SourceSystemCreator,
19
17
  )
20
- from cognite_toolkit._cdf_tk.commands._migrate.data_mapper import AssetCentricMapper
18
+ from cognite_toolkit._cdf_tk.commands._migrate.data_mapper import AssetCentricMapper, CanvasMapper, ChartMapper
21
19
  from cognite_toolkit._cdf_tk.commands._migrate.migration_io import (
20
+ AnnotationMigrationIO,
22
21
  AssetCentricMigrationIO,
23
22
  )
24
23
  from cognite_toolkit._cdf_tk.commands._migrate.selectors import (
@@ -26,11 +25,16 @@ from cognite_toolkit._cdf_tk.commands._migrate.selectors import (
26
25
  MigrateDataSetSelector,
27
26
  MigrationCSVFileSelector,
28
27
  )
28
+ from cognite_toolkit._cdf_tk.storageio import CanvasIO, ChartIO
29
+ from cognite_toolkit._cdf_tk.storageio.selectors import CanvasExternalIdSelector, ChartExternalIdSelector
29
30
  from cognite_toolkit._cdf_tk.utils.auth import EnvironmentVariables
30
31
  from cognite_toolkit._cdf_tk.utils.cli_args import parse_view_str
31
32
  from cognite_toolkit._cdf_tk.utils.interactive_select import (
32
33
  AssetInteractiveSelect,
33
34
  DataModelingSelect,
35
+ FileMetadataInteractiveSelect,
36
+ InteractiveCanvasSelect,
37
+ InteractiveChartSelect,
34
38
  ResourceViewMappingInteractiveSelect,
35
39
  )
36
40
  from cognite_toolkit._cdf_tk.utils.useful_types import AssetCentricKind
@@ -49,7 +53,9 @@ class MigrateApp(typer.Typer):
49
53
  self.command("events")(self.events)
50
54
  self.command("timeseries")(self.timeseries)
51
55
  self.command("files")(self.files)
56
+ self.command("annotations")(self.annotations)
52
57
  self.command("canvas")(self.canvas)
58
+ self.command("charts")(self.charts)
53
59
  # Uncomment when infield v2 config migration is ready
54
60
  # self.command("infield-configs")(self.infield_configs)
55
61
 
@@ -694,6 +700,149 @@ class MigrateApp(typer.Typer):
694
700
  )
695
701
  )
696
702
 
703
+ @classmethod
704
+ def annotations(
705
+ cls,
706
+ ctx: typer.Context,
707
+ mapping_file: Annotated[
708
+ Path | None,
709
+ typer.Option(
710
+ "--mapping-file",
711
+ "-m",
712
+ help="Path to the mapping file that contains the mapping from Annotations to CogniteDiagramAnnotation. "
713
+ "This file is expected to have the following columns: [id, space, externalId, ingestionView].",
714
+ ),
715
+ ] = None,
716
+ data_set_id: Annotated[
717
+ str | None,
718
+ typer.Option(
719
+ "--data-set-id",
720
+ "-s",
721
+ help="The data set ID to select for the annotations to migrate. If not provided and the mapping file is not provided, "
722
+ "an interactive selection will be performed to select the data set to migrate annotations from.",
723
+ ),
724
+ ] = None,
725
+ instance_space: Annotated[
726
+ str | None,
727
+ typer.Option(
728
+ "--instance-space",
729
+ "-i",
730
+ help="The instance space to use for the migrated annotations. Required when using --data-set-id.",
731
+ ),
732
+ ] = None,
733
+ asset_annotation_mapping: Annotated[
734
+ str | None,
735
+ typer.Option(
736
+ "--asset-annotation-mapping",
737
+ "-a",
738
+ help="The ingestion mapping to use for asset-linked annotations. If not provided, "
739
+ "the default mapping (cdf_asset_annotations_mapping) will be used.",
740
+ ),
741
+ ] = None,
742
+ file_annotation_mapping: Annotated[
743
+ str | None,
744
+ typer.Option(
745
+ "--file-annotation-mapping",
746
+ "-f",
747
+ help="The ingestion mapping to use for file-linked annotations. If not provided, "
748
+ "the default mapping (cdf_file_annotations_mapping) will be used.",
749
+ ),
750
+ ] = None,
751
+ log_dir: Annotated[
752
+ Path,
753
+ typer.Option(
754
+ "--log-dir",
755
+ "-l",
756
+ help="Path to the directory where logs will be stored. If the directory does not exist, it will be created.",
757
+ ),
758
+ ] = Path(f"migration_logs_{TODAY!s}"),
759
+ dry_run: Annotated[
760
+ bool,
761
+ typer.Option(
762
+ "--dry-run",
763
+ "-d",
764
+ help="If set, the migration will not be executed, but only a report of what would be done is printed.",
765
+ ),
766
+ ] = False,
767
+ verbose: Annotated[
768
+ bool,
769
+ typer.Option(
770
+ "--verbose",
771
+ "-v",
772
+ help="Turn on to get more verbose output when running the command",
773
+ ),
774
+ ] = False,
775
+ ) -> None:
776
+ """Migrate Annotations to CogniteDiagramAnnotation edges in data modeling.
777
+
778
+ Annotations are diagram annotations that link assets or files to other resources. This command
779
+ migrates them to edges in the data modeling space, preserving the relationships and metadata.
780
+ """
781
+ client = EnvironmentVariables.create_from_environment().get_client()
782
+
783
+ if data_set_id is not None and mapping_file is not None:
784
+ raise typer.BadParameter("Cannot specify both data_set_id and mapping_file")
785
+ elif mapping_file is not None:
786
+ selected: AssetCentricMigrationSelector = MigrationCSVFileSelector(
787
+ datafile=mapping_file, kind="Annotations"
788
+ )
789
+ annotation_io = AnnotationMigrationIO(client)
790
+ elif data_set_id is not None:
791
+ if instance_space is None:
792
+ raise typer.BadParameter("--instance-space is required when using --data-set-id")
793
+ selected = MigrateDataSetSelector(data_set_external_id=data_set_id, kind="Annotations")
794
+ annotation_io = AnnotationMigrationIO(
795
+ client,
796
+ instance_space=instance_space,
797
+ default_asset_annotation_mapping=asset_annotation_mapping,
798
+ default_file_annotation_mapping=file_annotation_mapping,
799
+ )
800
+ else:
801
+ # Interactive selection
802
+ selector = FileMetadataInteractiveSelect(client, "migrate")
803
+ selected_data_set_id = selector.select_data_set(allow_empty=False)
804
+ dm_selector = DataModelingSelect(client, "migrate")
805
+ selected_instance_space = dm_selector.select_instance_space(
806
+ multiselect=False,
807
+ message="In which instance space do you want to create the annotations?",
808
+ include_empty=True,
809
+ )
810
+ if selected_instance_space is None:
811
+ raise typer.Abort()
812
+ asset_annotations_selector = ResourceViewMappingInteractiveSelect(client, "migrate asset annotations")
813
+ asset_annotation_mapping = asset_annotations_selector.select_resource_view_mapping(
814
+ resource_type="assetAnnotation",
815
+ ).external_id
816
+ file_annotations_selector = ResourceViewMappingInteractiveSelect(client, "migrate file annotations")
817
+ file_annotation_mapping = file_annotations_selector.select_resource_view_mapping(
818
+ resource_type="fileAnnotation",
819
+ ).external_id
820
+
821
+ selected = MigrateDataSetSelector(data_set_external_id=selected_data_set_id, kind="Annotations")
822
+ annotation_io = AnnotationMigrationIO(
823
+ client,
824
+ instance_space=selected_instance_space,
825
+ default_asset_annotation_mapping=asset_annotation_mapping,
826
+ default_file_annotation_mapping=file_annotation_mapping,
827
+ )
828
+
829
+ dry_run = questionary.confirm("Do you want to perform a dry run?", default=dry_run).ask()
830
+ verbose = questionary.confirm("Do you want verbose output?", default=verbose).ask()
831
+ if any(res is None for res in [dry_run, verbose]):
832
+ raise typer.Abort()
833
+
834
+ cmd = MigrationCommand()
835
+ cmd.run(
836
+ lambda: cmd.migrate(
837
+ selected=selected,
838
+ data=annotation_io,
839
+ mapper=AssetCentricMapper[Annotation](client),
840
+ log_dir=log_dir,
841
+ dry_run=dry_run,
842
+ verbose=verbose,
843
+ )
844
+ )
845
+
697
846
  @staticmethod
698
847
  def canvas(
699
848
  ctx: typer.Context,
@@ -704,6 +853,23 @@ class MigrateApp(typer.Typer):
704
853
  "performed to select the Canvas to migrate."
705
854
  ),
706
855
  ] = None,
856
+ skip_on_missing_ref: Annotated[
857
+ bool,
858
+ typer.Option(
859
+ "--skip-on-missing-ref",
860
+ "-s",
861
+ help="If set, the migration will skip Canvases that reference resources that have not been migrated to data modeling. "
862
+ "If not set, the migration will continue but the result will exclude the missing references.",
863
+ ),
864
+ ] = False,
865
+ log_dir: Annotated[
866
+ Path,
867
+ typer.Option(
868
+ "--log-dir",
869
+ "-l",
870
+ help="Path to the directory where migration logs will be stored.",
871
+ ),
872
+ ] = Path(f"migration_logs_{TODAY}"),
707
873
  dry_run: Annotated[
708
874
  bool,
709
875
  typer.Option(
@@ -729,12 +895,86 @@ class MigrateApp(typer.Typer):
729
895
  is populated with the mapping from Asset-Centric resources to the new data modeling resources.
730
896
  """
731
897
  client = EnvironmentVariables.create_from_environment().get_client()
898
+ if external_id is None:
899
+ interactive = InteractiveCanvasSelect(client)
900
+ external_id = interactive.select_external_ids()
901
+ log_dir = questionary.path("Specify log directory for migration logs:", default=str(log_dir)).ask()
902
+ dry_run = questionary.confirm("Do you want to perform a dry run?", default=dry_run).ask()
903
+ verbose = questionary.confirm("Do you want verbose output?", default=verbose).ask()
904
+ if any(res is None for res in [log_dir, dry_run, verbose]):
905
+ raise typer.Abort()
906
+ log_dir = Path(log_dir)
732
907
 
733
- cmd = MigrationCanvasCommand()
908
+ cmd = MigrationCommand()
909
+ selector = CanvasExternalIdSelector(external_ids=tuple(external_id))
734
910
  cmd.run(
735
- lambda: cmd.migrate_canvas(
736
- client,
737
- external_ids=external_id,
911
+ lambda: cmd.migrate(
912
+ selected=selector,
913
+ data=CanvasIO(client, exclude_existing_version=True),
914
+ mapper=CanvasMapper(client, dry_run=dry_run, skip_on_missing_ref=skip_on_missing_ref),
915
+ log_dir=log_dir,
916
+ dry_run=dry_run,
917
+ verbose=verbose,
918
+ )
919
+ )
920
+
921
+ @staticmethod
922
+ def charts(
923
+ ctx: typer.Context,
924
+ external_id: Annotated[
925
+ list[str] | None,
926
+ typer.Argument(
927
+ help="The external ID of the Chart to migrate. If not provided, an interactive selection will be "
928
+ "performed to select the Charts to migrate."
929
+ ),
930
+ ] = None,
931
+ log_dir: Annotated[
932
+ Path,
933
+ typer.Option(
934
+ "--log-dir",
935
+ "-l",
936
+ help="Path to the directory where migration logs will be stored.",
937
+ ),
938
+ ] = Path(f"migration_logs_{TODAY}"),
939
+ dry_run: Annotated[
940
+ bool,
941
+ typer.Option(
942
+ "--dry-run",
943
+ "-d",
944
+ help="If set, the migration will not be executed, but only a report of "
945
+ "what would be done is printed. This is useful for checking that all time series referenced by the Charts "
946
+ "have been migrated to the new data modeling resources in CDF.",
947
+ ),
948
+ ] = False,
949
+ verbose: Annotated[
950
+ bool,
951
+ typer.Option(
952
+ "--verbose",
953
+ "-v",
954
+ help="Turn on to get more verbose output when running the command",
955
+ ),
956
+ ] = False,
957
+ ) -> None:
958
+ """Migrate Charts from time series references to data modeling in CDF.
959
+
960
+ This command expects that the CogniteMigration data model is already deployed, and that the Mapping view
961
+ is populated with the mapping from time series to the new data modeling resources.
962
+ """
963
+ client = EnvironmentVariables.create_from_environment().get_client()
964
+
965
+ selected_external_ids: list[str]
966
+ if external_id:
967
+ selected_external_ids = external_id
968
+ else:
969
+ selected_external_ids = InteractiveChartSelect(client).select_external_ids()
970
+
971
+ cmd = MigrationCommand()
972
+ cmd.run(
973
+ lambda: cmd.migrate(
974
+ selected=ChartExternalIdSelector(external_ids=tuple(selected_external_ids)),
975
+ data=ChartIO(client),
976
+ mapper=ChartMapper(client),
977
+ log_dir=log_dir,
738
978
  dry_run=dry_run,
739
979
  verbose=verbose,
740
980
  )
@@ -6,7 +6,6 @@ from rich import print
6
6
 
7
7
  from cognite_toolkit._cdf_tk.cdf_toml import CDFToml
8
8
  from cognite_toolkit._cdf_tk.commands import ModulesCommand, PullCommand
9
- from cognite_toolkit._cdf_tk.feature_flags import Flags
10
9
  from cognite_toolkit._cdf_tk.utils.auth import EnvironmentVariables
11
10
  from cognite_toolkit._version import __version__
12
11
 
@@ -58,7 +57,6 @@ class ModulesApp(typer.Typer):
58
57
  "--library-url",
59
58
  "-u",
60
59
  help="URL of the library to add to the project.",
61
- hidden=not Flags.EXTERNAL_LIBRARIES.is_enabled(),
62
60
  ),
63
61
  ] = None,
64
62
  library_checksum: Annotated[
@@ -67,7 +65,6 @@ class ModulesApp(typer.Typer):
67
65
  "--library-checksum",
68
66
  "-c",
69
67
  help="Checksum of the library to add to the project.",
70
- hidden=not Flags.EXTERNAL_LIBRARIES.is_enabled(),
71
68
  ),
72
69
  ] = None,
73
70
  verbose: Annotated[