snowflake-cli-labs 3.0.0rc4__py3-none-any.whl → 3.0.1__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.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/METADATA +6 -96
- snowflake_cli_labs-3.0.1.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 -61
- 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 -395
- 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.0rc4.dist-info/RECORD +0 -242
- snowflake_cli_labs-3.0.0rc4.dist-info/entry_points.txt +0 -2
- {snowflake_cli_labs-3.0.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/WHEEL +0 -0
- {snowflake_cli_labs-3.0.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,248 +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 logging
|
|
18
|
-
from typing import Any, Dict, List, Optional
|
|
19
|
-
|
|
20
|
-
import typer
|
|
21
|
-
import yaml
|
|
22
|
-
from click import ClickException
|
|
23
|
-
from snowflake.cli.__about__ import VERSION
|
|
24
|
-
from snowflake.cli.api.commands.flags import (
|
|
25
|
-
NoInteractiveOption,
|
|
26
|
-
variables_option,
|
|
27
|
-
)
|
|
28
|
-
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
|
|
29
|
-
from snowflake.cli.api.commands.utils import parse_key_value_variables
|
|
30
|
-
from snowflake.cli.api.constants import DEFAULT_SIZE_LIMIT_MB
|
|
31
|
-
from snowflake.cli.api.exceptions import InvalidTemplate
|
|
32
|
-
from snowflake.cli.api.output.types import (
|
|
33
|
-
CommandResult,
|
|
34
|
-
MessageResult,
|
|
35
|
-
)
|
|
36
|
-
from snowflake.cli.api.project.schemas.template import Template, TemplateVariable
|
|
37
|
-
from snowflake.cli.api.rendering.project_templates import render_template_files
|
|
38
|
-
from snowflake.cli.api.secure_path import SecurePath
|
|
39
|
-
|
|
40
|
-
# simple Typer with defaults because it won't become a command group as it contains only one command
|
|
41
|
-
app = SnowTyperFactory()
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
DEFAULT_SOURCE = "https://github.com/snowflakedb/snowflake-cli-templates"
|
|
45
|
-
|
|
46
|
-
log = logging.getLogger(__name__)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def _path_argument_callback(path: str) -> str:
|
|
50
|
-
if SecurePath(path).exists():
|
|
51
|
-
raise ClickException(
|
|
52
|
-
f"The directory {path} already exists. Please specify a different path for the project."
|
|
53
|
-
)
|
|
54
|
-
return path
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
PathArgument = typer.Argument(
|
|
58
|
-
...,
|
|
59
|
-
help="Directory to be initialized with the project. This directory must not already exist",
|
|
60
|
-
show_default=False,
|
|
61
|
-
callback=_path_argument_callback,
|
|
62
|
-
)
|
|
63
|
-
TemplateOption = typer.Option(
|
|
64
|
-
None,
|
|
65
|
-
"--template",
|
|
66
|
-
help="which template (subdirectory of --template-source) should be used. If not provided,"
|
|
67
|
-
" whole source will be used as the template.",
|
|
68
|
-
show_default=False,
|
|
69
|
-
)
|
|
70
|
-
SourceOption = typer.Option(
|
|
71
|
-
DEFAULT_SOURCE,
|
|
72
|
-
"--template-source",
|
|
73
|
-
help=f"local path to template directory or URL to git repository with templates.",
|
|
74
|
-
)
|
|
75
|
-
VariablesOption = variables_option(
|
|
76
|
-
"String in `key=value` format. Provided variables will not be prompted for."
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
TEMPLATE_METADATA_FILE_NAME = "template.yml"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def _fetch_local_template(
|
|
83
|
-
template_source: SecurePath, path: Optional[str], destination: SecurePath
|
|
84
|
-
) -> SecurePath:
|
|
85
|
-
"""Copies local template to [dest] and returns path to the template root.
|
|
86
|
-
Ends with an error of the template does not exist."""
|
|
87
|
-
|
|
88
|
-
template_source.assert_exists()
|
|
89
|
-
template_origin = template_source / path if path else template_source
|
|
90
|
-
log.info("Copying local template from %s", template_origin.path)
|
|
91
|
-
if not template_origin.exists():
|
|
92
|
-
raise ClickException(
|
|
93
|
-
f"Template '{path}' cannot be found under {template_source}"
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
template_origin.copy(destination.path)
|
|
97
|
-
return destination / template_origin.name
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def _fetch_remote_template(
|
|
101
|
-
url: str, path: Optional[str], destination: SecurePath
|
|
102
|
-
) -> SecurePath:
|
|
103
|
-
"""Downloads remote repository template to [dest],
|
|
104
|
-
and returns path to the template root.
|
|
105
|
-
Ends with an error of the template does not exist."""
|
|
106
|
-
from git import GitCommandError
|
|
107
|
-
from git import rmtree as git_rmtree
|
|
108
|
-
|
|
109
|
-
# TODO: during nativeapp refactor get rid of this dependency
|
|
110
|
-
from snowflake.cli._plugins.nativeapp.utils import shallow_git_clone
|
|
111
|
-
|
|
112
|
-
log.info("Downloading remote template from %s", url)
|
|
113
|
-
try:
|
|
114
|
-
shallow_git_clone(url, to_path=destination.path)
|
|
115
|
-
except GitCommandError as err:
|
|
116
|
-
import re
|
|
117
|
-
|
|
118
|
-
if re.search("fatal: repository '.*' not found", err.stderr):
|
|
119
|
-
raise ClickException(f"Repository '{url}' does not exist")
|
|
120
|
-
raise
|
|
121
|
-
|
|
122
|
-
if path:
|
|
123
|
-
# template is a subdirectoruy of the repository
|
|
124
|
-
template_root = destination / path
|
|
125
|
-
else:
|
|
126
|
-
# template is a whole repository
|
|
127
|
-
# removing .git directory not to copy it to the template
|
|
128
|
-
template_root = destination
|
|
129
|
-
git_rmtree((template_root / ".git").path)
|
|
130
|
-
if not template_root.exists():
|
|
131
|
-
raise ClickException(f"Template '{path}' cannot be found under {url}")
|
|
132
|
-
|
|
133
|
-
return template_root
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def _read_template_metadata(template_root: SecurePath, args_error_msg: str) -> Template:
|
|
137
|
-
"""Parse template.yml file."""
|
|
138
|
-
template_metadata_path = template_root / TEMPLATE_METADATA_FILE_NAME
|
|
139
|
-
log.debug("Reading template metadata from %s", template_metadata_path.path)
|
|
140
|
-
if not template_metadata_path.exists():
|
|
141
|
-
raise InvalidTemplate(
|
|
142
|
-
f"File {TEMPLATE_METADATA_FILE_NAME} not found. {args_error_msg}"
|
|
143
|
-
)
|
|
144
|
-
with template_metadata_path.open(read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB) as fd:
|
|
145
|
-
yaml_contents = yaml.safe_load(fd) or {}
|
|
146
|
-
return Template(template_root, **yaml_contents)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
def _remove_template_metadata_file(template_root: SecurePath) -> None:
|
|
150
|
-
(template_root / TEMPLATE_METADATA_FILE_NAME).unlink()
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
def _determine_variable_values(
|
|
154
|
-
variables_metadata: List[TemplateVariable],
|
|
155
|
-
variables_from_flags: Dict[str, Any],
|
|
156
|
-
no_interactive: bool,
|
|
157
|
-
) -> Dict[str, Any]:
|
|
158
|
-
"""
|
|
159
|
-
Prompt user for values not provided in [variables_from_flags].
|
|
160
|
-
If [no_interactive] is True, fill not provided variables with their default values.
|
|
161
|
-
"""
|
|
162
|
-
result = {}
|
|
163
|
-
|
|
164
|
-
log.debug(
|
|
165
|
-
"Resolving values of variables: %s",
|
|
166
|
-
", ".join(v.name for v in variables_metadata),
|
|
167
|
-
)
|
|
168
|
-
for variable in variables_metadata:
|
|
169
|
-
if variable.name in variables_from_flags:
|
|
170
|
-
value = variable.python_type(variables_from_flags[variable.name])
|
|
171
|
-
else:
|
|
172
|
-
value = variable.prompt_user_for_value(no_interactive)
|
|
173
|
-
|
|
174
|
-
result[variable.name] = value
|
|
175
|
-
|
|
176
|
-
return result
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
def _validate_cli_version(required_version: str) -> None:
|
|
180
|
-
from packaging.version import parse
|
|
181
|
-
|
|
182
|
-
if parse(required_version) > parse(VERSION):
|
|
183
|
-
raise ClickException(
|
|
184
|
-
f"Snowflake CLI version ({VERSION}) is too low - minimum version required"
|
|
185
|
-
f" by template is {required_version}. Please upgrade before continuing."
|
|
186
|
-
)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
@app.command(no_args_is_help=True)
|
|
190
|
-
def init(
|
|
191
|
-
path: str = PathArgument,
|
|
192
|
-
template: Optional[str] = TemplateOption,
|
|
193
|
-
template_source: Optional[str] = SourceOption,
|
|
194
|
-
variables: Optional[List[str]] = VariablesOption,
|
|
195
|
-
no_interactive: bool = NoInteractiveOption,
|
|
196
|
-
**options,
|
|
197
|
-
) -> CommandResult:
|
|
198
|
-
"""
|
|
199
|
-
Creates project directory from template.
|
|
200
|
-
"""
|
|
201
|
-
variables_from_flags = {
|
|
202
|
-
v.key: v.value for v in parse_key_value_variables(variables)
|
|
203
|
-
}
|
|
204
|
-
is_remote = any(
|
|
205
|
-
template_source.startswith(prefix) for prefix in ["git@", "http://", "https://"] # type: ignore
|
|
206
|
-
)
|
|
207
|
-
args_error_msg = f"Check whether {TemplateOption.param_decls[0]} and {SourceOption.param_decls[0]} arguments are correct."
|
|
208
|
-
|
|
209
|
-
# copy/download template into tmpdir, so it is going to be removed in case command ends with an error
|
|
210
|
-
with SecurePath.temporary_directory() as tmpdir:
|
|
211
|
-
if is_remote:
|
|
212
|
-
template_root = _fetch_remote_template(
|
|
213
|
-
url=template_source, path=template, destination=tmpdir # type: ignore
|
|
214
|
-
)
|
|
215
|
-
else:
|
|
216
|
-
template_root = _fetch_local_template(
|
|
217
|
-
template_source=SecurePath(template_source),
|
|
218
|
-
path=template,
|
|
219
|
-
destination=tmpdir,
|
|
220
|
-
)
|
|
221
|
-
|
|
222
|
-
template_metadata = _read_template_metadata(
|
|
223
|
-
template_root, args_error_msg=args_error_msg
|
|
224
|
-
)
|
|
225
|
-
if template_metadata.minimum_cli_version:
|
|
226
|
-
_validate_cli_version(template_metadata.minimum_cli_version)
|
|
227
|
-
|
|
228
|
-
variable_values = _determine_variable_values(
|
|
229
|
-
variables_metadata=template_metadata.variables,
|
|
230
|
-
variables_from_flags=variables_from_flags,
|
|
231
|
-
no_interactive=no_interactive,
|
|
232
|
-
) | {
|
|
233
|
-
"project_dir_name": SecurePath(path).name,
|
|
234
|
-
"snowflake_cli_version": VERSION,
|
|
235
|
-
}
|
|
236
|
-
log.debug(
|
|
237
|
-
"Rendering template files: %s", ", ".join(template_metadata.files_to_render)
|
|
238
|
-
)
|
|
239
|
-
render_template_files(
|
|
240
|
-
template_root=template_root,
|
|
241
|
-
files_to_render=template_metadata.files_to_render,
|
|
242
|
-
data=variable_values,
|
|
243
|
-
)
|
|
244
|
-
_remove_template_metadata_file(template_root)
|
|
245
|
-
SecurePath(path).parent.mkdir(exist_ok=True, parents=True)
|
|
246
|
-
template_root.copy(path)
|
|
247
|
-
|
|
248
|
-
return MessageResult(f"Initialized the new project in {path}")
|
|
@@ -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.init 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.SINGLE_COMMAND,
|
|
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.
|