cognite-toolkit 0.7.56__py3-none-any.whl → 0.7.58__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 (93) hide show
  1. cognite_toolkit/_cdf_tk/apps/_auth_app.py +2 -2
  2. cognite_toolkit/_cdf_tk/apps/_core_app.py +4 -4
  3. cognite_toolkit/_cdf_tk/apps/_dev_app.py +10 -1
  4. cognite_toolkit/_cdf_tk/apps/_download_app.py +13 -12
  5. cognite_toolkit/_cdf_tk/apps/_dump_app.py +13 -13
  6. cognite_toolkit/_cdf_tk/apps/_landing_app.py +10 -1
  7. cognite_toolkit/_cdf_tk/apps/_migrate_app.py +15 -15
  8. cognite_toolkit/_cdf_tk/apps/_modules_app.py +29 -5
  9. cognite_toolkit/_cdf_tk/apps/_profile_app.py +4 -4
  10. cognite_toolkit/_cdf_tk/apps/_purge.py +4 -5
  11. cognite_toolkit/_cdf_tk/apps/_repo_app.py +9 -2
  12. cognite_toolkit/_cdf_tk/apps/_run.py +5 -4
  13. cognite_toolkit/_cdf_tk/apps/_upload_app.py +2 -2
  14. cognite_toolkit/_cdf_tk/client/api/agents.py +2 -4
  15. cognite_toolkit/_cdf_tk/client/api/annotations.py +2 -2
  16. cognite_toolkit/_cdf_tk/client/api/assets.py +3 -5
  17. cognite_toolkit/_cdf_tk/client/api/containers.py +2 -2
  18. cognite_toolkit/_cdf_tk/client/api/data_models.py +2 -2
  19. cognite_toolkit/_cdf_tk/client/api/datasets.py +3 -3
  20. cognite_toolkit/_cdf_tk/client/api/events.py +3 -5
  21. cognite_toolkit/_cdf_tk/client/api/extraction_pipelines.py +3 -3
  22. cognite_toolkit/_cdf_tk/client/api/filemetadata.py +6 -6
  23. cognite_toolkit/_cdf_tk/client/api/function_schedules.py +2 -2
  24. cognite_toolkit/_cdf_tk/client/api/functions.py +2 -2
  25. cognite_toolkit/_cdf_tk/client/api/graphql_data_models.py +5 -5
  26. cognite_toolkit/_cdf_tk/client/api/groups.py +5 -7
  27. cognite_toolkit/_cdf_tk/client/api/hosted_extractor_destinations.py +3 -3
  28. cognite_toolkit/_cdf_tk/client/api/hosted_extractor_jobs.py +3 -3
  29. cognite_toolkit/_cdf_tk/client/api/hosted_extractor_mappings.py +3 -3
  30. cognite_toolkit/_cdf_tk/client/api/hosted_extractor_sources.py +4 -4
  31. cognite_toolkit/_cdf_tk/client/api/infield.py +8 -8
  32. cognite_toolkit/_cdf_tk/client/api/instances.py +3 -3
  33. cognite_toolkit/_cdf_tk/client/api/labels.py +3 -5
  34. cognite_toolkit/_cdf_tk/client/api/legacy/extended_functions.py +3 -3
  35. cognite_toolkit/_cdf_tk/client/api/location_filters.py +8 -8
  36. cognite_toolkit/_cdf_tk/client/api/project.py +14 -2
  37. cognite_toolkit/_cdf_tk/client/api/raw.py +5 -5
  38. cognite_toolkit/_cdf_tk/client/api/relationships.py +2 -2
  39. cognite_toolkit/_cdf_tk/client/api/robotics_capabilities.py +3 -3
  40. cognite_toolkit/_cdf_tk/client/api/robotics_data_postprocessing.py +3 -3
  41. cognite_toolkit/_cdf_tk/client/api/robotics_frames.py +3 -3
  42. cognite_toolkit/_cdf_tk/client/api/robotics_locations.py +3 -3
  43. cognite_toolkit/_cdf_tk/client/api/robotics_maps.py +3 -3
  44. cognite_toolkit/_cdf_tk/client/api/robotics_robots.py +3 -5
  45. cognite_toolkit/_cdf_tk/client/api/search_config.py +5 -5
  46. cognite_toolkit/_cdf_tk/client/api/security_categories.py +3 -3
  47. cognite_toolkit/_cdf_tk/client/api/sequences.py +3 -3
  48. cognite_toolkit/_cdf_tk/client/api/simulator_models.py +3 -3
  49. cognite_toolkit/_cdf_tk/client/api/spaces.py +2 -4
  50. cognite_toolkit/_cdf_tk/client/api/streams.py +6 -6
  51. cognite_toolkit/_cdf_tk/client/api/three_d.py +5 -5
  52. cognite_toolkit/_cdf_tk/client/api/timeseries.py +3 -3
  53. cognite_toolkit/_cdf_tk/client/api/transformations.py +3 -3
  54. cognite_toolkit/_cdf_tk/client/api/views.py +2 -4
  55. cognite_toolkit/_cdf_tk/client/api/workflow_triggers.py +3 -3
  56. cognite_toolkit/_cdf_tk/client/api/workflow_versions.py +3 -3
  57. cognite_toolkit/_cdf_tk/client/api/workflows.py +3 -3
  58. cognite_toolkit/_cdf_tk/client/cdf_client/api.py +11 -11
  59. cognite_toolkit/_cdf_tk/client/http_client/__init__.py +23 -23
  60. cognite_toolkit/_cdf_tk/client/http_client/_client.py +46 -50
  61. cognite_toolkit/_cdf_tk/client/http_client/{_data_classes2.py → _data_classes.py} +25 -25
  62. cognite_toolkit/_cdf_tk/client/http_client/_item_classes.py +16 -16
  63. cognite_toolkit/_cdf_tk/client/resource_classes/project.py +30 -0
  64. cognite_toolkit/_cdf_tk/commands/_base.py +18 -1
  65. cognite_toolkit/_cdf_tk/commands/_import_cmd.py +3 -1
  66. cognite_toolkit/_cdf_tk/commands/_migrate/command.py +7 -7
  67. cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py +11 -11
  68. cognite_toolkit/_cdf_tk/commands/_profile.py +10 -5
  69. cognite_toolkit/_cdf_tk/commands/_purge.py +17 -21
  70. cognite_toolkit/_cdf_tk/commands/_upload.py +3 -3
  71. cognite_toolkit/_cdf_tk/commands/build_cmd.py +2 -1
  72. cognite_toolkit/_cdf_tk/commands/build_v2/build_cmd.py +8 -2
  73. cognite_toolkit/_cdf_tk/commands/deploy.py +8 -2
  74. cognite_toolkit/_cdf_tk/commands/init.py +9 -2
  75. cognite_toolkit/_cdf_tk/commands/modules.py +3 -1
  76. cognite_toolkit/_cdf_tk/commands/pull.py +8 -2
  77. cognite_toolkit/_cdf_tk/commands/repo.py +3 -1
  78. cognite_toolkit/_cdf_tk/commands/resources.py +0 -3
  79. cognite_toolkit/_cdf_tk/data_classes/_tracking_info.py +1 -0
  80. cognite_toolkit/_cdf_tk/storageio/_applications.py +6 -6
  81. cognite_toolkit/_cdf_tk/storageio/_base.py +2 -2
  82. cognite_toolkit/_cdf_tk/storageio/_datapoints.py +7 -7
  83. cognite_toolkit/_cdf_tk/storageio/_file_content.py +22 -22
  84. cognite_toolkit/_cdf_tk/storageio/_raw.py +2 -2
  85. cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml +1 -1
  86. cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml +1 -1
  87. cognite_toolkit/_resources/cdf.toml +1 -1
  88. cognite_toolkit/_version.py +1 -1
  89. {cognite_toolkit-0.7.56.dist-info → cognite_toolkit-0.7.58.dist-info}/METADATA +1 -1
  90. {cognite_toolkit-0.7.56.dist-info → cognite_toolkit-0.7.58.dist-info}/RECORD +92 -92
  91. cognite_toolkit/config.dev.yaml +0 -13
  92. {cognite_toolkit-0.7.56.dist-info → cognite_toolkit-0.7.58.dist-info}/WHEEL +0 -0
  93. {cognite_toolkit-0.7.56.dist-info → cognite_toolkit-0.7.58.dist-info}/entry_points.txt +0 -0
