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.
- cognite_toolkit/_cdf.py +16 -17
- cognite_toolkit/_cdf_tk/apps/__init__.py +2 -0
- cognite_toolkit/_cdf_tk/apps/_core_app.py +13 -5
- cognite_toolkit/_cdf_tk/apps/_data_app.py +1 -1
- cognite_toolkit/_cdf_tk/apps/_dev_app.py +86 -0
- cognite_toolkit/_cdf_tk/apps/_download_app.py +692 -24
- cognite_toolkit/_cdf_tk/apps/_dump_app.py +43 -101
- cognite_toolkit/_cdf_tk/apps/_landing_app.py +18 -4
- cognite_toolkit/_cdf_tk/apps/_migrate_app.py +249 -9
- cognite_toolkit/_cdf_tk/apps/_modules_app.py +0 -3
- cognite_toolkit/_cdf_tk/apps/_purge.py +15 -43
- cognite_toolkit/_cdf_tk/apps/_run.py +11 -0
- cognite_toolkit/_cdf_tk/apps/_upload_app.py +45 -6
- cognite_toolkit/_cdf_tk/builders/__init__.py +2 -2
- cognite_toolkit/_cdf_tk/builders/_base.py +28 -42
- cognite_toolkit/_cdf_tk/cdf_toml.py +20 -1
- cognite_toolkit/_cdf_tk/client/_toolkit_client.py +23 -3
- cognite_toolkit/_cdf_tk/client/api/extended_functions.py +6 -9
- cognite_toolkit/_cdf_tk/client/api/infield.py +93 -1
- cognite_toolkit/_cdf_tk/client/api/migration.py +175 -1
- cognite_toolkit/_cdf_tk/client/api/streams.py +84 -0
- cognite_toolkit/_cdf_tk/client/api/three_d.py +50 -0
- cognite_toolkit/_cdf_tk/client/data_classes/base.py +25 -1
- cognite_toolkit/_cdf_tk/client/data_classes/canvas.py +46 -3
- cognite_toolkit/_cdf_tk/client/data_classes/charts.py +3 -3
- cognite_toolkit/_cdf_tk/client/data_classes/charts_data.py +95 -213
- cognite_toolkit/_cdf_tk/client/data_classes/infield.py +32 -18
- cognite_toolkit/_cdf_tk/client/data_classes/migration.py +10 -2
- cognite_toolkit/_cdf_tk/client/data_classes/streams.py +90 -0
- cognite_toolkit/_cdf_tk/client/data_classes/three_d.py +47 -0
- cognite_toolkit/_cdf_tk/client/testing.py +18 -2
- cognite_toolkit/_cdf_tk/commands/__init__.py +6 -6
- cognite_toolkit/_cdf_tk/commands/_changes.py +3 -42
- cognite_toolkit/_cdf_tk/commands/_download.py +21 -11
- cognite_toolkit/_cdf_tk/commands/_migrate/__init__.py +0 -2
- cognite_toolkit/_cdf_tk/commands/_migrate/command.py +22 -20
- cognite_toolkit/_cdf_tk/commands/_migrate/conversion.py +133 -91
- cognite_toolkit/_cdf_tk/commands/_migrate/data_classes.py +73 -22
- cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py +311 -43
- cognite_toolkit/_cdf_tk/commands/_migrate/default_mappings.py +5 -5
- cognite_toolkit/_cdf_tk/commands/_migrate/issues.py +33 -0
- cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py +157 -8
- cognite_toolkit/_cdf_tk/commands/_migrate/selectors.py +9 -4
- cognite_toolkit/_cdf_tk/commands/_purge.py +27 -28
- cognite_toolkit/_cdf_tk/commands/_questionary_style.py +16 -0
- cognite_toolkit/_cdf_tk/commands/_upload.py +109 -86
- cognite_toolkit/_cdf_tk/commands/about.py +221 -0
- cognite_toolkit/_cdf_tk/commands/auth.py +19 -12
- cognite_toolkit/_cdf_tk/commands/build_cmd.py +15 -61
- cognite_toolkit/_cdf_tk/commands/clean.py +63 -16
- cognite_toolkit/_cdf_tk/commands/deploy.py +20 -17
- cognite_toolkit/_cdf_tk/commands/dump_resource.py +6 -4
- cognite_toolkit/_cdf_tk/commands/init.py +225 -3
- cognite_toolkit/_cdf_tk/commands/modules.py +20 -44
- cognite_toolkit/_cdf_tk/commands/pull.py +6 -19
- cognite_toolkit/_cdf_tk/commands/resources.py +179 -0
- cognite_toolkit/_cdf_tk/constants.py +20 -1
- cognite_toolkit/_cdf_tk/cruds/__init__.py +19 -5
- cognite_toolkit/_cdf_tk/cruds/_base_cruds.py +14 -70
- cognite_toolkit/_cdf_tk/cruds/_data_cruds.py +8 -17
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/__init__.py +4 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/agent.py +11 -9
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/auth.py +4 -14
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/classic.py +44 -43
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/configuration.py +4 -11
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/data_organization.py +4 -13
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/datamodel.py +205 -66
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/extraction_pipeline.py +5 -17
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/fieldops.py +116 -27
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/file.py +6 -27
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/function.py +9 -28
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/hosted_extractors.py +12 -30
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/industrial_tool.py +3 -7
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/location.py +3 -15
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/migration.py +4 -12
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/raw.py +4 -10
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/relationship.py +3 -8
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/robotics.py +15 -44
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/streams.py +94 -0
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/three_d_model.py +3 -7
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/timeseries.py +5 -15
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/transformation.py +39 -31
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/workflow.py +20 -40
- cognite_toolkit/_cdf_tk/cruds/_worker.py +24 -36
- cognite_toolkit/_cdf_tk/feature_flags.py +16 -36
- cognite_toolkit/_cdf_tk/plugins.py +2 -1
- cognite_toolkit/_cdf_tk/resource_classes/__init__.py +4 -0
- cognite_toolkit/_cdf_tk/resource_classes/capabilities.py +12 -0
- cognite_toolkit/_cdf_tk/resource_classes/functions.py +3 -1
- cognite_toolkit/_cdf_tk/resource_classes/infield_cdm_location_config.py +109 -0
- cognite_toolkit/_cdf_tk/resource_classes/migration.py +8 -17
- cognite_toolkit/_cdf_tk/resource_classes/streams.py +29 -0
- cognite_toolkit/_cdf_tk/storageio/__init__.py +9 -21
- cognite_toolkit/_cdf_tk/storageio/_annotations.py +19 -16
- cognite_toolkit/_cdf_tk/storageio/_applications.py +338 -26
- cognite_toolkit/_cdf_tk/storageio/_asset_centric.py +67 -104
- cognite_toolkit/_cdf_tk/storageio/_base.py +61 -29
- cognite_toolkit/_cdf_tk/storageio/_datapoints.py +276 -20
- cognite_toolkit/_cdf_tk/storageio/_file_content.py +436 -0
- cognite_toolkit/_cdf_tk/storageio/_instances.py +34 -2
- cognite_toolkit/_cdf_tk/storageio/_raw.py +26 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/__init__.py +62 -4
- cognite_toolkit/_cdf_tk/storageio/selectors/_base.py +14 -2
- cognite_toolkit/_cdf_tk/storageio/selectors/_canvas.py +14 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/_charts.py +14 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/_datapoints.py +23 -3
- cognite_toolkit/_cdf_tk/storageio/selectors/_file_content.py +164 -0
- cognite_toolkit/_cdf_tk/tk_warnings/other.py +4 -0
- cognite_toolkit/_cdf_tk/tracker.py +2 -2
- cognite_toolkit/_cdf_tk/utils/dtype_conversion.py +9 -3
- cognite_toolkit/_cdf_tk/utils/fileio/__init__.py +2 -0
- cognite_toolkit/_cdf_tk/utils/fileio/_base.py +5 -1
- cognite_toolkit/_cdf_tk/utils/fileio/_readers.py +112 -20
- cognite_toolkit/_cdf_tk/utils/fileio/_writers.py +15 -15
- cognite_toolkit/_cdf_tk/utils/http_client/_client.py +284 -18
- cognite_toolkit/_cdf_tk/utils/http_client/_data_classes.py +50 -4
- cognite_toolkit/_cdf_tk/utils/http_client/_data_classes2.py +187 -0
- cognite_toolkit/_cdf_tk/utils/interactive_select.py +9 -14
- cognite_toolkit/_cdf_tk/utils/sql_parser.py +2 -3
- cognite_toolkit/_cdf_tk/utils/useful_types.py +6 -2
- cognite_toolkit/_cdf_tk/validation.py +79 -1
- cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml +1 -1
- cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml +1 -1
- cognite_toolkit/_resources/cdf.toml +5 -4
- cognite_toolkit/_version.py +1 -1
- cognite_toolkit/config.dev.yaml +13 -0
- {cognite_toolkit-0.6.97.dist-info → cognite_toolkit-0.7.30.dist-info}/METADATA +24 -24
- {cognite_toolkit-0.6.97.dist-info → cognite_toolkit-0.7.30.dist-info}/RECORD +153 -143
- cognite_toolkit-0.7.30.dist-info/WHEEL +4 -0
- {cognite_toolkit-0.6.97.dist-info → cognite_toolkit-0.7.30.dist-info}/entry_points.txt +1 -0
- cognite_toolkit/_cdf_tk/commands/_migrate/canvas.py +0 -201
- cognite_toolkit/_cdf_tk/commands/dump_data.py +0 -489
- cognite_toolkit/_cdf_tk/commands/featureflag.py +0 -27
- cognite_toolkit/_cdf_tk/utils/table_writers.py +0 -434
- cognite_toolkit-0.6.97.dist-info/WHEEL +0 -4
- cognite_toolkit-0.6.97.dist-info/licenses/LICENSE +0 -18
|
@@ -21,7 +21,7 @@ from .api.extended_files import ExtendedFileMetadataAPI
|
|
|
21
21
|
from .api.extended_functions import ExtendedFunctionsAPI
|
|
22
22
|
from .api.extended_raw import ExtendedRawAPI
|
|
23
23
|
from .api.extended_timeseries import ExtendedTimeSeriesAPI
|
|
24
|
-
from .api.infield import InfieldAPI, InfieldConfigAPI
|
|
24
|
+
from .api.infield import InfieldAPI, InFieldCDMConfigAPI, InfieldConfigAPI
|
|
25
25
|
from .api.location_filters import LocationFiltersAPI
|
|
26
26
|
from .api.lookup import (
|
|
27
27
|
AssetLookUpAPI,
|
|
@@ -35,7 +35,14 @@ from .api.lookup import (
|
|
|
35
35
|
SecurityCategoriesLookUpAPI,
|
|
36
36
|
TimeSeriesLookUpAPI,
|
|
37
37
|
)
|
|
38
|
-
from .api.migration import
|
|
38
|
+
from .api.migration import (
|
|
39
|
+
CreatedSourceSystemAPI,
|
|
40
|
+
InstanceSourceAPI,
|
|
41
|
+
LookupAPI,
|
|
42
|
+
MigrationAPI,
|
|
43
|
+
MigrationLookupAPI,
|
|
44
|
+
ResourceViewMappingAPI,
|
|
45
|
+
)
|
|
39
46
|
from .api.project import ProjectAPI
|
|
40
47
|
from .api.robotics import RoboticsAPI
|
|
41
48
|
from .api.robotics.capabilities import CapabilitiesAPI
|
|
@@ -45,6 +52,7 @@ from .api.robotics.locations import LocationsAPI as RoboticsLocationsAPI
|
|
|
45
52
|
from .api.robotics.maps import MapsAPI
|
|
46
53
|
from .api.search import SearchAPI
|
|
47
54
|
from .api.search_config import SearchConfigurationsAPI
|
|
55
|
+
from .api.streams import StreamsAPI
|
|
48
56
|
from .api.token import TokenAPI
|
|
49
57
|
from .api.verify import VerifyAPI
|
|
50
58
|
|
|
@@ -76,6 +84,7 @@ class ToolkitClientMock(CogniteClientMock):
|
|
|
76
84
|
self.functions.schedules = MagicMock(spec_set=FunctionSchedulesAPI)
|
|
77
85
|
self.infield = MagicMock(spec=InfieldAPI)
|
|
78
86
|
self.infield.config = MagicMock(spec_set=InfieldConfigAPI)
|
|
87
|
+
self.infield.cdm_config = MagicMock(spec_set=InFieldCDMConfigAPI)
|
|
79
88
|
|
|
80
89
|
self.project = MagicMock(spec_set=ProjectAPI)
|
|
81
90
|
|
|
@@ -95,6 +104,11 @@ class ToolkitClientMock(CogniteClientMock):
|
|
|
95
104
|
self.lookup.functions = MagicMock(spec_set=FunctionLookUpAPI)
|
|
96
105
|
self.migration = MagicMock(spec=MigrationAPI)
|
|
97
106
|
self.migration.instance_source = MagicMock(spec_set=InstanceSourceAPI)
|
|
107
|
+
self.migration.lookup = MagicMock(spec=MigrationLookupAPI)
|
|
108
|
+
self.migration.lookup.assets = MagicMock(spec_set=LookupAPI)
|
|
109
|
+
self.migration.lookup.events = MagicMock(spec_set=LookupAPI)
|
|
110
|
+
self.migration.lookup.files = MagicMock(spec_set=LookupAPI)
|
|
111
|
+
self.migration.lookup.time_series = MagicMock(spec_set=LookupAPI)
|
|
98
112
|
self.migration.resource_view_mapping = MagicMock(spec_set=ResourceViewMappingAPI)
|
|
99
113
|
self.migration.created_source_system = MagicMock(spec_set=CreatedSourceSystemAPI)
|
|
100
114
|
self.raw = MagicMock(spec=ExtendedRawAPI)
|
|
@@ -117,6 +131,8 @@ class ToolkitClientMock(CogniteClientMock):
|
|
|
117
131
|
self.time_series.data.synthetic = MagicMock(spec_set=SyntheticDatapointsAPI)
|
|
118
132
|
self.time_series.subscriptions = MagicMock(spec_set=DatapointsSubscriptionAPI)
|
|
119
133
|
|
|
134
|
+
self.streams = MagicMock(spec=StreamsAPI)
|
|
135
|
+
|
|
120
136
|
# This is a helper API, not a real API.
|
|
121
137
|
self.token = TokenAPI(self)
|
|
122
138
|
self.verify = MagicMock(spec_set=VerifyAPI)
|
|
@@ -1,37 +1,36 @@
|
|
|
1
1
|
from ._download import DownloadCommand
|
|
2
2
|
from ._migrate import (
|
|
3
|
-
|
|
3
|
+
MigrationCommand,
|
|
4
4
|
MigrationPrepareCommand,
|
|
5
5
|
)
|
|
6
6
|
from ._profile import ProfileAssetCentricCommand, ProfileAssetCommand, ProfileRawCommand, ProfileTransformationCommand
|
|
7
7
|
from ._purge import PurgeCommand
|
|
8
8
|
from ._upload import UploadCommand
|
|
9
|
+
from .about import AboutCommand
|
|
9
10
|
from .auth import AuthCommand
|
|
10
11
|
from .build_cmd import BuildCommand
|
|
11
12
|
from .clean import CleanCommand
|
|
12
13
|
from .collect import CollectCommand
|
|
13
14
|
from .deploy import DeployCommand
|
|
14
|
-
from .dump_data import DumpDataCommand
|
|
15
15
|
from .dump_resource import DumpResourceCommand
|
|
16
|
-
from .featureflag import FeatureFlagCommand
|
|
17
16
|
from .init import InitCommand
|
|
18
17
|
from .modules import ModulesCommand
|
|
19
18
|
from .pull import PullCommand
|
|
20
19
|
from .repo import RepoCommand
|
|
20
|
+
from .resources import ResourcesCommand
|
|
21
21
|
from .run import RunFunctionCommand, RunTransformationCommand, RunWorkflowCommand
|
|
22
22
|
|
|
23
23
|
__all__ = [
|
|
24
|
+
"AboutCommand",
|
|
24
25
|
"AuthCommand",
|
|
25
26
|
"BuildCommand",
|
|
26
27
|
"CleanCommand",
|
|
27
28
|
"CollectCommand",
|
|
28
29
|
"DeployCommand",
|
|
29
30
|
"DownloadCommand",
|
|
30
|
-
"DumpDataCommand",
|
|
31
31
|
"DumpResourceCommand",
|
|
32
|
-
"FeatureFlagCommand",
|
|
33
32
|
"InitCommand",
|
|
34
|
-
"
|
|
33
|
+
"MigrationCommand",
|
|
35
34
|
"MigrationPrepareCommand",
|
|
36
35
|
"ModulesCommand",
|
|
37
36
|
"ProfileAssetCentricCommand",
|
|
@@ -41,6 +40,7 @@ __all__ = [
|
|
|
41
40
|
"PullCommand",
|
|
42
41
|
"PurgeCommand",
|
|
43
42
|
"RepoCommand",
|
|
43
|
+
"ResourcesCommand",
|
|
44
44
|
"RunFunctionCommand",
|
|
45
45
|
"RunTransformationCommand",
|
|
46
46
|
"RunWorkflowCommand",
|
|
@@ -11,9 +11,8 @@ from packaging.version import Version
|
|
|
11
11
|
from packaging.version import parse as parse_version
|
|
12
12
|
from rich import print
|
|
13
13
|
|
|
14
|
-
from cognite_toolkit._cdf_tk.
|
|
14
|
+
from cognite_toolkit._cdf_tk.cdf_toml import CDFToml
|
|
15
15
|
from cognite_toolkit._cdf_tk.constants import DOCKER_IMAGE_NAME
|
|
16
|
-
from cognite_toolkit._cdf_tk.data_classes import ModuleDirectories
|
|
17
16
|
from cognite_toolkit._cdf_tk.utils import iterate_modules, read_yaml_file, safe_read, safe_write
|
|
18
17
|
from cognite_toolkit._version import __version__
|
|
19
18
|
|
|
@@ -51,40 +50,6 @@ class ManualChange(Change):
|
|
|
51
50
|
return ""
|
|
52
51
|
|
|
53
52
|
|
|
54
|
-
class SetKindOnFile(AutomaticChange):
|
|
55
|
-
"""Adds the kind to the filename of all resource files.
|
|
56
|
-
|
|
57
|
-
Before `your_file.yaml`:
|
|
58
|
-
After `your_file.FileMetadata.yaml`:
|
|
59
|
-
"""
|
|
60
|
-
|
|
61
|
-
deprecated_from = Version("0.4.0")
|
|
62
|
-
has_file_changes = True
|
|
63
|
-
|
|
64
|
-
def do(self) -> set[Path]:
|
|
65
|
-
module_directories = ModuleDirectories.load(self._organization_dir)
|
|
66
|
-
changed: set[Path] = set()
|
|
67
|
-
for module in module_directories:
|
|
68
|
-
for resource_folder, source_files in module.source_paths_by_resource_folder.items():
|
|
69
|
-
for source_file in source_files:
|
|
70
|
-
if source_file.suffix not in {".yaml", ".yml"}:
|
|
71
|
-
continue
|
|
72
|
-
loader, _ = get_loader(source_file, resource_folder, force_pattern=True)
|
|
73
|
-
if loader is None:
|
|
74
|
-
print(f"Could not find loader for {source_file}")
|
|
75
|
-
continue
|
|
76
|
-
if source_file.stem.casefold().endswith(loader.kind.casefold()):
|
|
77
|
-
continue
|
|
78
|
-
new_name = source_file.with_name(f"{source_file.stem}.{loader.kind}{source_file.suffix}")
|
|
79
|
-
source_file.rename(new_name)
|
|
80
|
-
changed.add(source_file)
|
|
81
|
-
for suffix in [".sql", ".csv", ".parquet"]:
|
|
82
|
-
if (adjacent_file := source_file.with_suffix(suffix)).exists():
|
|
83
|
-
adjacent_file.rename(new_name.with_suffix(suffix))
|
|
84
|
-
changed.add(adjacent_file)
|
|
85
|
-
|
|
86
|
-
return changed
|
|
87
|
-
|
|
88
53
|
|
|
89
54
|
class FixViewBasedLocationFilter(AutomaticChange):
|
|
90
55
|
"""The created view-based location filter has been fixed to be compatible with the CDF API.
|
|
@@ -362,7 +327,6 @@ After:
|
|
|
362
327
|
|
|
363
328
|
def do(self) -> set[Path]:
|
|
364
329
|
# Avoid circular import
|
|
365
|
-
from .modules import ModulesCommand
|
|
366
330
|
|
|
367
331
|
system_yaml = self._organization_dir / "_system.yaml"
|
|
368
332
|
if not system_yaml.exists():
|
|
@@ -372,11 +336,8 @@ After:
|
|
|
372
336
|
content = read_yaml_file(system_yaml)
|
|
373
337
|
current_version = content.get("cdf_toolkit_version", __version__)
|
|
374
338
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
cdf_toml_path = Path.cwd() / "cdf.toml"
|
|
379
|
-
cdf_toml_path.write_text(cdf_toml_content, encoding="utf-8")
|
|
339
|
+
CDFToml.write(self._organization_dir, version=current_version)
|
|
340
|
+
cdf_toml_path = Path.cwd() / CDFToml.file_name
|
|
380
341
|
system_yaml.unlink()
|
|
381
342
|
return {cdf_toml_path, system_yaml}
|
|
382
343
|
|
|
@@ -2,14 +2,24 @@ from collections.abc import Callable, Iterable
|
|
|
2
2
|
from functools import partial
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
|
|
5
|
-
from cognite.client.data_classes._base import T_CogniteResource
|
|
6
|
-
|
|
7
5
|
from cognite_toolkit._cdf_tk.constants import DATA_MANIFEST_STEM, DATA_RESOURCE_DIR
|
|
8
6
|
from cognite_toolkit._cdf_tk.exceptions import ToolkitValueError
|
|
9
|
-
from cognite_toolkit._cdf_tk.
|
|
7
|
+
from cognite_toolkit._cdf_tk.protocols import T_ResourceResponse
|
|
8
|
+
from cognite_toolkit._cdf_tk.storageio import (
|
|
9
|
+
ConfigurableStorageIO,
|
|
10
|
+
Page,
|
|
11
|
+
StorageIO,
|
|
12
|
+
T_Selector,
|
|
13
|
+
TableStorageIO,
|
|
14
|
+
)
|
|
10
15
|
from cognite_toolkit._cdf_tk.tk_warnings import LowSeverityWarning
|
|
11
16
|
from cognite_toolkit._cdf_tk.utils.file import safe_write, sanitize_filename, yaml_safe_dump
|
|
12
|
-
from cognite_toolkit._cdf_tk.utils.fileio import
|
|
17
|
+
from cognite_toolkit._cdf_tk.utils.fileio import (
|
|
18
|
+
TABLE_WRITE_CLS_BY_FORMAT,
|
|
19
|
+
Compression,
|
|
20
|
+
FileWriter,
|
|
21
|
+
SchemaColumn,
|
|
22
|
+
)
|
|
13
23
|
from cognite_toolkit._cdf_tk.utils.producer_worker import ProducerWorkerExecutor
|
|
14
24
|
from cognite_toolkit._cdf_tk.utils.useful_types import JsonVal
|
|
15
25
|
|
|
@@ -20,7 +30,7 @@ class DownloadCommand(ToolkitCommand):
|
|
|
20
30
|
def download(
|
|
21
31
|
self,
|
|
22
32
|
selectors: Iterable[T_Selector],
|
|
23
|
-
io: StorageIO[T_Selector,
|
|
33
|
+
io: StorageIO[T_Selector, T_ResourceResponse],
|
|
24
34
|
output_dir: Path,
|
|
25
35
|
verbose: bool,
|
|
26
36
|
file_format: str,
|
|
@@ -68,7 +78,7 @@ class DownloadCommand(ToolkitCommand):
|
|
|
68
78
|
with FileWriter.create_from_format(
|
|
69
79
|
file_format, target_dir, selector.kind, compression_cls, columns=columns
|
|
70
80
|
) as writer:
|
|
71
|
-
executor = ProducerWorkerExecutor[Page[
|
|
81
|
+
executor = ProducerWorkerExecutor[Page[T_ResourceResponse], list[dict[str, JsonVal]]](
|
|
72
82
|
download_iterable=io.stream_data(selector, limit),
|
|
73
83
|
process=self.create_data_process(io=io, selector=selector, is_table=is_table),
|
|
74
84
|
write=partial(writer.write_chunks, filestem=filestem),
|
|
@@ -95,7 +105,7 @@ class DownloadCommand(ToolkitCommand):
|
|
|
95
105
|
|
|
96
106
|
@staticmethod
|
|
97
107
|
def _get_iteration_count(
|
|
98
|
-
io: StorageIO[T_Selector,
|
|
108
|
+
io: StorageIO[T_Selector, T_ResourceResponse],
|
|
99
109
|
selector: T_Selector,
|
|
100
110
|
limit: int | None,
|
|
101
111
|
) -> int | None:
|
|
@@ -126,19 +136,19 @@ class DownloadCommand(ToolkitCommand):
|
|
|
126
136
|
|
|
127
137
|
@staticmethod
|
|
128
138
|
def create_data_process(
|
|
129
|
-
io: StorageIO[T_Selector,
|
|
139
|
+
io: StorageIO[T_Selector, T_ResourceResponse],
|
|
130
140
|
selector: T_Selector,
|
|
131
141
|
is_table: bool,
|
|
132
|
-
) -> Callable[[Page[
|
|
142
|
+
) -> Callable[[Page[T_ResourceResponse]], list[dict[str, JsonVal]]]:
|
|
133
143
|
"""Creates a data processing function based on the IO type and whether the output is a table."""
|
|
134
144
|
if is_table and isinstance(io, TableStorageIO):
|
|
135
145
|
|
|
136
|
-
def row_data_process(chunk: Page[
|
|
146
|
+
def row_data_process(chunk: Page[T_ResourceResponse]) -> list[dict[str, JsonVal]]:
|
|
137
147
|
return io.data_to_row(chunk.items, selector)
|
|
138
148
|
|
|
139
149
|
return row_data_process
|
|
140
150
|
|
|
141
|
-
def chunk_data_process(data_page: Page[
|
|
151
|
+
def chunk_data_process(data_page: Page[T_ResourceResponse]) -> list[dict[str, JsonVal]]:
|
|
142
152
|
return io.data_to_json_chunk(data_page.items, selector)
|
|
143
153
|
|
|
144
154
|
return chunk_data_process
|
|
@@ -2,7 +2,6 @@ from collections.abc import Callable, Iterable, Sequence
|
|
|
2
2
|
from enum import Enum
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
|
|
5
|
-
from cognite.client.data_classes._base import T_CogniteResource
|
|
6
5
|
from rich import print
|
|
7
6
|
from rich.console import Console
|
|
8
7
|
from rich.table import Table
|
|
@@ -20,6 +19,7 @@ from cognite_toolkit._cdf_tk.exceptions import (
|
|
|
20
19
|
ToolkitMigrationError,
|
|
21
20
|
ToolkitValueError,
|
|
22
21
|
)
|
|
22
|
+
from cognite_toolkit._cdf_tk.protocols import T_ResourceRequest, T_ResourceResponse
|
|
23
23
|
from cognite_toolkit._cdf_tk.storageio import T_Selector, UploadableStorageIO, UploadItem
|
|
24
24
|
from cognite_toolkit._cdf_tk.utils import humanize_collection, safe_write, sanitize_filename
|
|
25
25
|
from cognite_toolkit._cdf_tk.utils.file import yaml_safe_dump
|
|
@@ -27,7 +27,6 @@ from cognite_toolkit._cdf_tk.utils.fileio import Chunk, CSVWriter, NDJsonWriter,
|
|
|
27
27
|
from cognite_toolkit._cdf_tk.utils.http_client import HTTPClient, HTTPMessage, ItemMessage, SuccessResponseItems
|
|
28
28
|
from cognite_toolkit._cdf_tk.utils.producer_worker import ProducerWorkerExecutor
|
|
29
29
|
from cognite_toolkit._cdf_tk.utils.progress_tracker import AVAILABLE_STATUS, ProgressTracker, Status
|
|
30
|
-
from cognite_toolkit._cdf_tk.utils.useful_types import T_WriteCogniteResource
|
|
31
30
|
|
|
32
31
|
from .data_model import INSTANCE_SOURCE_VIEW_ID, MODEL_ID, RESOURCE_VIEW_MAPPING_VIEW_ID
|
|
33
32
|
|
|
@@ -45,8 +44,8 @@ class MigrationCommand(ToolkitCommand):
|
|
|
45
44
|
def migrate(
|
|
46
45
|
self,
|
|
47
46
|
selected: T_Selector,
|
|
48
|
-
data: UploadableStorageIO[T_Selector,
|
|
49
|
-
mapper: DataMapper[T_Selector,
|
|
47
|
+
data: UploadableStorageIO[T_Selector, T_ResourceResponse, T_ResourceRequest],
|
|
48
|
+
mapper: DataMapper[T_Selector, T_ResourceResponse, T_ResourceRequest],
|
|
50
49
|
log_dir: Path,
|
|
51
50
|
dry_run: bool = False,
|
|
52
51
|
verbose: bool = False,
|
|
@@ -71,9 +70,7 @@ class MigrationCommand(ToolkitCommand):
|
|
|
71
70
|
NDJsonWriter(log_dir, kind=f"{selected.kind}MigrationIssues", compression=Uncompressed) as log_file,
|
|
72
71
|
HTTPClient(config=data.client.config) as write_client,
|
|
73
72
|
):
|
|
74
|
-
executor = ProducerWorkerExecutor[
|
|
75
|
-
Sequence[T_CogniteResource], Sequence[UploadItem[T_WriteCogniteResource]]
|
|
76
|
-
](
|
|
73
|
+
executor = ProducerWorkerExecutor[Sequence[T_ResourceResponse], Sequence[UploadItem[T_ResourceRequest]]](
|
|
77
74
|
download_iterable=self._download_iterable(selected, data, tracker),
|
|
78
75
|
process=self._convert(mapper, data, tracker, log_file),
|
|
79
76
|
write=self._upload(selected, write_client, data, tracker, log_file, dry_run),
|
|
@@ -141,9 +138,9 @@ class MigrationCommand(ToolkitCommand):
|
|
|
141
138
|
def _download_iterable(
|
|
142
139
|
self,
|
|
143
140
|
selected: T_Selector,
|
|
144
|
-
data: UploadableStorageIO[T_Selector,
|
|
141
|
+
data: UploadableStorageIO[T_Selector, T_ResourceResponse, T_ResourceRequest],
|
|
145
142
|
tracker: ProgressTracker[str],
|
|
146
|
-
) -> Iterable[Sequence[
|
|
143
|
+
) -> Iterable[Sequence[T_ResourceResponse]]:
|
|
147
144
|
for page in data.stream_data(selected):
|
|
148
145
|
for item in page.items:
|
|
149
146
|
tracker.set_progress(data.as_id(item), self.Steps.DOWNLOAD, "success")
|
|
@@ -151,16 +148,17 @@ class MigrationCommand(ToolkitCommand):
|
|
|
151
148
|
|
|
152
149
|
def _convert(
|
|
153
150
|
self,
|
|
154
|
-
mapper: DataMapper[T_Selector,
|
|
155
|
-
data: UploadableStorageIO[T_Selector,
|
|
151
|
+
mapper: DataMapper[T_Selector, T_ResourceResponse, T_ResourceRequest],
|
|
152
|
+
data: UploadableStorageIO[T_Selector, T_ResourceResponse, T_ResourceRequest],
|
|
156
153
|
tracker: ProgressTracker[str],
|
|
157
154
|
log_file: NDJsonWriter,
|
|
158
|
-
) -> Callable[[Sequence[
|
|
159
|
-
def track_mapping(source: Sequence[
|
|
155
|
+
) -> Callable[[Sequence[T_ResourceResponse]], Sequence[UploadItem[T_ResourceRequest]]]:
|
|
156
|
+
def track_mapping(source: Sequence[T_ResourceResponse]) -> list[UploadItem[T_ResourceRequest]]:
|
|
157
|
+
mapped = mapper.map(source)
|
|
160
158
|
issues: list[Chunk] = []
|
|
161
|
-
targets: list[UploadItem[
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
targets: list[UploadItem[T_ResourceRequest]] = []
|
|
160
|
+
|
|
161
|
+
for (target, issue), item in zip(mapped, source):
|
|
164
162
|
id_ = data.as_id(item)
|
|
165
163
|
result: Status = "failed" if target is None else "success"
|
|
166
164
|
tracker.set_progress(id_, step=self.Steps.CONVERT, status=result)
|
|
@@ -180,17 +178,21 @@ class MigrationCommand(ToolkitCommand):
|
|
|
180
178
|
self,
|
|
181
179
|
selected: T_Selector,
|
|
182
180
|
write_client: HTTPClient,
|
|
183
|
-
target: UploadableStorageIO[T_Selector,
|
|
181
|
+
target: UploadableStorageIO[T_Selector, T_ResourceResponse, T_ResourceRequest],
|
|
184
182
|
tracker: ProgressTracker[str],
|
|
185
183
|
log_file: NDJsonWriter,
|
|
186
184
|
dry_run: bool,
|
|
187
|
-
) -> Callable[[Sequence[UploadItem[
|
|
188
|
-
def upload_items(data_item: Sequence[UploadItem[
|
|
185
|
+
) -> Callable[[Sequence[UploadItem[T_ResourceRequest]]], None]:
|
|
186
|
+
def upload_items(data_item: Sequence[UploadItem[T_ResourceRequest]]) -> None:
|
|
189
187
|
if not data_item:
|
|
190
188
|
return None
|
|
191
189
|
responses: Sequence[HTTPMessage]
|
|
192
190
|
if dry_run:
|
|
193
|
-
responses = [
|
|
191
|
+
responses = [
|
|
192
|
+
SuccessResponseItems(
|
|
193
|
+
status_code=200, body="", content=b"", ids=[item.source_id for item in data_item]
|
|
194
|
+
)
|
|
195
|
+
]
|
|
194
196
|
else:
|
|
195
197
|
responses = target.upload_items(data_chunk=data_item, http_client=write_client, selector=selected)
|
|
196
198
|
|