snowflake-cli-labs 3.0.0rc5__py3-none-any.whl → 3.0.2__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.
- README.md +21 -0
- {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/METADATA +6 -96
- snowflake_cli_labs-3.0.2.dist-info/RECORD +5 -0
- snowflake/cli/__about__.py +0 -17
- snowflake/cli/__init__.py +0 -13
- snowflake/cli/_app/__init__.py +0 -22
- snowflake/cli/_app/__main__.py +0 -31
- snowflake/cli/_app/api_impl/__init__.py +0 -13
- snowflake/cli/_app/api_impl/plugin/__init__.py +0 -13
- snowflake/cli/_app/api_impl/plugin/plugin_config_provider_impl.py +0 -66
- snowflake/cli/_app/cli_app.py +0 -252
- snowflake/cli/_app/commands_registration/__init__.py +0 -33
- snowflake/cli/_app/commands_registration/builtin_plugins.py +0 -50
- snowflake/cli/_app/commands_registration/command_plugins_loader.py +0 -169
- snowflake/cli/_app/commands_registration/commands_registration_with_callbacks.py +0 -105
- snowflake/cli/_app/commands_registration/exception_logging.py +0 -26
- snowflake/cli/_app/commands_registration/threadsafe.py +0 -48
- snowflake/cli/_app/commands_registration/typer_registration.py +0 -153
- snowflake/cli/_app/constants.py +0 -19
- snowflake/cli/_app/dev/__init__.py +0 -13
- snowflake/cli/_app/dev/commands_structure.py +0 -48
- snowflake/cli/_app/dev/docs/__init__.py +0 -13
- snowflake/cli/_app/dev/docs/commands_docs_generator.py +0 -118
- snowflake/cli/_app/dev/docs/generator.py +0 -35
- snowflake/cli/_app/dev/docs/project_definition_docs_generator.py +0 -58
- snowflake/cli/_app/dev/docs/project_definition_generate_json_schema.py +0 -227
- snowflake/cli/_app/dev/docs/template_utils.py +0 -23
- snowflake/cli/_app/dev/docs/templates/definition_description.rst.jinja2 +0 -38
- snowflake/cli/_app/dev/docs/templates/overview.rst.jinja2 +0 -9
- snowflake/cli/_app/dev/docs/templates/usage.rst.jinja2 +0 -67
- snowflake/cli/_app/dev/pycharm_remote_debug.py +0 -46
- snowflake/cli/_app/loggers.py +0 -199
- snowflake/cli/_app/main_typer.py +0 -62
- snowflake/cli/_app/printing.py +0 -181
- snowflake/cli/_app/secret.py +0 -9
- snowflake/cli/_app/snow_connector.py +0 -309
- snowflake/cli/_app/telemetry.py +0 -220
- snowflake/cli/_app/version_check.py +0 -74
- snowflake/cli/_plugins/__init__.py +0 -13
- snowflake/cli/_plugins/connection/__init__.py +0 -13
- snowflake/cli/_plugins/connection/commands.py +0 -353
- snowflake/cli/_plugins/connection/plugin_spec.py +0 -30
- snowflake/cli/_plugins/connection/util.py +0 -195
- snowflake/cli/_plugins/cortex/__init__.py +0 -13
- snowflake/cli/_plugins/cortex/commands.py +0 -332
- snowflake/cli/_plugins/cortex/constants.py +0 -17
- snowflake/cli/_plugins/cortex/manager.py +0 -189
- snowflake/cli/_plugins/cortex/plugin_spec.py +0 -30
- snowflake/cli/_plugins/cortex/types.py +0 -22
- snowflake/cli/_plugins/git/__init__.py +0 -13
- snowflake/cli/_plugins/git/commands.py +0 -358
- snowflake/cli/_plugins/git/manager.py +0 -151
- snowflake/cli/_plugins/git/plugin_spec.py +0 -30
- snowflake/cli/_plugins/helpers/__init__.py +0 -13
- snowflake/cli/_plugins/helpers/commands.py +0 -90
- snowflake/cli/_plugins/helpers/plugin_spec.py +0 -30
- snowflake/cli/_plugins/init/__init__.py +0 -13
- snowflake/cli/_plugins/init/commands.py +0 -248
- snowflake/cli/_plugins/init/plugin_spec.py +0 -30
- snowflake/cli/_plugins/nativeapp/__init__.py +0 -13
- snowflake/cli/_plugins/nativeapp/artifacts.py +0 -757
- snowflake/cli/_plugins/nativeapp/bundle_context.py +0 -31
- snowflake/cli/_plugins/nativeapp/codegen/__init__.py +0 -13
- snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py +0 -91
- snowflake/cli/_plugins/nativeapp/codegen/compiler.py +0 -149
- snowflake/cli/_plugins/nativeapp/codegen/sandbox.py +0 -306
- snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -249
- snowflake/cli/_plugins/nativeapp/codegen/setup/setup_driver.py.source +0 -59
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -181
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/extension_function_utils.py +0 -217
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/models.py +0 -61
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py +0 -523
- snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +0 -114
- snowflake/cli/_plugins/nativeapp/commands.py +0 -559
- snowflake/cli/_plugins/nativeapp/common_flags.py +0 -44
- snowflake/cli/_plugins/nativeapp/constants.py +0 -27
- snowflake/cli/_plugins/nativeapp/entities/__init__.py +0 -0
- snowflake/cli/_plugins/nativeapp/entities/application.py +0 -878
- snowflake/cli/_plugins/nativeapp/entities/application_package.py +0 -1392
- snowflake/cli/_plugins/nativeapp/exceptions.py +0 -113
- snowflake/cli/_plugins/nativeapp/feature_flags.py +0 -24
- snowflake/cli/_plugins/nativeapp/manager.py +0 -415
- snowflake/cli/_plugins/nativeapp/plugin_spec.py +0 -30
- snowflake/cli/_plugins/nativeapp/policy.py +0 -53
- snowflake/cli/_plugins/nativeapp/project_model.py +0 -211
- snowflake/cli/_plugins/nativeapp/run_processor.py +0 -184
- snowflake/cli/_plugins/nativeapp/same_account_install_method.py +0 -70
- snowflake/cli/_plugins/nativeapp/teardown_processor.py +0 -70
- snowflake/cli/_plugins/nativeapp/utils.py +0 -98
- snowflake/cli/_plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -262
- snowflake/cli/_plugins/nativeapp/version/__init__.py +0 -13
- snowflake/cli/_plugins/nativeapp/version/commands.py +0 -141
- snowflake/cli/_plugins/nativeapp/version/version_processor.py +0 -98
- snowflake/cli/_plugins/notebook/__init__.py +0 -13
- snowflake/cli/_plugins/notebook/commands.py +0 -86
- snowflake/cli/_plugins/notebook/exceptions.py +0 -20
- snowflake/cli/_plugins/notebook/manager.py +0 -71
- snowflake/cli/_plugins/notebook/plugin_spec.py +0 -30
- snowflake/cli/_plugins/notebook/types.py +0 -15
- snowflake/cli/_plugins/object/__init__.py +0 -13
- snowflake/cli/_plugins/object/command_aliases.py +0 -95
- snowflake/cli/_plugins/object/commands.py +0 -180
- snowflake/cli/_plugins/object/common.py +0 -85
- snowflake/cli/_plugins/object/manager.py +0 -118
- snowflake/cli/_plugins/object/plugin_spec.py +0 -30
- snowflake/cli/_plugins/snowpark/__init__.py +0 -13
- snowflake/cli/_plugins/snowpark/commands.py +0 -450
- snowflake/cli/_plugins/snowpark/common.py +0 -268
- snowflake/cli/_plugins/snowpark/models.py +0 -150
- snowflake/cli/_plugins/snowpark/package/__init__.py +0 -13
- snowflake/cli/_plugins/snowpark/package/anaconda_packages.py +0 -199
- snowflake/cli/_plugins/snowpark/package/commands.py +0 -195
- snowflake/cli/_plugins/snowpark/package/manager.py +0 -44
- snowflake/cli/_plugins/snowpark/package/utils.py +0 -26
- snowflake/cli/_plugins/snowpark/package_utils.py +0 -354
- snowflake/cli/_plugins/snowpark/plugin_spec.py +0 -30
- snowflake/cli/_plugins/snowpark/snowpark_entity.py +0 -29
- snowflake/cli/_plugins/snowpark/snowpark_entity_model.py +0 -173
- snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +0 -109
- snowflake/cli/_plugins/snowpark/snowpark_shared.py +0 -59
- snowflake/cli/_plugins/snowpark/zipper.py +0 -89
- snowflake/cli/_plugins/spcs/__init__.py +0 -33
- snowflake/cli/_plugins/spcs/common.py +0 -99
- snowflake/cli/_plugins/spcs/compute_pool/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/compute_pool/commands.py +0 -241
- snowflake/cli/_plugins/spcs/compute_pool/manager.py +0 -121
- snowflake/cli/_plugins/spcs/image_registry/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/image_registry/commands.py +0 -65
- snowflake/cli/_plugins/spcs/image_registry/manager.py +0 -105
- snowflake/cli/_plugins/spcs/image_repository/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/image_repository/commands.py +0 -202
- snowflake/cli/_plugins/spcs/image_repository/manager.py +0 -84
- snowflake/cli/_plugins/spcs/plugin_spec.py +0 -30
- snowflake/cli/_plugins/spcs/services/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/services/commands.py +0 -345
- snowflake/cli/_plugins/spcs/services/manager.py +0 -208
- snowflake/cli/_plugins/sql/__init__.py +0 -13
- snowflake/cli/_plugins/sql/commands.py +0 -86
- snowflake/cli/_plugins/sql/manager.py +0 -92
- snowflake/cli/_plugins/sql/plugin_spec.py +0 -30
- snowflake/cli/_plugins/sql/snowsql_templating.py +0 -28
- snowflake/cli/_plugins/stage/__init__.py +0 -13
- snowflake/cli/_plugins/stage/commands.py +0 -264
- snowflake/cli/_plugins/stage/diff.py +0 -280
- snowflake/cli/_plugins/stage/manager.py +0 -582
- snowflake/cli/_plugins/stage/md5.py +0 -160
- snowflake/cli/_plugins/stage/plugin_spec.py +0 -30
- snowflake/cli/_plugins/stage/utils.py +0 -54
- snowflake/cli/_plugins/streamlit/__init__.py +0 -13
- snowflake/cli/_plugins/streamlit/commands.py +0 -195
- snowflake/cli/_plugins/streamlit/manager.py +0 -220
- snowflake/cli/_plugins/streamlit/plugin_spec.py +0 -30
- snowflake/cli/_plugins/streamlit/streamlit_entity.py +0 -12
- snowflake/cli/_plugins/streamlit/streamlit_entity_model.py +0 -66
- snowflake/cli/_plugins/workspace/__init__.py +0 -13
- snowflake/cli/_plugins/workspace/action_context.py +0 -18
- snowflake/cli/_plugins/workspace/commands.py +0 -306
- snowflake/cli/_plugins/workspace/manager.py +0 -74
- snowflake/cli/_plugins/workspace/plugin_spec.py +0 -30
- snowflake/cli/api/__init__.py +0 -48
- snowflake/cli/api/cli_global_context.py +0 -247
- snowflake/cli/api/commands/__init__.py +0 -13
- snowflake/cli/api/commands/alias.py +0 -23
- snowflake/cli/api/commands/common.py +0 -25
- snowflake/cli/api/commands/decorators.py +0 -369
- snowflake/cli/api/commands/execution_metadata.py +0 -40
- snowflake/cli/api/commands/experimental_behaviour.py +0 -18
- snowflake/cli/api/commands/flags.py +0 -561
- snowflake/cli/api/commands/overrideable_parameter.py +0 -143
- snowflake/cli/api/commands/snow_typer.py +0 -247
- snowflake/cli/api/commands/utils.py +0 -18
- snowflake/cli/api/config.py +0 -380
- snowflake/cli/api/connections.py +0 -216
- snowflake/cli/api/console/__init__.py +0 -17
- snowflake/cli/api/console/abc.py +0 -94
- snowflake/cli/api/console/console.py +0 -134
- snowflake/cli/api/console/enum.py +0 -17
- snowflake/cli/api/constants.py +0 -90
- snowflake/cli/api/entities/common.py +0 -56
- snowflake/cli/api/entities/utils.py +0 -370
- snowflake/cli/api/errno.py +0 -28
- snowflake/cli/api/exceptions.py +0 -190
- snowflake/cli/api/feature_flags.py +0 -54
- snowflake/cli/api/identifiers.py +0 -190
- snowflake/cli/api/metrics.py +0 -92
- snowflake/cli/api/output/__init__.py +0 -13
- snowflake/cli/api/output/formats.py +0 -20
- snowflake/cli/api/output/types.py +0 -118
- snowflake/cli/api/plugins/__init__.py +0 -13
- snowflake/cli/api/plugins/command/__init__.py +0 -72
- snowflake/cli/api/plugins/command/plugin_hook_specs.py +0 -21
- snowflake/cli/api/plugins/plugin_config.py +0 -32
- snowflake/cli/api/project/__init__.py +0 -13
- snowflake/cli/api/project/definition.py +0 -126
- snowflake/cli/api/project/definition_conversion.py +0 -400
- snowflake/cli/api/project/definition_manager.py +0 -145
- snowflake/cli/api/project/errors.py +0 -56
- snowflake/cli/api/project/project_verification.py +0 -23
- snowflake/cli/api/project/schemas/__init__.py +0 -13
- snowflake/cli/api/project/schemas/entities/__init__.py +0 -13
- snowflake/cli/api/project/schemas/entities/common.py +0 -153
- snowflake/cli/api/project/schemas/entities/entities.py +0 -61
- snowflake/cli/api/project/schemas/project_definition.py +0 -330
- snowflake/cli/api/project/schemas/template.py +0 -77
- snowflake/cli/api/project/schemas/updatable_model.py +0 -202
- snowflake/cli/api/project/schemas/v1/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/identifier_model.py +0 -51
- snowflake/cli/api/project/schemas/v1/native_app/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/native_app/application.py +0 -61
- snowflake/cli/api/project/schemas/v1/native_app/native_app.py +0 -93
- snowflake/cli/api/project/schemas/v1/native_app/package.py +0 -84
- snowflake/cli/api/project/schemas/v1/native_app/path_mapping.py +0 -65
- snowflake/cli/api/project/schemas/v1/snowpark/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/snowpark/argument.py +0 -28
- snowflake/cli/api/project/schemas/v1/snowpark/callable.py +0 -69
- snowflake/cli/api/project/schemas/v1/snowpark/snowpark.py +0 -36
- snowflake/cli/api/project/schemas/v1/streamlit/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/streamlit/streamlit.py +0 -47
- snowflake/cli/api/project/util.py +0 -278
- snowflake/cli/api/rendering/__init__.py +0 -13
- snowflake/cli/api/rendering/jinja.py +0 -118
- snowflake/cli/api/rendering/project_definition_templates.py +0 -43
- snowflake/cli/api/rendering/project_templates.py +0 -98
- snowflake/cli/api/rendering/sql_templates.py +0 -105
- snowflake/cli/api/rest_api.py +0 -178
- snowflake/cli/api/sanitizers.py +0 -43
- snowflake/cli/api/secure_path.py +0 -360
- snowflake/cli/api/secure_utils.py +0 -118
- snowflake/cli/api/sql_execution.py +0 -280
- snowflake/cli/api/utils/__init__.py +0 -13
- snowflake/cli/api/utils/cursor.py +0 -34
- snowflake/cli/api/utils/definition_rendering.py +0 -415
- snowflake/cli/api/utils/dict_utils.py +0 -73
- snowflake/cli/api/utils/error_handling.py +0 -23
- snowflake/cli/api/utils/graph.py +0 -97
- snowflake/cli/api/utils/models.py +0 -63
- snowflake/cli/api/utils/naming_utils.py +0 -13
- snowflake/cli/api/utils/path_utils.py +0 -36
- snowflake/cli/api/utils/templating_functions.py +0 -144
- snowflake/cli/api/utils/types.py +0 -35
- snowflake_cli_labs-3.0.0rc5.dist-info/RECORD +0 -242
- snowflake_cli_labs-3.0.0rc5.dist-info/entry_points.txt +0 -2
- {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/WHEEL +0 -0
- {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2024 Snowflake Inc.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from __future__ import annotations
|
|
16
|
-
|
|
17
|
-
import itertools
|
|
18
|
-
import logging
|
|
19
|
-
from os import path
|
|
20
|
-
from pathlib import Path
|
|
21
|
-
from typing import Dict, List, Optional
|
|
22
|
-
|
|
23
|
-
import typer
|
|
24
|
-
from click import ClickException
|
|
25
|
-
from snowflake.cli._plugins.git.manager import GitManager
|
|
26
|
-
from snowflake.cli._plugins.object.command_aliases import (
|
|
27
|
-
add_object_command_aliases,
|
|
28
|
-
scope_option,
|
|
29
|
-
)
|
|
30
|
-
from snowflake.cli._plugins.object.manager import ObjectManager
|
|
31
|
-
from snowflake.cli.api.commands.common import OnErrorType
|
|
32
|
-
from snowflake.cli.api.commands.flags import (
|
|
33
|
-
ExecuteVariablesOption,
|
|
34
|
-
OnErrorOption,
|
|
35
|
-
PatternOption,
|
|
36
|
-
identifier_argument,
|
|
37
|
-
like_option,
|
|
38
|
-
)
|
|
39
|
-
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
|
|
40
|
-
from snowflake.cli.api.console.console import cli_console
|
|
41
|
-
from snowflake.cli.api.constants import ObjectType
|
|
42
|
-
from snowflake.cli.api.output.types import CollectionResult, CommandResult, QueryResult
|
|
43
|
-
from snowflake.cli.api.utils.path_utils import is_stage_path
|
|
44
|
-
from snowflake.connector import DictCursor
|
|
45
|
-
|
|
46
|
-
app = SnowTyperFactory(
|
|
47
|
-
name="git",
|
|
48
|
-
help="Manages git repositories in Snowflake.",
|
|
49
|
-
)
|
|
50
|
-
log = logging.getLogger(__name__)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def _repo_path_argument_callback(path):
|
|
54
|
-
# All repository paths must start with repository scope:
|
|
55
|
-
# "@repo_name/tag/example_tag/*"
|
|
56
|
-
if not is_stage_path(path) or path.count("/") < 3:
|
|
57
|
-
raise ClickException(
|
|
58
|
-
"REPOSITORY_PATH should be a path to git repository stage with scope provided."
|
|
59
|
-
" Path to the repository root must end with '/'."
|
|
60
|
-
" For example: @my_repo/branches/main/"
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
return path
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
RepoNameArgument = identifier_argument(sf_object="git repository", example="my_repo")
|
|
67
|
-
RepoPathArgument = typer.Argument(
|
|
68
|
-
metavar="REPOSITORY_PATH",
|
|
69
|
-
help=(
|
|
70
|
-
"Path to git repository stage with scope provided."
|
|
71
|
-
" Path to the repository root must end with '/'."
|
|
72
|
-
" For example: @my_repo/branches/main/"
|
|
73
|
-
),
|
|
74
|
-
callback=_repo_path_argument_callback,
|
|
75
|
-
show_default=False,
|
|
76
|
-
)
|
|
77
|
-
add_object_command_aliases(
|
|
78
|
-
app=app,
|
|
79
|
-
object_type=ObjectType.GIT_REPOSITORY,
|
|
80
|
-
name_argument=RepoNameArgument,
|
|
81
|
-
like_option=like_option(
|
|
82
|
-
help_example='`list --like "my%"` lists all git repositories with name that begin with “my”',
|
|
83
|
-
),
|
|
84
|
-
scope_option=scope_option(help_example="`list --in database my_db`"),
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
from snowflake.cli.api.identifiers import FQN
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def _assure_repository_does_not_exist(om: ObjectManager, repository_name: FQN) -> None:
|
|
91
|
-
if om.object_exists(
|
|
92
|
-
object_type=ObjectType.GIT_REPOSITORY.value.cli_name, fqn=repository_name
|
|
93
|
-
):
|
|
94
|
-
raise ClickException(f"Repository '{repository_name}' already exists")
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def _validate_origin_url(url: str) -> None:
|
|
98
|
-
if not url.startswith("https://"):
|
|
99
|
-
raise ClickException("Url address should start with 'https'")
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def _unique_new_object_name(
|
|
103
|
-
om: ObjectManager, object_type: ObjectType, proposed_fqn: FQN
|
|
104
|
-
) -> str:
|
|
105
|
-
existing_objects: List[Dict] = om.show(
|
|
106
|
-
object_type=object_type.value.cli_name,
|
|
107
|
-
like=f"{proposed_fqn.name}%",
|
|
108
|
-
cursor_class=DictCursor,
|
|
109
|
-
).fetchall()
|
|
110
|
-
existing_names = set(o["name"].upper() for o in existing_objects)
|
|
111
|
-
|
|
112
|
-
result = proposed_fqn.name
|
|
113
|
-
i = 1
|
|
114
|
-
while result.upper() in existing_names:
|
|
115
|
-
result = proposed_fqn.name + str(i)
|
|
116
|
-
i += 1
|
|
117
|
-
return result
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
@app.command("setup", requires_connection=True)
|
|
121
|
-
def setup(
|
|
122
|
-
repository_name: FQN = RepoNameArgument,
|
|
123
|
-
**options,
|
|
124
|
-
) -> CommandResult:
|
|
125
|
-
"""
|
|
126
|
-
Sets up a git repository object.
|
|
127
|
-
|
|
128
|
-
## Usage notes
|
|
129
|
-
|
|
130
|
-
You will be prompted for:
|
|
131
|
-
|
|
132
|
-
* url - address of repository to be used for git clone operation
|
|
133
|
-
|
|
134
|
-
* secret - Snowflake secret containing authentication credentials. Not needed if origin repository does not require
|
|
135
|
-
authentication for RO operations (clone, fetch)
|
|
136
|
-
|
|
137
|
-
* API integration - object allowing Snowflake to interact with git repository.
|
|
138
|
-
"""
|
|
139
|
-
manager = GitManager()
|
|
140
|
-
om = ObjectManager()
|
|
141
|
-
_assure_repository_does_not_exist(om, repository_name)
|
|
142
|
-
|
|
143
|
-
url = typer.prompt("Origin url")
|
|
144
|
-
_validate_origin_url(url)
|
|
145
|
-
|
|
146
|
-
secret_needed = typer.confirm("Use secret for authentication?")
|
|
147
|
-
should_create_secret = False
|
|
148
|
-
secret_name = None
|
|
149
|
-
if secret_needed:
|
|
150
|
-
default_secret_name = (
|
|
151
|
-
FQN.from_string(f"{repository_name.name}_secret")
|
|
152
|
-
.set_schema(repository_name.schema)
|
|
153
|
-
.set_database(repository_name.database)
|
|
154
|
-
)
|
|
155
|
-
default_secret_name.set_name(
|
|
156
|
-
_unique_new_object_name(
|
|
157
|
-
om, object_type=ObjectType.SECRET, proposed_fqn=default_secret_name
|
|
158
|
-
),
|
|
159
|
-
)
|
|
160
|
-
secret_name = FQN.from_string(
|
|
161
|
-
typer.prompt(
|
|
162
|
-
"Secret identifier (will be created if not exists)",
|
|
163
|
-
default=default_secret_name.name,
|
|
164
|
-
)
|
|
165
|
-
)
|
|
166
|
-
if not secret_name.database:
|
|
167
|
-
secret_name.set_database(repository_name.database)
|
|
168
|
-
if not secret_name.schema:
|
|
169
|
-
secret_name.set_schema(repository_name.schema)
|
|
170
|
-
|
|
171
|
-
if om.object_exists(
|
|
172
|
-
object_type=ObjectType.SECRET.value.cli_name, fqn=secret_name
|
|
173
|
-
):
|
|
174
|
-
cli_console.step(f"Using existing secret '{secret_name}'")
|
|
175
|
-
else:
|
|
176
|
-
should_create_secret = True
|
|
177
|
-
cli_console.step(f"Secret '{secret_name}' will be created")
|
|
178
|
-
secret_username = typer.prompt("username")
|
|
179
|
-
secret_password = typer.prompt("password/token", hide_input=True)
|
|
180
|
-
|
|
181
|
-
# API integration is an account-level object
|
|
182
|
-
api_integration = FQN.from_string(f"{repository_name.name}_api_integration")
|
|
183
|
-
api_integration.set_name(
|
|
184
|
-
typer.prompt(
|
|
185
|
-
"API integration identifier (will be created if not exists)",
|
|
186
|
-
default=_unique_new_object_name(
|
|
187
|
-
om,
|
|
188
|
-
object_type=ObjectType.INTEGRATION,
|
|
189
|
-
proposed_fqn=api_integration,
|
|
190
|
-
),
|
|
191
|
-
)
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
if should_create_secret:
|
|
195
|
-
manager.create_password_secret(
|
|
196
|
-
name=secret_name, username=secret_username, password=secret_password
|
|
197
|
-
)
|
|
198
|
-
cli_console.step(f"Secret '{secret_name}' successfully created.")
|
|
199
|
-
|
|
200
|
-
if not om.object_exists(
|
|
201
|
-
object_type=ObjectType.INTEGRATION.value.cli_name, fqn=api_integration
|
|
202
|
-
):
|
|
203
|
-
manager.create_api_integration(
|
|
204
|
-
name=api_integration,
|
|
205
|
-
api_provider="git_https_api",
|
|
206
|
-
allowed_prefix=url,
|
|
207
|
-
secret=secret_name,
|
|
208
|
-
)
|
|
209
|
-
cli_console.step(f"API integration '{api_integration}' successfully created.")
|
|
210
|
-
else:
|
|
211
|
-
cli_console.step(f"Using existing API integration '{api_integration}'.")
|
|
212
|
-
|
|
213
|
-
return QueryResult(
|
|
214
|
-
manager.create(
|
|
215
|
-
repo_name=repository_name,
|
|
216
|
-
url=url,
|
|
217
|
-
api_integration=api_integration,
|
|
218
|
-
secret=secret_name,
|
|
219
|
-
)
|
|
220
|
-
)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
@app.command(
|
|
224
|
-
"list-branches",
|
|
225
|
-
requires_connection=True,
|
|
226
|
-
)
|
|
227
|
-
def list_branches(
|
|
228
|
-
repository_name: FQN = RepoNameArgument,
|
|
229
|
-
like=like_option(
|
|
230
|
-
help_example='`list-branches --like "%_test"` lists all branches that end with "_test"'
|
|
231
|
-
),
|
|
232
|
-
**options,
|
|
233
|
-
) -> CommandResult:
|
|
234
|
-
"""
|
|
235
|
-
List all branches in the repository.
|
|
236
|
-
"""
|
|
237
|
-
return QueryResult(
|
|
238
|
-
GitManager().show_branches(repo_name=repository_name.identifier, like=like)
|
|
239
|
-
)
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
@app.command(
|
|
243
|
-
"list-tags",
|
|
244
|
-
requires_connection=True,
|
|
245
|
-
)
|
|
246
|
-
def list_tags(
|
|
247
|
-
repository_name: FQN = RepoNameArgument,
|
|
248
|
-
like=like_option(
|
|
249
|
-
help_example='`list-tags --like "v2.0%"` lists all tags that start with "v2.0"'
|
|
250
|
-
),
|
|
251
|
-
**options,
|
|
252
|
-
) -> CommandResult:
|
|
253
|
-
"""
|
|
254
|
-
List all tags in the repository.
|
|
255
|
-
"""
|
|
256
|
-
return QueryResult(
|
|
257
|
-
GitManager().show_tags(repo_name=repository_name.identifier, like=like)
|
|
258
|
-
)
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
@app.command(
|
|
262
|
-
"list-files",
|
|
263
|
-
requires_connection=True,
|
|
264
|
-
)
|
|
265
|
-
def list_files(
|
|
266
|
-
repository_path: str = RepoPathArgument,
|
|
267
|
-
pattern=PatternOption,
|
|
268
|
-
**options,
|
|
269
|
-
) -> CommandResult:
|
|
270
|
-
"""
|
|
271
|
-
List files from given state of git repository.
|
|
272
|
-
"""
|
|
273
|
-
return QueryResult(
|
|
274
|
-
GitManager().list_files(stage_name=repository_path, pattern=pattern)
|
|
275
|
-
)
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
@app.command(
|
|
279
|
-
"fetch",
|
|
280
|
-
requires_connection=True,
|
|
281
|
-
)
|
|
282
|
-
def fetch(
|
|
283
|
-
repository_name: FQN = RepoNameArgument,
|
|
284
|
-
**options,
|
|
285
|
-
) -> CommandResult:
|
|
286
|
-
"""
|
|
287
|
-
Fetch changes from origin to Snowflake repository.
|
|
288
|
-
"""
|
|
289
|
-
return QueryResult(GitManager().fetch(fqn=repository_name))
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
@app.command(
|
|
293
|
-
"copy",
|
|
294
|
-
requires_connection=True,
|
|
295
|
-
)
|
|
296
|
-
def copy(
|
|
297
|
-
repository_path: str = RepoPathArgument,
|
|
298
|
-
destination_path: str = typer.Argument(
|
|
299
|
-
help="Target path for copy operation. Should be a path to a directory on remote stage or local file system.",
|
|
300
|
-
show_default=False,
|
|
301
|
-
),
|
|
302
|
-
parallel: int = typer.Option(
|
|
303
|
-
4,
|
|
304
|
-
help="Number of parallel threads to use when downloading files.",
|
|
305
|
-
),
|
|
306
|
-
**options,
|
|
307
|
-
):
|
|
308
|
-
"""
|
|
309
|
-
Copies all files from given state of repository to local directory or stage.
|
|
310
|
-
|
|
311
|
-
If the source path ends with '/', the command copies contents of specified directory.
|
|
312
|
-
Otherwise, it creates a new directory or file in the destination directory.
|
|
313
|
-
"""
|
|
314
|
-
is_copy = is_stage_path(destination_path)
|
|
315
|
-
if is_copy:
|
|
316
|
-
return QueryResult(
|
|
317
|
-
GitManager().copy_files(
|
|
318
|
-
source_path=repository_path, destination_path=destination_path
|
|
319
|
-
)
|
|
320
|
-
)
|
|
321
|
-
return get(
|
|
322
|
-
source_path=repository_path,
|
|
323
|
-
destination_path=destination_path,
|
|
324
|
-
parallel=parallel,
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
@app.command("execute", requires_connection=True)
|
|
329
|
-
def execute(
|
|
330
|
-
repository_path: str = RepoPathArgument,
|
|
331
|
-
on_error: OnErrorType = OnErrorOption,
|
|
332
|
-
variables: Optional[List[str]] = ExecuteVariablesOption,
|
|
333
|
-
**options,
|
|
334
|
-
):
|
|
335
|
-
"""
|
|
336
|
-
Execute immediate all files from the repository path. Files can be filtered with glob like pattern,
|
|
337
|
-
e.g. `@my_repo/branches/main/*.sql`, `@my_repo/branches/main/dev/*`. Only files with `.sql`
|
|
338
|
-
extension will be executed.
|
|
339
|
-
"""
|
|
340
|
-
results = GitManager().execute(
|
|
341
|
-
stage_path=repository_path, on_error=on_error, variables=variables
|
|
342
|
-
)
|
|
343
|
-
return CollectionResult(results)
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
def get(source_path: str, destination_path: str, parallel: int):
|
|
347
|
-
target = Path(destination_path).resolve()
|
|
348
|
-
|
|
349
|
-
cursors = GitManager().get_recursive(
|
|
350
|
-
stage_path=source_path, dest_path=target, parallel=parallel
|
|
351
|
-
)
|
|
352
|
-
results = [list(QueryResult(c).result) for c in cursors]
|
|
353
|
-
flattened_results = list(itertools.chain.from_iterable(results))
|
|
354
|
-
sorted_results = sorted(
|
|
355
|
-
flattened_results,
|
|
356
|
-
key=lambda e: (path.dirname(e["file"]), path.basename(e["file"])),
|
|
357
|
-
)
|
|
358
|
-
return CollectionResult(sorted_results)
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2024 Snowflake Inc.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from __future__ import annotations
|
|
16
|
-
|
|
17
|
-
from pathlib import Path, PurePosixPath
|
|
18
|
-
from textwrap import dedent
|
|
19
|
-
from typing import List
|
|
20
|
-
|
|
21
|
-
from click import UsageError
|
|
22
|
-
from snowflake.cli._plugins.stage.manager import (
|
|
23
|
-
USER_STAGE_PREFIX,
|
|
24
|
-
StageManager,
|
|
25
|
-
StagePathParts,
|
|
26
|
-
UserStagePathParts,
|
|
27
|
-
)
|
|
28
|
-
from snowflake.cli.api.identifiers import FQN
|
|
29
|
-
from snowflake.connector.cursor import SnowflakeCursor
|
|
30
|
-
|
|
31
|
-
# Replace magic numbers with constants
|
|
32
|
-
OMIT_FIRST = slice(1, None)
|
|
33
|
-
OMIT_STAGE = slice(3, None)
|
|
34
|
-
OMIT_STAGE_IN_NEW_LIST_FILES = slice(2, None)
|
|
35
|
-
ONLY_STAGE = slice(3)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
class GitStagePathParts(StagePathParts):
|
|
39
|
-
def __init__(self, stage_path: str):
|
|
40
|
-
self.stage = GitManager.get_stage_from_path(stage_path)
|
|
41
|
-
stage_path_parts = GitManager.split_git_path(stage_path)
|
|
42
|
-
git_repo_name = stage_path_parts[0].split(".")[-1]
|
|
43
|
-
if git_repo_name.startswith("@"):
|
|
44
|
-
git_repo_name = git_repo_name[OMIT_FIRST]
|
|
45
|
-
self.stage_name = "/".join([git_repo_name, *stage_path_parts[1:3], ""])
|
|
46
|
-
self.directory = "/".join(stage_path_parts[OMIT_STAGE])
|
|
47
|
-
self.is_directory = True if stage_path.endswith("/") else False
|
|
48
|
-
|
|
49
|
-
@property
|
|
50
|
-
def path(self) -> str:
|
|
51
|
-
return f"{self.stage_name.rstrip('/')}/{self.directory}"
|
|
52
|
-
|
|
53
|
-
@classmethod
|
|
54
|
-
def get_directory(cls, stage_path: str) -> str:
|
|
55
|
-
git_path_parts = GitManager.split_git_path(stage_path)
|
|
56
|
-
# New file list does not have a stage name at the beginning
|
|
57
|
-
if stage_path.startswith("/"):
|
|
58
|
-
return "/".join(git_path_parts[OMIT_STAGE_IN_NEW_LIST_FILES])
|
|
59
|
-
else:
|
|
60
|
-
return "/".join(git_path_parts[OMIT_STAGE])
|
|
61
|
-
|
|
62
|
-
@property
|
|
63
|
-
def full_path(self) -> str:
|
|
64
|
-
return f"{self.stage.rstrip('/')}/{self.directory}"
|
|
65
|
-
|
|
66
|
-
def replace_stage_prefix(self, file_path: str) -> str:
|
|
67
|
-
stage = Path(self.stage).parts[0]
|
|
68
|
-
file_path_without_prefix = Path(file_path).parts[OMIT_FIRST]
|
|
69
|
-
return f"{stage}/{'/'.join(file_path_without_prefix)}"
|
|
70
|
-
|
|
71
|
-
def add_stage_prefix(self, file_path: str) -> str:
|
|
72
|
-
stage = self.stage.rstrip("/")
|
|
73
|
-
return f"{stage}/{file_path.lstrip('/')}"
|
|
74
|
-
|
|
75
|
-
def get_directory_from_file_path(self, file_path: str) -> List[str]:
|
|
76
|
-
stage_path_length = len(Path(self.directory).parts)
|
|
77
|
-
return list(Path(file_path).parts[3 + stage_path_length : -1])
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
class GitManager(StageManager):
|
|
81
|
-
def show_branches(self, repo_name: str, like: str) -> SnowflakeCursor:
|
|
82
|
-
return self._execute_query(f"show git branches like '{like}' in {repo_name}")
|
|
83
|
-
|
|
84
|
-
def show_tags(self, repo_name: str, like: str) -> SnowflakeCursor:
|
|
85
|
-
return self._execute_query(f"show git tags like '{like}' in {repo_name}")
|
|
86
|
-
|
|
87
|
-
def fetch(self, fqn: FQN) -> SnowflakeCursor:
|
|
88
|
-
return self._execute_query(f"alter git repository {fqn} fetch")
|
|
89
|
-
|
|
90
|
-
def create(
|
|
91
|
-
self, repo_name: FQN, api_integration: str, url: str, secret: str
|
|
92
|
-
) -> SnowflakeCursor:
|
|
93
|
-
query = dedent(
|
|
94
|
-
f"""
|
|
95
|
-
create git repository {repo_name.sql_identifier}
|
|
96
|
-
api_integration = {api_integration}
|
|
97
|
-
origin = '{url}'
|
|
98
|
-
"""
|
|
99
|
-
)
|
|
100
|
-
if secret is not None:
|
|
101
|
-
query += f"git_credentials = {secret}\n"
|
|
102
|
-
return self._execute_query(query)
|
|
103
|
-
|
|
104
|
-
@staticmethod
|
|
105
|
-
def get_stage_from_path(path: str):
|
|
106
|
-
"""
|
|
107
|
-
Returns stage name from potential path on stage. For example
|
|
108
|
-
repo/branches/main/foo/bar -> repo/branches/main/
|
|
109
|
-
"""
|
|
110
|
-
path_parts = GitManager.split_git_path(path)
|
|
111
|
-
return f"{'/'.join(path_parts[ONLY_STAGE])}/"
|
|
112
|
-
|
|
113
|
-
@staticmethod
|
|
114
|
-
def _stage_path_part_factory(stage_path: str) -> StagePathParts:
|
|
115
|
-
stage_path = StageManager.get_standard_stage_prefix(stage_path)
|
|
116
|
-
if stage_path.startswith(USER_STAGE_PREFIX):
|
|
117
|
-
return UserStagePathParts(stage_path)
|
|
118
|
-
return GitStagePathParts(stage_path)
|
|
119
|
-
|
|
120
|
-
@staticmethod
|
|
121
|
-
def split_git_path(path: str):
|
|
122
|
-
# Check if path contains quotes and split it accordingly
|
|
123
|
-
if '/"' in path and '"/' in path:
|
|
124
|
-
if path.count('"') > 2:
|
|
125
|
-
raise UsageError(
|
|
126
|
-
f'Invalid string {path}, too much " in path, expected 2.'
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
path_parts = path.split('"')
|
|
130
|
-
before_quoted_part = GitManager._split_path_without_empty_parts(
|
|
131
|
-
path_parts[0]
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
if path_parts[2] == "/":
|
|
135
|
-
after_quoted_part = []
|
|
136
|
-
else:
|
|
137
|
-
after_quoted_part = GitManager._split_path_without_empty_parts(
|
|
138
|
-
path_parts[2]
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
return [
|
|
142
|
-
*before_quoted_part,
|
|
143
|
-
f'"{path_parts[1]}"',
|
|
144
|
-
*after_quoted_part,
|
|
145
|
-
]
|
|
146
|
-
else:
|
|
147
|
-
return GitManager._split_path_without_empty_parts(path)
|
|
148
|
-
|
|
149
|
-
@staticmethod
|
|
150
|
-
def _split_path_without_empty_parts(path: str):
|
|
151
|
-
return [e for e in PurePosixPath(path).parts if e != "/"]
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2024 Snowflake Inc.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from snowflake.cli._plugins.git import commands
|
|
16
|
-
from snowflake.cli.api.plugins.command import (
|
|
17
|
-
SNOWCLI_ROOT_COMMAND_PATH,
|
|
18
|
-
CommandSpec,
|
|
19
|
-
CommandType,
|
|
20
|
-
plugin_hook_impl,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@plugin_hook_impl
|
|
25
|
-
def command_spec():
|
|
26
|
-
return CommandSpec(
|
|
27
|
-
parent_command_path=SNOWCLI_ROOT_COMMAND_PATH,
|
|
28
|
-
command_type=CommandType.COMMAND_GROUP,
|
|
29
|
-
typer_instance=commands.app.create_instance(),
|
|
30
|
-
)
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2024 Snowflake Inc.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2024 Snowflake Inc.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from __future__ import annotations
|
|
16
|
-
|
|
17
|
-
import typer
|
|
18
|
-
import yaml
|
|
19
|
-
from click import ClickException
|
|
20
|
-
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
|
|
21
|
-
from snowflake.cli.api.output.types import MessageResult
|
|
22
|
-
from snowflake.cli.api.project.definition_conversion import (
|
|
23
|
-
convert_project_definition_to_v2,
|
|
24
|
-
)
|
|
25
|
-
from snowflake.cli.api.project.definition_manager import DefinitionManager
|
|
26
|
-
from snowflake.cli.api.secure_path import SecurePath
|
|
27
|
-
|
|
28
|
-
app = SnowTyperFactory(
|
|
29
|
-
name="helpers",
|
|
30
|
-
help="Helper commands.",
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@app.command()
|
|
35
|
-
def v1_to_v2(
|
|
36
|
-
accept_templates: bool = typer.Option(
|
|
37
|
-
False, "-t", "--accept-templates", help="Allows the migration of templates."
|
|
38
|
-
),
|
|
39
|
-
migrate_local_yml: (bool | None) = typer.Option(
|
|
40
|
-
None,
|
|
41
|
-
"-l",
|
|
42
|
-
"--migrate-local-overrides/--no-migrate-local-overrides",
|
|
43
|
-
help=(
|
|
44
|
-
"Merge values in snowflake.local.yml into the main project definition. "
|
|
45
|
-
"The snowflake.local.yml file will not be migrated, "
|
|
46
|
-
"instead its values will be reflected in the output snowflake.yml file. "
|
|
47
|
-
"If unset and snowflake.local.yml is present, an error will be raised."
|
|
48
|
-
),
|
|
49
|
-
show_default=False,
|
|
50
|
-
),
|
|
51
|
-
**options,
|
|
52
|
-
):
|
|
53
|
-
"""Migrates the Snowpark, Streamlit, and Native App project definition files from V1 to V2."""
|
|
54
|
-
manager = DefinitionManager()
|
|
55
|
-
local_yml_path = manager.project_root / "snowflake.local.yml"
|
|
56
|
-
has_local_yml = local_yml_path in manager.project_config_paths
|
|
57
|
-
if has_local_yml:
|
|
58
|
-
if migrate_local_yml is None:
|
|
59
|
-
raise ClickException(
|
|
60
|
-
"snowflake.local.yml file detected, "
|
|
61
|
-
"please specify --migrate-local-overrides to include "
|
|
62
|
-
"or --no-migrate-local-overrides to exclude its values."
|
|
63
|
-
)
|
|
64
|
-
if not migrate_local_yml:
|
|
65
|
-
# If we don't want the local file,
|
|
66
|
-
# remove it from the list of paths to load
|
|
67
|
-
manager.project_config_paths.remove(local_yml_path)
|
|
68
|
-
|
|
69
|
-
pd = manager.unrendered_project_definition
|
|
70
|
-
|
|
71
|
-
if pd.meets_version_requirement("2"):
|
|
72
|
-
return MessageResult("Project definition is already at version 2.")
|
|
73
|
-
|
|
74
|
-
pd_v2 = convert_project_definition_to_v2(
|
|
75
|
-
manager.project_root, pd, accept_templates, manager.template_context
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
SecurePath("snowflake.yml").rename("snowflake_V1.yml")
|
|
79
|
-
if has_local_yml:
|
|
80
|
-
SecurePath("snowflake.local.yml").rename("snowflake_V1.local.yml")
|
|
81
|
-
with open("snowflake.yml", "w") as file:
|
|
82
|
-
yaml.dump(
|
|
83
|
-
pd_v2.model_dump(
|
|
84
|
-
exclude_unset=True, exclude_none=True, mode="json", by_alias=True
|
|
85
|
-
),
|
|
86
|
-
file,
|
|
87
|
-
sort_keys=False,
|
|
88
|
-
width=float("inf"), # Don't break lines
|
|
89
|
-
)
|
|
90
|
-
return MessageResult("Project definition migrated to version 2.")
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2024 Snowflake Inc.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from snowflake.cli._plugins.helpers import commands
|
|
16
|
-
from snowflake.cli.api.plugins.command import (
|
|
17
|
-
SNOWCLI_ROOT_COMMAND_PATH,
|
|
18
|
-
CommandSpec,
|
|
19
|
-
CommandType,
|
|
20
|
-
plugin_hook_impl,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@plugin_hook_impl
|
|
25
|
-
def command_spec():
|
|
26
|
-
return CommandSpec(
|
|
27
|
-
parent_command_path=SNOWCLI_ROOT_COMMAND_PATH,
|
|
28
|
-
command_type=CommandType.COMMAND_GROUP,
|
|
29
|
-
typer_instance=commands.app.create_instance(),
|
|
30
|
-
)
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2024 Snowflake Inc.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|