snowflake-cli-labs 2.8.0rc1__py3-none-any.whl → 3.0.0rc1__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.
- snowflake/cli/__about__.py +1 -1
- snowflake/cli/{app → _app}/__main__.py +1 -1
- snowflake/cli/{app → _app}/cli_app.py +12 -12
- snowflake/cli/{app → _app}/commands_registration/builtin_plugins.py +13 -19
- snowflake/cli/{app → _app}/commands_registration/command_plugins_loader.py +9 -9
- snowflake/cli/{app → _app}/commands_registration/commands_registration_with_callbacks.py +4 -4
- snowflake/cli/{app → _app}/commands_registration/exception_logging.py +2 -2
- snowflake/cli/{app → _app}/commands_registration/typer_registration.py +2 -2
- snowflake/cli/{app → _app}/dev/docs/commands_docs_generator.py +30 -12
- snowflake/cli/{app → _app}/dev/docs/generator.py +3 -3
- snowflake/cli/{app → _app}/dev/docs/project_definition_docs_generator.py +4 -4
- snowflake/cli/{app → _app}/dev/docs/templates/usage.rst.jinja2 +14 -4
- snowflake/cli/{app → _app}/main_typer.py +2 -2
- snowflake/cli/{app → _app}/printing.py +2 -2
- snowflake/cli/{app → _app}/snow_connector.py +24 -17
- snowflake/cli/{app → _app}/telemetry.py +4 -5
- snowflake/cli/{plugins → _plugins}/connection/commands.py +25 -7
- snowflake/cli/_plugins/connection/plugin_spec.py +30 -0
- snowflake/cli/{plugins → _plugins}/connection/util.py +16 -0
- snowflake/cli/{plugins → _plugins}/cortex/commands.py +54 -49
- snowflake/cli/{plugins → _plugins}/cortex/constants.py +1 -1
- snowflake/cli/{plugins → _plugins}/cortex/manager.py +5 -5
- snowflake/cli/{plugins → _plugins}/cortex/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/git/commands.py +32 -20
- snowflake/cli/{plugins → _plugins}/git/manager.py +20 -11
- snowflake/cli/{plugins → _plugins}/git/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/init/commands.py +10 -6
- snowflake/cli/{plugins → _plugins}/init/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/nativeapp/artifacts.py +14 -0
- snowflake/cli/_plugins/nativeapp/bundle_context.py +31 -0
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/artifact_processor.py +3 -3
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/compiler.py +32 -18
- snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +249 -0
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/setup/setup_driver.py.source +5 -2
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/extension_function_utils.py +4 -4
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/python_processor.py +23 -29
- snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +93 -0
- snowflake/cli/{plugins → _plugins}/nativeapp/commands.py +171 -42
- snowflake/cli/{plugins → _plugins}/nativeapp/common_flags.py +1 -1
- snowflake/cli/{plugins → _plugins}/nativeapp/exceptions.py +3 -3
- snowflake/cli/{plugins → _plugins}/nativeapp/init.py +1 -1
- snowflake/cli/_plugins/nativeapp/manager.py +572 -0
- snowflake/cli/{plugins/connection → _plugins/nativeapp}/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/nativeapp/project_model.py +35 -19
- snowflake/cli/{plugins → _plugins}/nativeapp/run_processor.py +25 -23
- snowflake/cli/{plugins → _plugins}/nativeapp/teardown_processor.py +24 -110
- snowflake/cli/{plugins → _plugins}/nativeapp/v2_conversions/v2_to_v1_decorator.py +47 -28
- snowflake/cli/{plugins → _plugins}/nativeapp/version/commands.py +15 -12
- snowflake/cli/{plugins → _plugins}/nativeapp/version/version_processor.py +22 -20
- snowflake/cli/{plugins → _plugins}/notebook/commands.py +8 -6
- snowflake/cli/{plugins → _plugins}/notebook/manager.py +14 -14
- snowflake/cli/{plugins → _plugins}/notebook/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/notebook/types.py +0 -1
- snowflake/cli/{plugins → _plugins}/object/command_aliases.py +6 -5
- snowflake/cli/{plugins → _plugins}/object/commands.py +16 -10
- snowflake/cli/{plugins → _plugins}/object/manager.py +7 -6
- snowflake/cli/{plugins → _plugins}/object/plugin_spec.py +1 -1
- snowflake/cli/_plugins/snowpark/commands.py +450 -0
- snowflake/cli/_plugins/snowpark/common.py +268 -0
- snowflake/cli/{plugins → _plugins}/snowpark/models.py +0 -7
- snowflake/cli/{plugins → _plugins}/snowpark/package/anaconda_packages.py +2 -36
- snowflake/cli/{plugins → _plugins}/snowpark/package/commands.py +13 -74
- snowflake/cli/{plugins → _plugins}/snowpark/package/manager.py +4 -3
- snowflake/cli/{plugins → _plugins}/snowpark/package_utils.py +5 -5
- snowflake/cli/{plugins/nativeapp → _plugins/snowpark}/plugin_spec.py +1 -1
- snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +109 -0
- snowflake/cli/{plugins → _plugins}/snowpark/snowpark_shared.py +0 -36
- snowflake/cli/{plugins → _plugins}/snowpark/zipper.py +16 -8
- snowflake/cli/{plugins → _plugins}/spcs/__init__.py +5 -7
- snowflake/cli/{plugins → _plugins}/spcs/compute_pool/commands.py +29 -28
- snowflake/cli/{plugins → _plugins}/spcs/compute_pool/manager.py +3 -3
- snowflake/cli/{plugins → _plugins}/spcs/image_registry/commands.py +3 -3
- snowflake/cli/{plugins → _plugins}/spcs/image_repository/commands.py +25 -19
- snowflake/cli/{plugins → _plugins}/spcs/image_repository/manager.py +1 -1
- snowflake/cli/{plugins → _plugins}/spcs/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/spcs/services/commands.py +66 -32
- snowflake/cli/{plugins → _plugins}/spcs/services/manager.py +43 -5
- snowflake/cli/{plugins → _plugins}/sql/commands.py +20 -17
- snowflake/cli/{plugins → _plugins}/sql/manager.py +1 -1
- snowflake/cli/{plugins → _plugins}/sql/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/stage/commands.py +20 -17
- snowflake/cli/{plugins → _plugins}/stage/diff.py +1 -47
- snowflake/cli/{plugins → _plugins}/stage/manager.py +54 -21
- snowflake/cli/{plugins → _plugins}/stage/plugin_spec.py +1 -1
- snowflake/cli/_plugins/stage/utils.py +54 -0
- snowflake/cli/{plugins → _plugins}/streamlit/commands.py +59 -62
- snowflake/cli/{plugins → _plugins}/streamlit/manager.py +51 -70
- snowflake/cli/_plugins/streamlit/plugin_spec.py +30 -0
- snowflake/cli/_plugins/workspace/action_context.py +17 -0
- snowflake/cli/_plugins/workspace/commands.py +194 -0
- snowflake/cli/_plugins/workspace/manager.py +73 -0
- snowflake/cli/{plugins → _plugins}/workspace/plugin_spec.py +1 -1
- snowflake/cli/api/cli_global_context.py +40 -13
- snowflake/cli/api/commands/common.py +25 -0
- snowflake/cli/api/commands/decorators.py +5 -4
- snowflake/cli/api/commands/experimental_behaviour.py +2 -3
- snowflake/cli/api/commands/flags.py +97 -179
- snowflake/cli/api/commands/overrideable_parameter.py +143 -0
- snowflake/cli/api/commands/snow_typer.py +14 -6
- snowflake/cli/api/commands/typer_pre_execute.py +3 -3
- snowflake/cli/api/commands/utils.py +18 -0
- snowflake/cli/api/config.py +18 -5
- snowflake/cli/api/console/abc.py +5 -2
- snowflake/cli/api/constants.py +11 -0
- snowflake/cli/api/entities/application_entity.py +12 -0
- snowflake/cli/api/entities/application_package_entity.py +553 -0
- snowflake/cli/api/entities/common.py +51 -0
- snowflake/cli/api/entities/snowpark_entity.py +29 -0
- snowflake/cli/api/entities/streamlit_entity.py +12 -0
- snowflake/cli/api/entities/utils.py +357 -0
- snowflake/cli/api/exceptions.py +31 -5
- snowflake/cli/api/feature_flags.py +0 -1
- snowflake/cli/api/identifiers.py +41 -9
- snowflake/cli/api/project/definition.py +37 -6
- snowflake/cli/api/project/definition_conversion.py +194 -0
- snowflake/cli/api/project/definition_manager.py +12 -1
- snowflake/cli/api/project/project_verification.py +3 -3
- snowflake/cli/api/project/schemas/entities/{application_entity.py → application_entity_model.py} +21 -9
- snowflake/cli/api/project/schemas/entities/{application_package_entity.py → application_package_entity_model.py} +43 -15
- snowflake/cli/api/project/schemas/entities/common.py +80 -6
- snowflake/cli/api/project/schemas/entities/entities.py +38 -8
- snowflake/cli/api/project/schemas/entities/snowpark_entity.py +176 -0
- snowflake/cli/api/project/schemas/entities/streamlit_entity_model.py +73 -0
- snowflake/cli/api/project/schemas/identifier_model.py +10 -1
- snowflake/cli/api/project/schemas/native_app/application.py +8 -9
- snowflake/cli/api/project/schemas/native_app/package.py +7 -1
- snowflake/cli/api/project/schemas/project_definition.py +98 -27
- snowflake/cli/api/project/schemas/updatable_model.py +11 -3
- snowflake/cli/api/project/util.py +23 -6
- snowflake/cli/api/rendering/jinja.py +14 -8
- snowflake/cli/api/rendering/project_definition_templates.py +1 -1
- snowflake/cli/api/rendering/sql_templates.py +43 -11
- snowflake/cli/api/secure_path.py +16 -18
- snowflake/cli/api/secure_utils.py +90 -1
- snowflake/cli/api/sql_execution.py +48 -19
- snowflake/cli/api/utils/definition_rendering.py +18 -8
- {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0rc1.dist-info}/METADATA +13 -13
- snowflake_cli_labs-3.0.0rc1.dist-info/RECORD +236 -0
- snowflake_cli_labs-3.0.0rc1.dist-info/entry_points.txt +2 -0
- snowflake/cli/api/commands/project_initialisation.py +0 -65
- snowflake/cli/app/build_and_push.sh +0 -8
- snowflake/cli/plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -172
- snowflake/cli/plugins/nativeapp/manager.py +0 -823
- snowflake/cli/plugins/object_stage_deprecated/__init__.py +0 -15
- snowflake/cli/plugins/object_stage_deprecated/commands.py +0 -122
- snowflake/cli/plugins/object_stage_deprecated/plugin_spec.py +0 -32
- snowflake/cli/plugins/snowpark/commands.py +0 -548
- snowflake/cli/plugins/snowpark/common.py +0 -307
- snowflake/cli/plugins/snowpark/manager.py +0 -109
- snowflake/cli/plugins/snowpark/plugin_spec.py +0 -30
- snowflake/cli/plugins/snowpark/snowpark_package_paths.py +0 -65
- snowflake/cli/plugins/spcs/jobs/commands.py +0 -78
- snowflake/cli/plugins/spcs/jobs/manager.py +0 -53
- snowflake/cli/plugins/streamlit/plugin_spec.py +0 -30
- snowflake/cli/plugins/workspace/commands.py +0 -35
- snowflake/cli/templates/default_snowpark/.gitignore +0 -4
- snowflake/cli/templates/default_snowpark/app/__init__.py +0 -0
- snowflake/cli/templates/default_snowpark/app/common.py +0 -2
- snowflake/cli/templates/default_snowpark/app/functions.py +0 -15
- snowflake/cli/templates/default_snowpark/app/procedures.py +0 -22
- snowflake/cli/templates/default_snowpark/requirements.txt +0 -1
- snowflake/cli/templates/default_snowpark/snowflake.yml +0 -23
- snowflake/cli/templates/default_streamlit/.gitignore +0 -4
- snowflake/cli/templates/default_streamlit/common/hello.py +0 -2
- snowflake/cli/templates/default_streamlit/environment.yml +0 -6
- snowflake/cli/templates/default_streamlit/pages/my_page.py +0 -3
- snowflake/cli/templates/default_streamlit/snowflake.yml +0 -10
- snowflake/cli/templates/default_streamlit/streamlit_app.py +0 -4
- snowflake_cli_labs-2.8.0rc1.dist-info/RECORD +0 -240
- snowflake_cli_labs-2.8.0rc1.dist-info/entry_points.txt +0 -2
- /snowflake/cli/{app → _app}/__init__.py +0 -0
- /snowflake/cli/{app → _app}/api_impl/__init__.py +0 -0
- /snowflake/cli/{app → _app}/api_impl/plugin/__init__.py +0 -0
- /snowflake/cli/{app → _app}/api_impl/plugin/plugin_config_provider_impl.py +0 -0
- /snowflake/cli/{app → _app}/commands_registration/__init__.py +0 -0
- /snowflake/cli/{app → _app}/commands_registration/threadsafe.py +0 -0
- /snowflake/cli/{app → _app}/constants.py +0 -0
- /snowflake/cli/{app → _app}/dev/__init__.py +0 -0
- /snowflake/cli/{app → _app}/dev/commands_structure.py +0 -0
- /snowflake/cli/{app → _app}/dev/docs/__init__.py +0 -0
- /snowflake/cli/{app → _app}/dev/docs/project_definition_generate_json_schema.py +0 -0
- /snowflake/cli/{app → _app}/dev/docs/template_utils.py +0 -0
- /snowflake/cli/{app → _app}/dev/docs/templates/definition_description.rst.jinja2 +0 -0
- /snowflake/cli/{app → _app}/dev/docs/templates/overview.rst.jinja2 +0 -0
- /snowflake/cli/{app → _app}/dev/pycharm_remote_debug.py +0 -0
- /snowflake/cli/{app → _app}/loggers.py +0 -0
- /snowflake/cli/{plugins → _plugins}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/connection/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/cortex/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/cortex/types.py +0 -0
- /snowflake/cli/{plugins → _plugins}/git/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/init/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/sandbox.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/models.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/constants.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/feature_flags.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/policy.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/utils.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/version/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/notebook/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/notebook/exceptions.py +0 -0
- /snowflake/cli/{plugins → _plugins}/object/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/object/common.py +0 -0
- /snowflake/cli/{plugins → _plugins}/snowpark/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/snowpark/package/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/snowpark/package/utils.py +0 -0
- /snowflake/cli/{plugins → _plugins}/spcs/common.py +0 -0
- /snowflake/cli/{plugins → _plugins}/spcs/compute_pool/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/spcs/image_registry/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/spcs/image_registry/manager.py +0 -0
- /snowflake/cli/{plugins → _plugins}/spcs/image_repository/__init__.py +0 -0
- /snowflake/cli/{plugins/spcs/jobs → _plugins/spcs/services}/__init__.py +0 -0
- /snowflake/cli/{plugins/spcs/services → _plugins/sql}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/sql/snowsql_templating.py +0 -0
- /snowflake/cli/{plugins/sql → _plugins/stage}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/stage/md5.py +0 -0
- /snowflake/cli/{plugins/stage → _plugins/streamlit}/__init__.py +0 -0
- /snowflake/cli/{plugins/streamlit → _plugins/workspace}/__init__.py +0 -0
- /snowflake/cli/{plugins/workspace → api/project/schemas/entities}/__init__.py +0 -0
- {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0rc1.dist-info}/WHEEL +0 -0
- {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0rc1.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,194 @@
|
|
|
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 pathlib import Path
|
|
19
|
+
from textwrap import dedent
|
|
20
|
+
from typing import List, Optional
|
|
21
|
+
|
|
22
|
+
import typer
|
|
23
|
+
import yaml
|
|
24
|
+
from snowflake.cli._plugins.nativeapp.artifacts import BundleMap
|
|
25
|
+
from snowflake.cli._plugins.nativeapp.common_flags import (
|
|
26
|
+
ForceOption,
|
|
27
|
+
ValidateOption,
|
|
28
|
+
)
|
|
29
|
+
from snowflake.cli._plugins.workspace.manager import WorkspaceManager
|
|
30
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
31
|
+
from snowflake.cli.api.commands.decorators import with_project_definition
|
|
32
|
+
from snowflake.cli.api.commands.snow_typer import SnowTyper
|
|
33
|
+
from snowflake.cli.api.entities.common import EntityActions
|
|
34
|
+
from snowflake.cli.api.exceptions import IncompatibleParametersError
|
|
35
|
+
from snowflake.cli.api.output.types import MessageResult
|
|
36
|
+
from snowflake.cli.api.project.definition_conversion import (
|
|
37
|
+
convert_project_definition_to_v2,
|
|
38
|
+
)
|
|
39
|
+
from snowflake.cli.api.project.definition_manager import DefinitionManager
|
|
40
|
+
from snowflake.cli.api.secure_path import SecurePath
|
|
41
|
+
|
|
42
|
+
ws = SnowTyper(
|
|
43
|
+
name="ws",
|
|
44
|
+
help="Deploy and interact with snowflake.yml-based entities.",
|
|
45
|
+
)
|
|
46
|
+
log = logging.getLogger(__name__)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@ws.command()
|
|
50
|
+
def migrate(
|
|
51
|
+
accept_templates: bool = typer.Option(
|
|
52
|
+
False, "-t", "--accept-templates", help="Allows the migration of templates."
|
|
53
|
+
),
|
|
54
|
+
**options,
|
|
55
|
+
):
|
|
56
|
+
"""Migrates the Snowpark and Streamlit project definition files from V1 to V2."""
|
|
57
|
+
pd = DefinitionManager().unrendered_project_definition
|
|
58
|
+
|
|
59
|
+
if pd.meets_version_requirement("2"):
|
|
60
|
+
return MessageResult("Project definition is already at version 2.")
|
|
61
|
+
|
|
62
|
+
pd_v2 = convert_project_definition_to_v2(pd, accept_templates)
|
|
63
|
+
|
|
64
|
+
SecurePath("snowflake.yml").rename("snowflake_V1.yml")
|
|
65
|
+
with open("snowflake.yml", "w") as file:
|
|
66
|
+
yaml.dump(
|
|
67
|
+
pd_v2.model_dump(
|
|
68
|
+
exclude_unset=True, exclude_none=True, mode="json", by_alias=True
|
|
69
|
+
),
|
|
70
|
+
file,
|
|
71
|
+
)
|
|
72
|
+
return MessageResult("Project definition migrated to version 2.")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@ws.command(requires_connection=True, hidden=True)
|
|
76
|
+
@with_project_definition()
|
|
77
|
+
def validate(
|
|
78
|
+
**options,
|
|
79
|
+
):
|
|
80
|
+
"""Validates the project definition file."""
|
|
81
|
+
# If we get to this point, @with_project_definition() has already validated the PDF schema
|
|
82
|
+
return MessageResult("Project definition is valid.")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@ws.command(requires_connection=True, hidden=True)
|
|
86
|
+
@with_project_definition()
|
|
87
|
+
def bundle(
|
|
88
|
+
entity_id: str = typer.Option(
|
|
89
|
+
help=f"""The ID of the entity you want to bundle.""",
|
|
90
|
+
),
|
|
91
|
+
**options,
|
|
92
|
+
):
|
|
93
|
+
"""
|
|
94
|
+
Prepares a local folder with the configured artifacts of the specified entity.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
cli_context = get_cli_context()
|
|
98
|
+
ws = WorkspaceManager(
|
|
99
|
+
project_definition=cli_context.project_definition,
|
|
100
|
+
project_root=cli_context.project_root,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
bundle_map: BundleMap = ws.perform_action(entity_id, EntityActions.BUNDLE)
|
|
104
|
+
return MessageResult(f"Bundle generated at {bundle_map.deploy_root()}")
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@ws.command(requires_connection=True)
|
|
108
|
+
@with_project_definition()
|
|
109
|
+
def deploy(
|
|
110
|
+
entity_id: str = typer.Option(
|
|
111
|
+
help=f"""The ID of the entity you want to deploy.""",
|
|
112
|
+
),
|
|
113
|
+
# TODO The following options should be generated automatically, depending on the specified entity type
|
|
114
|
+
prune: Optional[bool] = typer.Option(
|
|
115
|
+
default=None,
|
|
116
|
+
help=f"""Whether to delete specified files from the stage if they don't exist locally. If set, the command deletes files that exist in the stage, but not in the local filesystem. This option cannot be used when paths are specified.""",
|
|
117
|
+
),
|
|
118
|
+
recursive: Optional[bool] = typer.Option(
|
|
119
|
+
None,
|
|
120
|
+
"--recursive/--no-recursive",
|
|
121
|
+
"-r",
|
|
122
|
+
help=f"""Whether to traverse and deploy files from subdirectories. If set, the command deploys all files and subdirectories; otherwise, only files in the current directory are deployed.""",
|
|
123
|
+
),
|
|
124
|
+
paths: Optional[List[Path]] = typer.Argument(
|
|
125
|
+
default=None,
|
|
126
|
+
show_default=False,
|
|
127
|
+
help=dedent(
|
|
128
|
+
f"""
|
|
129
|
+
Paths, relative to the the project root, of files or directories you want to upload to a stage. If a file is
|
|
130
|
+
specified, it must match one of the artifacts src pattern entries in snowflake.yml. If a directory is
|
|
131
|
+
specified, it will be searched for subfolders or files to deploy based on artifacts src pattern entries. If
|
|
132
|
+
unspecified, the command syncs all local changes to the stage."""
|
|
133
|
+
).strip(),
|
|
134
|
+
),
|
|
135
|
+
validate: bool = ValidateOption,
|
|
136
|
+
**options,
|
|
137
|
+
):
|
|
138
|
+
"""
|
|
139
|
+
Deploys the specified entity.
|
|
140
|
+
"""
|
|
141
|
+
if prune is None and recursive is None and not paths:
|
|
142
|
+
prune = True
|
|
143
|
+
recursive = True
|
|
144
|
+
else:
|
|
145
|
+
if prune is None:
|
|
146
|
+
prune = False
|
|
147
|
+
if recursive is None:
|
|
148
|
+
recursive = False
|
|
149
|
+
|
|
150
|
+
if paths and prune:
|
|
151
|
+
raise IncompatibleParametersError(["paths", "--prune"])
|
|
152
|
+
|
|
153
|
+
cli_context = get_cli_context()
|
|
154
|
+
ws = WorkspaceManager(
|
|
155
|
+
project_definition=cli_context.project_definition,
|
|
156
|
+
project_root=cli_context.project_root,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
ws.perform_action(
|
|
160
|
+
entity_id,
|
|
161
|
+
EntityActions.DEPLOY,
|
|
162
|
+
prune=prune,
|
|
163
|
+
recursive=recursive,
|
|
164
|
+
paths=paths,
|
|
165
|
+
validate=validate,
|
|
166
|
+
)
|
|
167
|
+
return MessageResult("Deployed successfully.")
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
@ws.command(requires_connection=True)
|
|
171
|
+
@with_project_definition()
|
|
172
|
+
def drop(
|
|
173
|
+
entity_id: str = typer.Option(
|
|
174
|
+
help=f"""The ID of the entity you want to drop.""",
|
|
175
|
+
),
|
|
176
|
+
# TODO The following options should be generated automatically, depending on the specified entity type
|
|
177
|
+
force: Optional[bool] = ForceOption,
|
|
178
|
+
**options,
|
|
179
|
+
):
|
|
180
|
+
"""
|
|
181
|
+
Drops the specified entity.
|
|
182
|
+
"""
|
|
183
|
+
|
|
184
|
+
cli_context = get_cli_context()
|
|
185
|
+
ws = WorkspaceManager(
|
|
186
|
+
project_definition=cli_context.project_definition,
|
|
187
|
+
project_root=cli_context.project_root,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
ws.perform_action(
|
|
191
|
+
entity_id,
|
|
192
|
+
EntityActions.DROP,
|
|
193
|
+
force_drop=force,
|
|
194
|
+
)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Dict
|
|
3
|
+
|
|
4
|
+
from snowflake.cli._plugins.workspace.action_context import ActionContext
|
|
5
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
6
|
+
from snowflake.cli.api.console import cli_console as cc
|
|
7
|
+
from snowflake.cli.api.entities.common import EntityActions, get_sql_executor
|
|
8
|
+
from snowflake.cli.api.exceptions import InvalidProjectDefinitionVersionError
|
|
9
|
+
from snowflake.cli.api.project.definition import default_role
|
|
10
|
+
from snowflake.cli.api.project.schemas.entities.entities import (
|
|
11
|
+
Entity,
|
|
12
|
+
v2_entity_model_to_entity_map,
|
|
13
|
+
)
|
|
14
|
+
from snowflake.cli.api.project.schemas.project_definition import (
|
|
15
|
+
DefinitionV20,
|
|
16
|
+
ProjectDefinition,
|
|
17
|
+
)
|
|
18
|
+
from snowflake.cli.api.project.util import to_identifier
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class WorkspaceManager:
|
|
22
|
+
"""
|
|
23
|
+
Instantiates entity instances from entity models, providing higher-order functionality on entity compositions.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, project_definition: ProjectDefinition, project_root: Path):
|
|
27
|
+
if not project_definition.meets_version_requirement("2"):
|
|
28
|
+
raise InvalidProjectDefinitionVersionError(
|
|
29
|
+
"2.x", project_definition.definition_version
|
|
30
|
+
)
|
|
31
|
+
self._entities_cache: Dict[str, Entity] = {}
|
|
32
|
+
self._project_definition: DefinitionV20 = project_definition
|
|
33
|
+
self._project_root = project_root
|
|
34
|
+
self._default_role = default_role()
|
|
35
|
+
if self._default_role is None:
|
|
36
|
+
self._default_role = get_sql_executor().current_role()
|
|
37
|
+
self.default_warehouse = None
|
|
38
|
+
cli_context = get_cli_context()
|
|
39
|
+
if cli_context.connection.warehouse:
|
|
40
|
+
self.default_warehouse = to_identifier(cli_context.connection.warehouse)
|
|
41
|
+
|
|
42
|
+
def get_entity(self, entity_id: str):
|
|
43
|
+
"""
|
|
44
|
+
Returns an entity instance with the given ID. If exists, reuses the previously returned instance, or instantiates a new one otherwise.
|
|
45
|
+
"""
|
|
46
|
+
if entity_id in self._entities_cache:
|
|
47
|
+
return self._entities_cache[entity_id]
|
|
48
|
+
entity_model = self._project_definition.entities.get(entity_id, None)
|
|
49
|
+
if entity_model is None:
|
|
50
|
+
raise ValueError(f"No such entity ID: {entity_id}")
|
|
51
|
+
entity_model_cls = entity_model.__class__
|
|
52
|
+
entity_cls = v2_entity_model_to_entity_map[entity_model_cls]
|
|
53
|
+
self._entities_cache[entity_id] = entity_cls(entity_model)
|
|
54
|
+
return self._entities_cache[entity_id]
|
|
55
|
+
|
|
56
|
+
def perform_action(self, entity_id: str, action: EntityActions, *args, **kwargs):
|
|
57
|
+
"""
|
|
58
|
+
Instantiates an entity of the given ID and calls the given action on it.
|
|
59
|
+
"""
|
|
60
|
+
entity = self.get_entity(entity_id)
|
|
61
|
+
if entity.supports(action):
|
|
62
|
+
action_ctx = ActionContext(
|
|
63
|
+
console=cc,
|
|
64
|
+
project_root=self.project_root(),
|
|
65
|
+
default_role=self._default_role,
|
|
66
|
+
default_warehouse=self.default_warehouse,
|
|
67
|
+
)
|
|
68
|
+
return entity.perform(action, action_ctx, *args, **kwargs)
|
|
69
|
+
else:
|
|
70
|
+
raise ValueError(f'This entity type does not support "{action.value}"')
|
|
71
|
+
|
|
72
|
+
def project_root(self) -> Path:
|
|
73
|
+
return self._project_root
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from snowflake.cli._plugins.workspace import commands
|
|
15
16
|
from snowflake.cli.api.plugins.command import (
|
|
16
17
|
SNOWCLI_ROOT_COMMAND_PATH,
|
|
17
18
|
CommandSpec,
|
|
18
19
|
CommandType,
|
|
19
20
|
plugin_hook_impl,
|
|
20
21
|
)
|
|
21
|
-
from snowflake.cli.plugins.workspace import commands
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
@plugin_hook_impl
|
|
@@ -15,13 +15,17 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import re
|
|
18
|
+
import warnings
|
|
18
19
|
from pathlib import Path
|
|
19
|
-
from typing import Callable, Optional
|
|
20
|
+
from typing import TYPE_CHECKING, Callable, Optional
|
|
20
21
|
|
|
21
22
|
from snowflake.cli.api.exceptions import InvalidSchemaError
|
|
22
23
|
from snowflake.cli.api.output.formats import OutputFormat
|
|
23
|
-
from snowflake.cli.api.project.schemas.project_definition import ProjectDefinition
|
|
24
24
|
from snowflake.connector import SnowflakeConnection
|
|
25
|
+
from snowflake.connector.compat import IS_WINDOWS
|
|
26
|
+
|
|
27
|
+
if TYPE_CHECKING:
|
|
28
|
+
from snowflake.cli.api.project.schemas.project_definition import ProjectDefinition
|
|
25
29
|
|
|
26
30
|
schema_pattern = re.compile(r".+\..+")
|
|
27
31
|
|
|
@@ -38,7 +42,7 @@ class _ConnectionContext:
|
|
|
38
42
|
self._user: Optional[str] = None
|
|
39
43
|
self._password: Optional[str] = None
|
|
40
44
|
self._authenticator: Optional[str] = None
|
|
41
|
-
self.
|
|
45
|
+
self._private_key_file: Optional[str] = None
|
|
42
46
|
self._warehouse: Optional[str] = None
|
|
43
47
|
self._mfa_passcode: Optional[str] = None
|
|
44
48
|
self._enable_diag: Optional[bool] = False
|
|
@@ -121,11 +125,11 @@ class _ConnectionContext:
|
|
|
121
125
|
self._authenticator = value
|
|
122
126
|
|
|
123
127
|
@property
|
|
124
|
-
def
|
|
125
|
-
return self.
|
|
128
|
+
def private_key_file(self) -> Optional[str]:
|
|
129
|
+
return self._private_key_file
|
|
126
130
|
|
|
127
|
-
def
|
|
128
|
-
self.
|
|
131
|
+
def set_private_key_file(self, value: Optional[str]):
|
|
132
|
+
self._private_key_file = value
|
|
129
133
|
|
|
130
134
|
@property
|
|
131
135
|
def warehouse(self) -> Optional[str]:
|
|
@@ -202,7 +206,7 @@ class _ConnectionContext:
|
|
|
202
206
|
"user": self.user,
|
|
203
207
|
"password": self.password,
|
|
204
208
|
"authenticator": self.authenticator,
|
|
205
|
-
"
|
|
209
|
+
"private_key_file": self.private_key_file,
|
|
206
210
|
"database": self.database,
|
|
207
211
|
"schema": self.schema,
|
|
208
212
|
"role": self.role,
|
|
@@ -213,7 +217,16 @@ class _ConnectionContext:
|
|
|
213
217
|
}
|
|
214
218
|
|
|
215
219
|
def _build_connection(self):
|
|
216
|
-
from snowflake.cli.
|
|
220
|
+
from snowflake.cli._app.snow_connector import connect_to_snowflake
|
|
221
|
+
|
|
222
|
+
# Ignore warnings about bad owner or permissions on Windows
|
|
223
|
+
# Telemetry omit our warning filter from config.py
|
|
224
|
+
if IS_WINDOWS:
|
|
225
|
+
warnings.filterwarnings(
|
|
226
|
+
action="ignore",
|
|
227
|
+
message="Bad owner or permissions.*",
|
|
228
|
+
module="snowflake.connector.config_manager",
|
|
229
|
+
)
|
|
217
230
|
|
|
218
231
|
return connect_to_snowflake(
|
|
219
232
|
temporary_connection=self.temporary_connection,
|
|
@@ -367,8 +380,8 @@ class _CliGlobalContextAccess:
|
|
|
367
380
|
return self._manager.project_definition
|
|
368
381
|
|
|
369
382
|
@property
|
|
370
|
-
def project_root(self):
|
|
371
|
-
return self._manager.project_root
|
|
383
|
+
def project_root(self) -> Path:
|
|
384
|
+
return Path(self._manager.project_root)
|
|
372
385
|
|
|
373
386
|
@property
|
|
374
387
|
def template_context(self) -> dict:
|
|
@@ -386,5 +399,19 @@ class _CliGlobalContextAccess:
|
|
|
386
399
|
return self._manager.output_format == OutputFormat.JSON
|
|
387
400
|
|
|
388
401
|
|
|
389
|
-
|
|
390
|
-
|
|
402
|
+
_CLI_CONTEXT_MANAGER: _CliGlobalContextManager | None = None
|
|
403
|
+
_CLI_CONTEXT: _CliGlobalContextAccess | None = None
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def get_cli_context_manager() -> _CliGlobalContextManager:
|
|
407
|
+
global _CLI_CONTEXT_MANAGER
|
|
408
|
+
if _CLI_CONTEXT_MANAGER is None:
|
|
409
|
+
_CLI_CONTEXT_MANAGER = _CliGlobalContextManager()
|
|
410
|
+
return _CLI_CONTEXT_MANAGER
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
def get_cli_context() -> _CliGlobalContextAccess:
|
|
414
|
+
global _CLI_CONTEXT
|
|
415
|
+
if _CLI_CONTEXT is None:
|
|
416
|
+
_CLI_CONTEXT = _CliGlobalContextAccess(get_cli_context_manager())
|
|
417
|
+
return _CLI_CONTEXT
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from enum import Enum
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class OnErrorType(Enum):
|
|
6
|
+
"""
|
|
7
|
+
Command option values for what to do when an error occurs.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
BREAK = "break"
|
|
11
|
+
CONTINUE = "continue"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class Variable:
|
|
16
|
+
"""
|
|
17
|
+
Key-value pair dataclass, returned after parsing "key=value" command options.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
key: str
|
|
21
|
+
value: str
|
|
22
|
+
|
|
23
|
+
def __init__(self, key: str, value: str):
|
|
24
|
+
self.key = key
|
|
25
|
+
self.value = value
|
|
@@ -19,7 +19,7 @@ from functools import wraps
|
|
|
19
19
|
from inspect import Signature
|
|
20
20
|
from typing import Callable, Dict, List, Optional, get_type_hints
|
|
21
21
|
|
|
22
|
-
from snowflake.cli.api.cli_global_context import
|
|
22
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
23
23
|
from snowflake.cli.api.commands.flags import (
|
|
24
24
|
AccountOption,
|
|
25
25
|
AuthenticatorOption,
|
|
@@ -125,8 +125,9 @@ def with_experimental_behaviour(
|
|
|
125
125
|
|
|
126
126
|
|
|
127
127
|
def _execute_before_command_using_global_options(**options):
|
|
128
|
-
from snowflake.cli.
|
|
128
|
+
from snowflake.cli._app.loggers import create_loggers
|
|
129
129
|
|
|
130
|
+
cli_context = get_cli_context()
|
|
130
131
|
create_loggers(cli_context.verbose, cli_context.enable_tracebacks)
|
|
131
132
|
|
|
132
133
|
|
|
@@ -234,7 +235,7 @@ GLOBAL_CONNECTION_OPTIONS = [
|
|
|
234
235
|
default=AuthenticatorOption,
|
|
235
236
|
),
|
|
236
237
|
inspect.Parameter(
|
|
237
|
-
"
|
|
238
|
+
"private_key_file",
|
|
238
239
|
inspect.Parameter.KEYWORD_ONLY,
|
|
239
240
|
annotation=Optional[str],
|
|
240
241
|
default=PrivateKeyPathOption,
|
|
@@ -342,7 +343,7 @@ GLOBAL_OPTIONS = [
|
|
|
342
343
|
|
|
343
344
|
|
|
344
345
|
def with_output(func):
|
|
345
|
-
from snowflake.cli.
|
|
346
|
+
from snowflake.cli._app.printing import print_result
|
|
346
347
|
|
|
347
348
|
@wraps(func)
|
|
348
349
|
def wrapper(*args, **kwargs):
|
|
@@ -11,9 +11,8 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from snowflake.cli.api.cli_global_context import cli_context
|
|
14
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
16
15
|
|
|
17
16
|
|
|
18
17
|
def experimental_behaviour_enabled() -> bool:
|
|
19
|
-
return
|
|
18
|
+
return get_cli_context().experimental
|