@@ -54,6 +54,7 @@ class AuthApp(typer.Typer):
54
54
  "projectsAcl": ["LIST", "READ"],
55
55
  "groupsAcl": ["LIST", "READ", "CREATE", "UPDATE", "DELETE"]
56
56
  """
57
+ # We do not pass in a client here as this is typically used to create the .env file needed for authentication.
57
58
  cmd = AuthCommand()
58
59
  cmd.run(
59
60
  lambda: cmd.init(
@@ -92,9 +93,8 @@ class AuthApp(typer.Typer):
92
93
  ] = False,
93
94
  ) -> None:
94
95
  """Verify that the current user or service principal has the required capabilities to run the CDF Toolkit commands."""
95
- cmd = AuthCommand()
96
96
  client = EnvironmentVariables.create_from_environment().get_client()
97
-
97
+ cmd = AuthCommand(client=client)
98
98
  cmd.run(
99
99
  lambda: cmd.verify(
100
100
  client,
@@ -210,9 +210,9 @@ class CoreApp(typer.Typer):
210
210
  print_warning = False
211
211
 
212
212
  cmd = (
213
- BuildCommandV2(print_warning=print_warning)
213
+ BuildCommandV2(print_warning=print_warning, client=client)
214
214
  if Flags.v08.is_enabled()
215
- else BuildCommand(print_warning=print_warning)
215
+ else BuildCommand(print_warning=print_warning, client=client)
216
216
  )
217
217
  cmd.run(
218
218
  lambda: cmd.execute(
@@ -302,8 +302,8 @@ class CoreApp(typer.Typer):
302
302
  ] = False,
303
303
  ) -> None:
304
304
  """Deploys the configuration files in the build directory to the CDF project."""
305
- cmd = DeployCommand(print_warning=True)
306
305
  env_vars = EnvironmentVariables.create_from_environment()
306
+ cmd = DeployCommand(print_warning=True, client=env_vars.get_client())
307
307
  cmd.run(
308
308
  lambda: cmd.deploy_build_directory(
309
309
  env_vars=env_vars,
@@ -371,8 +371,8 @@ class CoreApp(typer.Typer):
371
371
  ) -> None:
372
372
  """Cleans the resources in the build directory from the CDF project."""
373
373
  # Override cluster and project from the options/env variables
374
- cmd = CleanCommand(print_warning=True)
375
374
  env = EnvironmentVariables.create_from_environment()
375
+ cmd = CleanCommand(print_warning=True, client=env.get_client())
376
376
  cmd.run(
377
377
  lambda: cmd.execute(
378
378
  env,
@@ -1,3 +1,4 @@
1
+ import contextlib
1
2
  from pathlib import Path
2
3
  from typing import Annotated, Any
3
4
 
@@ -5,8 +6,10 @@ import typer
5
6
  from rich import print
6
7
 
7
8
  from cognite_toolkit._cdf_tk.cdf_toml import CDFToml
9
+ from cognite_toolkit._cdf_tk.client import ToolkitClient
8
10
  from cognite_toolkit._cdf_tk.commands import ResourcesCommand
9
11
  from cognite_toolkit._cdf_tk.feature_flags import FeatureFlag, Flags
12
+ from cognite_toolkit._cdf_tk.utils.auth import EnvironmentVariables
10
13
 
11
14
  from ._run import RunApp
12
15
 
@@ -74,7 +77,13 @@ class DevApp(typer.Typer):
74
77
  ] = CDF_TOML.cdf.default_organization_dir,
75
78
  ) -> None:
76
79
  """create resource YAMLs."""
77
- cmd = ResourcesCommand()
80
+ client: ToolkitClient | None = None
81
+ with contextlib.redirect_stdout(None), contextlib.suppress(Exception):
82
+ # Try to load client if possible, but ignore errors.
83
+ # This is only used for logging purposes in the command.
84
+ client = EnvironmentVariables.create_from_environment().get_client()
85
+
86
+ cmd = ResourcesCommand(client=client)
78
87
  cmd.run(
79
88
  lambda: cmd.create(
80
89
  organization_dir=organization_dir,
@@ -193,9 +193,9 @@ class DownloadApp(typer.Typer):
193
193
  ] = False,
194
194
  ) -> None:
195
195
  """This command will download RAW tables from CDF into a temporary directory."""
196
- cmd = DownloadCommand()
197
-
198
196
  client = EnvironmentVariables.create_from_environment().get_client()
197
+ cmd = DownloadCommand(client=client)
198
+
199
199
  if tables and database:
200
200
  selectors = [RawTable(db_name=database, table_name=table) for table in tables]
201
201
  elif tables and not database:
@@ -289,7 +289,7 @@ class DownloadApp(typer.Typer):
289
289
  )
290
290
 
291
291
  selectors = [DataSetSelector(kind="Assets", data_set_external_id=data_set) for data_set in data_sets]
292
- cmd = DownloadCommand()
292
+ cmd = DownloadCommand(client=client)
293
293
  cmd.run(
294
294
  lambda: cmd.download(
295
295
  selectors=selectors,
@@ -407,7 +407,7 @@ class DownloadApp(typer.Typer):
407
407
  )
408
408
 
409
409
  selectors = [DataSetSelector(kind="TimeSeries", data_set_external_id=data_set) for data_set in data_sets]
410
- cmd = DownloadCommand()
410
+ cmd = DownloadCommand(client=client)
411
411
  cmd.run(
412
412
  lambda: cmd.download(
413
413
  selectors=selectors,
@@ -486,7 +486,7 @@ class DownloadApp(typer.Typer):
486
486
  )
487
487
 
488
488
  selectors = [DataSetSelector(kind="Events", data_set_external_id=data_set) for data_set in data_sets]
489
- cmd = DownloadCommand()
489
+ cmd = DownloadCommand(client=client)
490
490
 
491
491
  cmd.run(
492
492
  lambda: cmd.download(
@@ -613,7 +613,7 @@ class DownloadApp(typer.Typer):
613
613
  selectors = [DataSetSelector(kind="FileMetadata", data_set_external_id=data_set) for data_set in data_sets]
614
614
  io = FileMetadataIO(client)
615
615
 
616
- cmd = DownloadCommand()
616
+ cmd = DownloadCommand(client=client)
617
617
  cmd.run(
618
618
  lambda: cmd.download(
619
619
  selectors=selectors, # type: ignore[misc]
@@ -678,9 +678,9 @@ class DownloadApp(typer.Typer):
678
678
  ] = False,
679
679
  ) -> None:
680
680
  """This command will download an asset hierarchy from CDF into a temporary directory."""
681
- cmd = DownloadCommand()
682
-
683
681
  client = EnvironmentVariables.create_from_environment().get_client()
682
+ cmd = DownloadCommand(client=client)
683
+
684
684
  if hierarchy is None:
685
685
  selector = AssetInteractiveSelect(client, "download")
686
686
  hierarchy = selector.select_hierarchy(allow_empty=False)
@@ -782,7 +782,8 @@ class DownloadApp(typer.Typer):
782
782
  ] = False,
783
783
  ) -> None:
784
784
  """This command will download Instances from CDF into a temporary directory."""
785
- cmd = DownloadCommand()
785
+ client = EnvironmentVariables.create_from_environment().get_client()
786
+ cmd = DownloadCommand(client=client)
786
787
 
787
788
  client = EnvironmentVariables.create_from_environment().get_client()
788
789
  if instance_space is None:
@@ -957,7 +958,7 @@ class DownloadApp(typer.Typer):
957
958
  ).unsafe_ask()
958
959
  )
959
960
 
960
- cmd = DownloadCommand()
961
+ cmd = DownloadCommand(client=client)
961
962
  selector = DataPointsDataSetSelector(
962
963
  data_set_external_id=dataset,
963
964
  start=start_time,
@@ -1028,8 +1029,8 @@ class DownloadApp(typer.Typer):
1028
1029
  ] = False,
1029
1030
  ) -> None:
1030
1031
  """This command will download Charts from CDF into a temporary directory."""
1031
- cmd = DownloadCommand()
1032
1032
  client = EnvironmentVariables.create_from_environment().get_client()
1033
+ cmd = DownloadCommand(client=client)
1033
1034
  selector: ChartSelector
1034
1035
  if external_ids is None:
1035
1036
  selected_external_ids = InteractiveChartSelect(client).select_external_ids()
@@ -1101,8 +1102,8 @@ class DownloadApp(typer.Typer):
1101
1102
  ] = False,
1102
1103
  ) -> None:
1103
1104
  """This command will download Canvas from CDF into a temporary directory."""
1104
- cmd = DownloadCommand()
1105
1105
  client = EnvironmentVariables.create_from_environment().get_client()
1106
+ cmd = DownloadCommand(client=client)
1106
1107
  selector: CanvasSelector
1107
1108
  if external_ids is None:
1108
1109
  selected_external_ids = InteractiveCanvasSelect(client).select_external_ids()
@@ -143,7 +143,7 @@ class DumpConfigApp(typer.Typer):
143
143
  selected_data_model = DataModelId(*data_model_id)
144
144
  client = EnvironmentVariables.create_from_environment().get_client()
145
145
 
146
- cmd = DumpResourceCommand()
146
+ cmd = DumpResourceCommand(client=client)
147
147
  cmd.run(
148
148
  lambda: cmd.dump_to_yamls(
149
149
  DataModelFinder(client, selected_data_model, include_global=include_global),
@@ -199,7 +199,7 @@ class DumpConfigApp(typer.Typer):
199
199
  selected_workflow = WorkflowVersionId(*workflow_id)
200
200
  client = EnvironmentVariables.create_from_environment().get_client()
201
201
 
202
- cmd = DumpResourceCommand()
202
+ cmd = DumpResourceCommand(client=client)
203
203
  cmd.run(
204
204
  lambda: cmd.dump_to_yamls(
205
205
  WorkflowFinder(client, selected_workflow),
@@ -248,7 +248,7 @@ class DumpConfigApp(typer.Typer):
248
248
  """This command will dump the selected transformation as yaml to the folder specified, defaults to /tmp."""
249
249
  client = EnvironmentVariables.create_from_environment().get_client()
250
250
 
251
- cmd = DumpResourceCommand()
251
+ cmd = DumpResourceCommand(client=client)
252
252
  cmd.run(
253
253
  lambda: cmd.dump_to_yamls(
254
254
  TransformationFinder(client, tuple(transformation_id) if transformation_id else None),
@@ -297,7 +297,7 @@ class DumpConfigApp(typer.Typer):
297
297
  """This command will dump the selected group as yaml to the folder specified, defaults to /tmp."""
298
298
  client = EnvironmentVariables.create_from_environment().get_client()
299
299
 
300
- cmd = DumpResourceCommand()
300
+ cmd = DumpResourceCommand(client=client)
301
301
  cmd.run(
302
302
  lambda: cmd.dump_to_yamls(
303
303
  GroupFinder(client, tuple(group_name) if group_name else None),
@@ -346,7 +346,7 @@ class DumpConfigApp(typer.Typer):
346
346
  """Dump on or more agents as yaml to the specified folder, defaults to /tmp."""
347
347
 
348
348
  client = EnvironmentVariables.create_from_environment().get_client()
349
- cmd = DumpResourceCommand()
349
+ cmd = DumpResourceCommand(client=client)
350
350
  cmd.run(
351
351
  lambda: cmd.dump_to_yamls(
352
352
  AgentFinder(client, tuple(external_id) if external_id else None),
@@ -405,7 +405,7 @@ class DumpConfigApp(typer.Typer):
405
405
  )
406
406
  selected_view_id = ViewId(*view_id)
407
407
 
408
- cmd = DumpResourceCommand()
408
+ cmd = DumpResourceCommand(client=client)
409
409
  cmd.run(
410
410
  lambda: cmd.dump_to_yamls(
411
411
  NodeFinder(client, selected_view_id),
@@ -453,7 +453,7 @@ class DumpConfigApp(typer.Typer):
453
453
  ) -> None:
454
454
  """This command will dump the selected location filters as yaml to the folder specified, defaults to /tmp."""
455
455
  client = EnvironmentVariables.create_from_environment().get_client()
456
- cmd = DumpResourceCommand()
456
+ cmd = DumpResourceCommand(client=client)
457
457
  cmd.run(
458
458
  lambda: cmd.dump_to_yamls(
459
459
  LocationFilterFinder(client, tuple(external_id) if external_id else None),
@@ -501,7 +501,7 @@ class DumpConfigApp(typer.Typer):
501
501
  ) -> None:
502
502
  """This command will dump the selected extraction pipeline as yaml to the folder specified, defaults to /tmp."""
503
503
  client = EnvironmentVariables.create_from_environment().get_client()
504
- cmd = DumpResourceCommand()
504
+ cmd = DumpResourceCommand(client=client)
505
505
  cmd.run(
506
506
  lambda: cmd.dump_to_yamls(
507
507
  ExtractionPipelineFinder(client, tuple(external_id) if external_id else None),
@@ -549,7 +549,7 @@ class DumpConfigApp(typer.Typer):
549
549
  ) -> None:
550
550
  """This command will dump the selected datasets as yaml to the folder specified, defaults to /tmp."""
551
551
  client = EnvironmentVariables.create_from_environment().get_client()
552
- cmd = DumpResourceCommand()
552
+ cmd = DumpResourceCommand(client=client)
553
553
  cmd.run(
554
554
  lambda: cmd.dump_to_yamls(
555
555
  DataSetFinder(client, tuple(external_id) if external_id else None),
@@ -597,7 +597,7 @@ class DumpConfigApp(typer.Typer):
597
597
  ) -> None:
598
598
  """This command will dump the selected functions as yaml to the folder specified, defaults to /tmp."""
599
599
  client = EnvironmentVariables.create_from_environment().get_client()
600
- cmd = DumpResourceCommand()
600
+ cmd = DumpResourceCommand(client=client)
601
601
  cmd.run(
602
602
  lambda: cmd.dump_to_yamls(
603
603
  FunctionFinder(client, tuple(external_id) if external_id else None),
@@ -645,7 +645,7 @@ class DumpConfigApp(typer.Typer):
645
645
  ) -> None:
646
646
  """This command will dump the selected Streamlit apps as yaml to the folder specified, defaults to /tmp."""
647
647
  client = EnvironmentVariables.create_from_environment().get_client()
648
- cmd = DumpResourceCommand()
648
+ cmd = DumpResourceCommand(client=client)
649
649
  cmd.run(
650
650
  lambda: cmd.dump_to_yamls(
651
651
  StreamlitFinder(client, tuple(external_id) if external_id else None),
@@ -693,7 +693,7 @@ class DumpConfigApp(typer.Typer):
693
693
  ) -> None:
694
694
  """This command will dump the selected instance spaces as yaml to the folder specified, defaults to /tmp."""
695
695
  client = EnvironmentVariables.create_from_environment().get_client()
696
- cmd = DumpResourceCommand()
696
+ cmd = DumpResourceCommand(client=client)
697
697
  cmd.run(
698
698
  lambda: cmd.dump_to_yamls(
699
699
  SpaceFinder(client, tuple(spaces) if spaces else None),
@@ -748,7 +748,7 @@ class DumpConfigApp(typer.Typer):
748
748
  "View ID must be provided as exactly two arguments: externalId and space."
749
749
  )
750
750
  selected_view_id = SearchConfigViewId(*view_id)
751
- cmd = DumpResourceCommand()
751
+ cmd = DumpResourceCommand(client=client)
752
752
  cmd.run(
753
753
  lambda: cmd.dump_to_yamls(
754
754
  SearchConfigFinder(client, tuple([selected_view_id]) if selected_view_id else None),
@@ -1,8 +1,11 @@
1
+ import contextlib
1
2
  from typing import Annotated
2
3
 
3
4
  import typer
4
5
 
6
+ from cognite_toolkit._cdf_tk.client import ToolkitClient
5
7
  from cognite_toolkit._cdf_tk.commands import InitCommand
8
+ from cognite_toolkit._cdf_tk.utils.auth import EnvironmentVariables
6
9
 
7
10
 
8
11
  class LandingApp(typer.Typer):
@@ -21,7 +24,13 @@ class LandingApp(typer.Typer):
21
24
  ] = False,
22
25
  ) -> None:
23
26
  """Getting started checklist"""
24
- cmd = InitCommand()
27
+ client: ToolkitClient | None = None
28
+ with contextlib.redirect_stdout(None), contextlib.suppress(Exception):
29
+ # Remove the Error message from failing to load the config
30
+ # This is verified in check_auth
31
+ client = EnvironmentVariables.create_from_environment().get_client()
32
+
33
+ cmd = InitCommand(client=client)
25
34
  # Tracking command with the usual lambda run construct
26
35
  # is intentionally left out because we don't want to expose the user to the warning
27
36
  # before they've had the chance to opt in (which is something they'll do later using this command).
@@ -108,7 +108,7 @@ class MigrateApp(typer.Typer):
108
108
  depend on the primary resources 3D and annotations.
109
109
  """
110
110
  client = EnvironmentVariables.create_from_environment().get_client(enable_set_pending_ids=True)
111
- cmd = MigrationPrepareCommand()
111
+ cmd = MigrationPrepareCommand(client=client)
112
112
  cmd.run(
113
113
  lambda: cmd.deploy_cognite_migration(
114
114
  client,
@@ -167,7 +167,7 @@ class MigrateApp(typer.Typer):
167
167
  )
168
168
  verbose = questionary.confirm("Do you want verbose output?", default=verbose).unsafe_ask()
169
169
 
170
- cmd = MigrationCommand()
170
+ cmd = MigrationCommand(client=client)
171
171
  cmd.run(
172
172
  lambda: cmd.create(
173
173
  client,
@@ -244,7 +244,7 @@ class MigrateApp(typer.Typer):
244
244
  elif data_set is None or instance_space is None:
245
245
  raise typer.BadParameter("Both data_set and instance_space must be provided together.")
246
246
 
247
- cmd = MigrationCommand()
247
+ cmd = MigrationCommand(client=client)
248
248
  cmd.run(
249
249
  lambda: cmd.create(
250
250
  client,
@@ -337,7 +337,7 @@ class MigrateApp(typer.Typer):
337
337
  container_id=ContainerId("cdf_cdm", "CogniteAsset"),
338
338
  )
339
339
 
340
- cmd = MigrationCommand()
340
+ cmd = MigrationCommand(client=client)
341
341
  cmd.run(
342
342
  lambda: cmd.migrate(
343
343
  selected=selected,
@@ -484,7 +484,7 @@ class MigrateApp(typer.Typer):
484
484
  container_id=ContainerId("cdf_cdm", "CogniteActivity"),
485
485
  )
486
486
 
487
- cmd = MigrationCommand()
487
+ cmd = MigrationCommand(client=client)
488
488
 
489
489
  cmd.run(
490
490
  lambda: cmd.migrate(
@@ -592,7 +592,7 @@ class MigrateApp(typer.Typer):
592
592
  "Do you want to link old and new TimeSeries?", default=not skip_linking
593
593
  ).unsafe_ask()
594
594
 
595
- cmd = MigrationCommand()
595
+ cmd = MigrationCommand(client=client)
596
596
  cmd.run(
597
597
  lambda: cmd.migrate(
598
598
  selected=selected,
@@ -694,7 +694,7 @@ class MigrateApp(typer.Typer):
694
694
  resource_type="file",
695
695
  container_id=ContainerId("cdf_cdm", "CogniteFile"),
696
696
  )
697
- cmd = MigrationCommand()
697
+ cmd = MigrationCommand(client=client)
698
698
 
699
699
  if data_set_id is None:
700
700
  skip_linking = not questionary.confirm(
@@ -841,7 +841,7 @@ class MigrateApp(typer.Typer):
841
841
  dry_run = questionary.confirm("Do you want to perform a dry run?", default=dry_run).unsafe_ask()
842
842
  verbose = questionary.confirm("Do you want verbose output?", default=verbose).unsafe_ask()
843
843
 
844
- cmd = MigrationCommand()
844
+ cmd = MigrationCommand(client=client)
845
845
  cmd.run(
846
846
  lambda: cmd.migrate(
847
847
  selected=selected,
@@ -914,7 +914,7 @@ class MigrateApp(typer.Typer):
914
914
  dry_run = questionary.confirm("Do you want to perform a dry run?", default=dry_run).unsafe_ask()
915
915
  verbose = questionary.confirm("Do you want verbose output?", default=verbose).unsafe_ask()
916
916
 
917
- cmd = MigrationCommand()
917
+ cmd = MigrationCommand(client=client)
918
918
  selector = CanvasExternalIdSelector(external_ids=tuple(external_id))
919
919
  cmd.run(
920
920
  lambda: cmd.migrate(
@@ -977,7 +977,7 @@ class MigrateApp(typer.Typer):
977
977
  else:
978
978
  selected_external_ids = InteractiveChartSelect(client).select_external_ids()
979
979
 
980
- cmd = MigrationCommand()
980
+ cmd = MigrationCommand(client=client)
981
981
  cmd.run(
982
982
  lambda: cmd.migrate(
983
983
  selected=ChartExternalIdSelector(external_ids=tuple(selected_external_ids)),
@@ -1039,7 +1039,7 @@ class MigrateApp(typer.Typer):
1039
1039
  selected_models = ThreeDInteractiveSelect(client, "migrate").select_three_d_models("classic")
1040
1040
  selected_ids = [model.id for model in selected_models]
1041
1041
 
1042
- cmd = MigrationCommand()
1042
+ cmd = MigrationCommand(client=client)
1043
1043
  cmd.run(
1044
1044
  lambda: cmd.migrate(
1045
1045
  selected=ThreeDModelIdSelector(ids=tuple(selected_ids)),
@@ -1118,12 +1118,12 @@ class MigrateApp(typer.Typer):
1118
1118
  object_3D_space = space_selector.select_instance_space(
1119
1119
  multiselect=False,
1120
1120
  message="In which instance space do you want to create the 3D Object nodes?",
1121
- include_empty=False,
1121
+ include_empty=True,
1122
1122
  )
1123
1123
  cad_node_space = space_selector.select_instance_space(
1124
1124
  multiselect=False,
1125
1125
  message="In which instance space do you want to create the CAD Node nodes?",
1126
- include_empty=False,
1126
+ include_empty=True,
1127
1127
  )
1128
1128
  dry_run = questionary.confirm("Do you want to perform a dry run?", default=dry_run).unsafe_ask()
1129
1129
  verbose = questionary.confirm("Do you want verbose output?", default=verbose).unsafe_ask()
@@ -1133,7 +1133,7 @@ class MigrateApp(typer.Typer):
1133
1133
  "--object-3d-space and --cad-node-space are required when specifying IDs directly."
1134
1134
  )
1135
1135
 
1136
- cmd = MigrationCommand()
1136
+ cmd = MigrationCommand(client=client)
1137
1137
  cmd.run(
1138
1138
  lambda: cmd.migrate(
1139
1139
  selected=ThreeDModelIdSelector(ids=tuple(selected_ids)),
@@ -1179,7 +1179,7 @@ class MigrateApp(typer.Typer):
1179
1179
  """Creates Infield V2 configurations from existing APM Configurations in CDF."""
1180
1180
  client = EnvironmentVariables.create_from_environment().get_client()
1181
1181
 
1182
- cmd = MigrationCommand()
1182
+ cmd = MigrationCommand(client=client)
1183
1183
  cmd.run(
1184
1184
  lambda: cmd.create(
1185
1185
  client,
@@ -1,3 +1,4 @@
1
+ import contextlib
1
2
  from pathlib import Path
2
3
  from typing import Annotated
3
4
 
@@ -5,6 +6,7 @@ import typer
5
6
  from rich import print
6
7
 
7
8
  from cognite_toolkit._cdf_tk.cdf_toml import CDFToml
9
+ from cognite_toolkit._cdf_tk.client import ToolkitClient
8
10
  from cognite_toolkit._cdf_tk.commands import ModulesCommand, PullCommand
9
11
  from cognite_toolkit._cdf_tk.utils.auth import EnvironmentVariables
10
12
  from cognite_toolkit._version import __version__
@@ -77,6 +79,11 @@ class ModulesApp(typer.Typer):
77
79
  ] = False,
78
80
  ) -> None:
79
81
  """Initialize or upgrade a new CDF project with templates interactively."""
82
+ client: ToolkitClient | None = None
83
+ with contextlib.redirect_stdout(None), contextlib.suppress(Exception):
84
+ # Try to load client if possible, but ignore errors.
85
+ # This is only used for logging purposes in the command.
86
+ client = EnvironmentVariables.create_from_environment().get_client()
80
87
 
81
88
  if library_url and not library_checksum:
82
89
  raise typer.BadParameter(
@@ -84,7 +91,7 @@ class ModulesApp(typer.Typer):
84
91
  param_hint="--library-checksum",
85
92
  )
86
93
 
87
- with ModulesCommand() as cmd:
94
+ with ModulesCommand(client=client) as cmd:
88
95
  cmd.run(
89
96
  lambda: cmd.init(
90
97
  organization_dir=organization_dir,
@@ -114,7 +121,13 @@ class ModulesApp(typer.Typer):
114
121
  ),
115
122
  ] = False,
116
123
  ) -> None:
117
- cmd = ModulesCommand()
124
+ client: ToolkitClient | None = None
125
+ with contextlib.redirect_stdout(None), contextlib.suppress(Exception):
126
+ # Try to load client if possible, but ignore errors.
127
+ # This is only used for logging purposes in the command.
128
+ client = EnvironmentVariables.create_from_environment().get_client()
129
+
130
+ cmd = ModulesCommand(client=client)
118
131
  cmd.run(lambda: cmd.upgrade(organization_dir=organization_dir, verbose=verbose))
119
132
 
120
133
  # This is a trick to use an f-string for the docstring
@@ -140,7 +153,12 @@ class ModulesApp(typer.Typer):
140
153
  ] = False,
141
154
  ) -> None:
142
155
  """Add one or more new module(s) to the project."""
143
- with ModulesCommand() as cmd:
156
+ client: ToolkitClient | None = None
157
+ with contextlib.redirect_stdout(None), contextlib.suppress(Exception):
158
+ # Try to load client if possible, but ignore errors.
159
+ # This is only used for logging purposes in the command.
160
+ client = EnvironmentVariables.create_from_environment().get_client()
161
+ with ModulesCommand(client=client) as cmd:
144
162
  cmd.run(lambda: cmd.add(organization_dir=organization_dir))
145
163
 
146
164
  def pull(
@@ -187,8 +205,8 @@ class ModulesApp(typer.Typer):
187
205
  ] = False,
188
206
  ) -> None:
189
207
  """Pull a module from CDF. This will overwrite the local files with the latest version from CDF."""
190
- cmd = PullCommand()
191
208
  env_vars = EnvironmentVariables.create_from_environment()
209
+ cmd = PullCommand(client=env_vars.get_client())
192
210
  cmd.run(
193
211
  lambda: cmd.pull_module(
194
212
  module_name_or_path=module_name_or_path,
@@ -227,5 +245,11 @@ class ModulesApp(typer.Typer):
227
245
  ] = False,
228
246
  ) -> None:
229
247
  """List all available modules in the project."""
230
- cmd = ModulesCommand()
248
+ client: ToolkitClient | None = None
249
+ with contextlib.redirect_stdout(None), contextlib.suppress(Exception):
250
+ # Try to load client if possible, but ignore errors.
251
+ # This is only used for logging purposes in the command.
252
+ client = EnvironmentVariables.create_from_environment().get_client()
253
+
254
+ cmd = ModulesCommand(client=client)
231
255
  cmd.run(lambda: cmd.list(organization_dir=organization_dir, build_env_name=build_env))
@@ -55,7 +55,7 @@ class ProfileApp(typer.Typer):
55
55
  these data sets, and the RAW tables that is used in these transformations.
56
56
  """
57
57
  client = EnvironmentVariables.create_from_environment().get_client()
58
- cmd = ProfileAssetCommand(output_spreadsheet)
58
+ cmd = ProfileAssetCommand(output_spreadsheet, client=client)
59
59
  cmd.run(
60
60
  lambda: cmd.assets(
61
61
  client=client,
@@ -90,7 +90,7 @@ class ProfileApp(typer.Typer):
90
90
  This shows an approximation of unstructured data count. This can, for example, be used to estimate the
91
91
  effort to model this data in data modeling."""
92
92
  client = EnvironmentVariables.create_from_environment().get_client()
93
- cmd = ProfileAssetCentricCommand(output_spreadsheet)
93
+ cmd = ProfileAssetCentricCommand(output_spreadsheet, client=client)
94
94
  cmd.run(
95
95
  lambda: cmd.asset_centric(
96
96
  client,
@@ -127,7 +127,7 @@ class ProfileApp(typer.Typer):
127
127
  source of the data in a specific CDF resource.
128
128
  """
129
129
  client = EnvironmentVariables.create_from_environment().get_client()
130
- cmd = ProfileTransformationCommand(output_spreadsheet)
130
+ cmd = ProfileTransformationCommand(output_spreadsheet, client=client)
131
131
  cmd.run(
132
132
  lambda: cmd.transformation(
133
133
  client,
@@ -165,7 +165,7 @@ class ProfileApp(typer.Typer):
165
165
  source of the data in a specific CDF resource.
166
166
  """
167
167
  client = EnvironmentVariables.create_from_environment().get_client()
168
- cmd = ProfileRawCommand(output_spreadsheet)
168
+ cmd = ProfileRawCommand(output_spreadsheet, client=client)
169
169
  cmd.run(
170
170
  lambda: cmd.raw(
171
171
  client,
@@ -106,8 +106,8 @@ class PurgeApp(typer.Typer):
106
106
  ] = False,
107
107
  ) -> None:
108
108
  """This command will delete the contents of the specified dataset"""
109
- cmd = PurgeCommand()
110
109
  client = EnvironmentVariables.create_from_environment().get_client()
110
+ cmd = PurgeCommand(client=client)
111
111
 
112
112
  if external_id is None:
113
113
  # Is Interactive
@@ -203,9 +203,8 @@ class PurgeApp(typer.Typer):
203
203
  ] = False,
204
204
  ) -> None:
205
205
  """This command will delete the contents of the specified space."""
206
-
207
- cmd = PurgeCommand()
208
206
  client = EnvironmentVariables.create_from_environment().get_client()
207
+ cmd = PurgeCommand(client=client)
209
208
 
210
209
  if space is None:
211
210
  # Is Interactive
@@ -319,9 +318,9 @@ class PurgeApp(typer.Typer):
319
318
  ] = False,
320
319
  ) -> None:
321
320
  """This command will delete the contents of the specified instances."""
322
-
323
- cmd = PurgeCommand()
324
321
  client = EnvironmentVariables.create_from_environment().get_client(enable_set_pending_ids=True)
322
+ cmd = PurgeCommand(client=client)
323
+
325
324
  is_interactive = view is None and instance_list is None
326
325
  selector: InstanceSelector
327
326
  if is_interactive:
@@ -1,12 +1,15 @@
1
+ import contextlib
1
2
  from pathlib import Path
2
3
  from typing import Annotated
3
4
 
4
5
  import typer
5
6
  from rich import print
6
7
 
8
+ from cognite_toolkit._cdf_tk.client import ToolkitClient
7
9
  from cognite_toolkit._cdf_tk.commands import RepoCommand
8
10
  from cognite_toolkit._cdf_tk.commands.repo import REPOSITORY_HOSTING
9
11
  from cognite_toolkit._cdf_tk.utils import humanize_collection
12
+ from cognite_toolkit._cdf_tk.utils.auth import EnvironmentVariables
10
13
 
11
14
 
12
15
  class RepoApp(typer.Typer):
@@ -37,6 +40,10 @@ class RepoApp(typer.Typer):
37
40
  verbose: bool = typer.Option(False, "-v", "--verbose", help="Verbose output"),
38
41
  ) -> None:
39
42
  """Initialize a new git repository with files like .gitignore, cdf.toml, and so on."""
40
-
41
- cmd = RepoCommand()
43
+ client: ToolkitClient | None = None
44
+ with contextlib.redirect_stdout(None), contextlib.suppress(Exception):
45
+ # Try to load client if possible, but ignore errors.
46
+ # This is only used for logging purposes in the command.
47
+ client = EnvironmentVariables.create_from_environment().get_client()
48
+ cmd = RepoCommand(client=client)
42
49
  cmd.run(lambda: cmd.init(cwd=cwd, host=host, verbose=verbose))
@@ -58,8 +58,9 @@ class RunApp(typer.Typer):
58
58
  ) -> None:
59
59
  """This command will run the specified transformation using a one-time session."""
60
60
  RunApp._print_deprecation_warning()
61
- cmd = RunTransformationCommand()
62
61
  client = EnvironmentVariables.create_from_environment().get_client()
62
+ cmd = RunTransformationCommand(client=client)
63
+
63
64
  cmd.run(lambda: cmd.run_transformation(client, external_id))
64
65
 
65
66
  @staticmethod
@@ -116,8 +117,8 @@ class RunApp(typer.Typer):
116
117
  ) -> None:
117
118
  """This command will run the specified workflow."""
118
119
  RunApp._print_deprecation_warning()
119
- cmd = RunWorkflowCommand()
120
120
  env_vars = EnvironmentVariables.create_from_environment()
121
+ cmd = RunWorkflowCommand(client=env_vars.get_client())
121
122
  cmd.run(lambda: cmd.run_workflow(env_vars, organization_dir, env_name, external_id, version, wait))
122
123
 
123
124
 
@@ -188,8 +189,8 @@ class RunFunctionApp(typer.Typer):
188
189
  ) -> None:
189
190
  """This command will run the specified function locally."""
190
191
  RunApp._print_deprecation_warning()
191
- cmd = RunFunctionCommand()
192
192
  env_vars = EnvironmentVariables.create_from_environment()
193
+ cmd = RunFunctionCommand(client=env_vars.get_client())
193
194
  cmd.run(
194
195
  lambda: cmd.run_local(
195
196
  env_vars,
@@ -254,6 +255,6 @@ class RunFunctionApp(typer.Typer):
254
255
  ) -> None:
255
256
  """This command will run the specified function (assuming it is deployed) in CDF."""
256
257
  RunApp._print_deprecation_warning()
257
- cmd = RunFunctionCommand()
258
258
  env_vars = EnvironmentVariables.create_from_environment()
259
+ cmd = RunFunctionCommand(client=env_vars.get_client())
259
260
  cmd.run(lambda: cmd.run_cdf(env_vars, organization_dir, env_name, external_id, schedule, wait))