snowflake-cli-labs 2.8.0rc0__py3-none-any.whl → 3.0.0rc0__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 +6 -6
- snowflake/cli/{app → _app}/telemetry.py +4 -5
- snowflake/cli/{plugins → _plugins}/connection/commands.py +22 -5
- 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 +6 -5
- 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 +16 -18
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/setup/native_app_setup_processor.py +24 -28
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/extension_function_utils.py +4 -4
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/python_processor.py +20 -24
- snowflake/cli/{plugins → _plugins}/nativeapp/commands.py +171 -42
- snowflake/cli/{plugins → _plugins}/nativeapp/common_flags.py +1 -1
- snowflake/cli/{plugins → _plugins}/nativeapp/init.py +1 -1
- snowflake/cli/_plugins/nativeapp/manager.py +601 -0
- snowflake/cli/{plugins/connection → _plugins/nativeapp}/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/nativeapp/project_model.py +34 -11
- snowflake/cli/{plugins → _plugins}/nativeapp/run_processor.py +25 -23
- snowflake/cli/{plugins → _plugins}/nativeapp/teardown_processor.py +8 -8
- 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 +510 -0
- snowflake/cli/_plugins/snowpark/common.py +252 -0
- snowflake/cli/{plugins → _plugins}/snowpark/models.py +0 -7
- snowflake/cli/{plugins → _plugins}/snowpark/package/anaconda_packages.py +1 -1
- 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 +19 -15
- 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 +8 -6
- snowflake/cli/{plugins → _plugins}/stage/plugin_spec.py +1 -1
- snowflake/cli/_plugins/stage/utils.py +54 -0
- snowflake/cli/_plugins/streamlit/commands.py +242 -0
- snowflake/cli/{plugins → _plugins}/streamlit/manager.py +47 -70
- snowflake/cli/_plugins/streamlit/plugin_spec.py +30 -0
- snowflake/cli/_plugins/workspace/action_context.py +11 -0
- snowflake/cli/_plugins/workspace/commands.py +113 -0
- snowflake/cli/_plugins/workspace/manager.py +57 -0
- snowflake/cli/{plugins → _plugins}/workspace/plugin_spec.py +1 -1
- snowflake/cli/api/cli_global_context.py +34 -7
- snowflake/cli/api/commands/common.py +25 -0
- snowflake/cli/api/commands/decorators.py +4 -3
- snowflake/cli/api/commands/experimental_behaviour.py +2 -3
- snowflake/cli/api/commands/flags.py +73 -174
- snowflake/cli/api/commands/overrideable_parameter.py +143 -0
- snowflake/cli/api/commands/snow_typer.py +5 -4
- snowflake/cli/api/commands/typer_pre_execute.py +3 -3
- snowflake/cli/api/commands/utils.py +18 -0
- snowflake/cli/api/config.py +1 -1
- snowflake/cli/api/console/abc.py +5 -2
- snowflake/cli/api/entities/application_entity.py +12 -0
- snowflake/cli/api/entities/application_package_entity.py +260 -0
- snowflake/cli/api/entities/common.py +47 -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 +321 -0
- snowflake/cli/api/exceptions.py +19 -3
- snowflake/cli/api/feature_flags.py +2 -1
- snowflake/cli/api/identifiers.py +41 -9
- snowflake/cli/api/project/definition.py +13 -5
- snowflake/cli/api/project/definition_manager.py +12 -1
- snowflake/cli/api/project/errors.py +16 -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} +26 -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 +97 -23
- snowflake/cli/api/project/schemas/updatable_model.py +11 -3
- snowflake/cli/api/project/util.py +23 -6
- snowflake/cli/api/rendering/jinja.py +28 -8
- snowflake/cli/api/rendering/sql_templates.py +41 -12
- snowflake/cli/api/secure_path.py +3 -0
- snowflake/cli/api/sql_execution.py +35 -19
- snowflake/cli/api/utils/definition_rendering.py +14 -2
- {snowflake_cli_labs-2.8.0rc0.dist-info → snowflake_cli_labs-3.0.0rc0.dist-info}/METADATA +12 -12
- snowflake_cli_labs-3.0.0rc0.dist-info/RECORD +234 -0
- snowflake_cli_labs-3.0.0rc0.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/manager.py +0 -819
- 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/commands.py +0 -186
- 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.0rc0.dist-info/RECORD +0 -240
- snowflake_cli_labs-2.8.0rc0.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/setup/setup_driver.py.source +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/exceptions.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.0rc0.dist-info → snowflake_cli_labs-3.0.0rc0.dist-info}/WHEEL +0 -0
- {snowflake_cli_labs-2.8.0rc0.dist-info → snowflake_cli_labs-3.0.0rc0.dist-info}/licenses/LICENSE +0 -0
|
@@ -18,24 +18,27 @@ from functools import cached_property
|
|
|
18
18
|
from pathlib import Path
|
|
19
19
|
from typing import List, Optional
|
|
20
20
|
|
|
21
|
-
from snowflake.cli.
|
|
21
|
+
from snowflake.cli._plugins.nativeapp.artifacts import resolve_without_follow
|
|
22
|
+
from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext
|
|
23
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
22
24
|
from snowflake.cli.api.project.definition import (
|
|
23
25
|
default_app_package,
|
|
24
26
|
default_application,
|
|
25
27
|
default_role,
|
|
26
28
|
)
|
|
27
|
-
from snowflake.cli.api.project.schemas.
|
|
28
|
-
PostDeployHook,
|
|
29
|
-
)
|
|
29
|
+
from snowflake.cli.api.project.schemas.entities.common import PostDeployHook
|
|
30
30
|
from snowflake.cli.api.project.schemas.native_app.native_app import NativeApp
|
|
31
31
|
from snowflake.cli.api.project.schemas.native_app.path_mapping import PathMapping
|
|
32
|
-
from snowflake.cli.api.project.util import
|
|
33
|
-
|
|
32
|
+
from snowflake.cli.api.project.util import (
|
|
33
|
+
append_test_resource_suffix,
|
|
34
|
+
extract_schema,
|
|
35
|
+
to_identifier,
|
|
36
|
+
)
|
|
34
37
|
from snowflake.connector import DictCursor
|
|
35
38
|
|
|
36
39
|
|
|
37
40
|
def current_role() -> str:
|
|
38
|
-
conn =
|
|
41
|
+
conn = get_cli_context().connection
|
|
39
42
|
*_, cursor = conn.execute_string("select current_role()", cursor_class=DictCursor)
|
|
40
43
|
role_result = cursor.fetchone()
|
|
41
44
|
return role_result["CURRENT_ROLE()"]
|
|
@@ -107,6 +110,7 @@ class NativeAppProjectModel:
|
|
|
107
110
|
if self.definition.package and self.definition.package.warehouse:
|
|
108
111
|
return to_identifier(self.definition.package.warehouse)
|
|
109
112
|
else:
|
|
113
|
+
cli_context = get_cli_context()
|
|
110
114
|
if cli_context.connection.warehouse:
|
|
111
115
|
return to_identifier(cli_context.connection.warehouse)
|
|
112
116
|
return None
|
|
@@ -116,6 +120,7 @@ class NativeAppProjectModel:
|
|
|
116
120
|
if self.definition.application and self.definition.application.warehouse:
|
|
117
121
|
return to_identifier(self.definition.application.warehouse)
|
|
118
122
|
else:
|
|
123
|
+
cli_context = get_cli_context()
|
|
119
124
|
if cli_context.connection.warehouse:
|
|
120
125
|
return to_identifier(cli_context.connection.warehouse)
|
|
121
126
|
return None
|
|
@@ -126,12 +131,16 @@ class NativeAppProjectModel:
|
|
|
126
131
|
# sometimes strip out double quotes, so we try to get them back here.
|
|
127
132
|
return to_identifier(self.definition.name)
|
|
128
133
|
|
|
129
|
-
@
|
|
134
|
+
@property
|
|
130
135
|
def package_name(self) -> str:
|
|
131
136
|
if self.definition.package and self.definition.package.name:
|
|
132
137
|
return to_identifier(self.definition.package.name)
|
|
133
138
|
else:
|
|
134
|
-
|
|
139
|
+
# V1.0 PDF doesn't support templating, so if the identifier isn't
|
|
140
|
+
# explicitly specified, the default is generated here,
|
|
141
|
+
# so we have to append the test resource suffix here
|
|
142
|
+
name = default_app_package(self.project_identifier)
|
|
143
|
+
return to_identifier(append_test_resource_suffix(name))
|
|
135
144
|
|
|
136
145
|
@cached_property
|
|
137
146
|
def package_role(self) -> str:
|
|
@@ -147,12 +156,16 @@ class NativeAppProjectModel:
|
|
|
147
156
|
else:
|
|
148
157
|
return "internal"
|
|
149
158
|
|
|
150
|
-
@
|
|
159
|
+
@property
|
|
151
160
|
def app_name(self) -> str:
|
|
152
161
|
if self.definition.application and self.definition.application.name:
|
|
153
162
|
return to_identifier(self.definition.application.name)
|
|
154
163
|
else:
|
|
155
|
-
|
|
164
|
+
# V1.0 PDF doesn't support templating, so if the identifier isn't
|
|
165
|
+
# explicitly specified, the default is generated here,
|
|
166
|
+
# so we have to append the test resource suffix here
|
|
167
|
+
name = default_application(self.project_identifier)
|
|
168
|
+
return to_identifier(append_test_resource_suffix(name))
|
|
156
169
|
|
|
157
170
|
@cached_property
|
|
158
171
|
def app_role(self) -> str:
|
|
@@ -193,3 +206,13 @@ class NativeAppProjectModel:
|
|
|
193
206
|
if self.definition.application:
|
|
194
207
|
return self.definition.application.debug
|
|
195
208
|
return None
|
|
209
|
+
|
|
210
|
+
def get_bundle_context(self) -> BundleContext:
|
|
211
|
+
return BundleContext(
|
|
212
|
+
package_name=self.package_name,
|
|
213
|
+
artifacts=self.artifacts,
|
|
214
|
+
project_root=self.project_root,
|
|
215
|
+
bundle_root=self.bundle_root,
|
|
216
|
+
deploy_root=self.deploy_root,
|
|
217
|
+
generated_root=self.generated_root,
|
|
218
|
+
)
|
|
@@ -20,7 +20,32 @@ from typing import Optional
|
|
|
20
20
|
|
|
21
21
|
import typer
|
|
22
22
|
from click import UsageError
|
|
23
|
+
from snowflake.cli._plugins.nativeapp.artifacts import BundleMap
|
|
24
|
+
from snowflake.cli._plugins.nativeapp.constants import (
|
|
25
|
+
ALLOWED_SPECIAL_COMMENTS,
|
|
26
|
+
COMMENT_COL,
|
|
27
|
+
PATCH_COL,
|
|
28
|
+
SPECIAL_COMMENT,
|
|
29
|
+
VERSION_COL,
|
|
30
|
+
)
|
|
31
|
+
from snowflake.cli._plugins.nativeapp.exceptions import (
|
|
32
|
+
ApplicationCreatedExternallyError,
|
|
33
|
+
ApplicationPackageDoesNotExistError,
|
|
34
|
+
)
|
|
35
|
+
from snowflake.cli._plugins.nativeapp.manager import (
|
|
36
|
+
NativeAppCommandProcessor,
|
|
37
|
+
NativeAppManager,
|
|
38
|
+
)
|
|
39
|
+
from snowflake.cli._plugins.nativeapp.policy import PolicyBase
|
|
40
|
+
from snowflake.cli._plugins.nativeapp.project_model import (
|
|
41
|
+
NativeAppProjectModel,
|
|
42
|
+
)
|
|
43
|
+
from snowflake.cli._plugins.stage.manager import StageManager
|
|
23
44
|
from snowflake.cli.api.console import cli_console as cc
|
|
45
|
+
from snowflake.cli.api.entities.utils import (
|
|
46
|
+
ensure_correct_owner,
|
|
47
|
+
generic_sql_error_handler,
|
|
48
|
+
)
|
|
24
49
|
from snowflake.cli.api.errno import (
|
|
25
50
|
APPLICATION_NO_LONGER_AVAILABLE,
|
|
26
51
|
APPLICATION_OWNS_EXTERNAL_OBJECTS,
|
|
@@ -36,29 +61,6 @@ from snowflake.cli.api.project.util import (
|
|
|
36
61
|
unquote_identifier,
|
|
37
62
|
)
|
|
38
63
|
from snowflake.cli.api.utils.cursor import find_all_rows
|
|
39
|
-
from snowflake.cli.plugins.nativeapp.artifacts import BundleMap
|
|
40
|
-
from snowflake.cli.plugins.nativeapp.constants import (
|
|
41
|
-
ALLOWED_SPECIAL_COMMENTS,
|
|
42
|
-
COMMENT_COL,
|
|
43
|
-
PATCH_COL,
|
|
44
|
-
SPECIAL_COMMENT,
|
|
45
|
-
VERSION_COL,
|
|
46
|
-
)
|
|
47
|
-
from snowflake.cli.plugins.nativeapp.exceptions import (
|
|
48
|
-
ApplicationCreatedExternallyError,
|
|
49
|
-
ApplicationPackageDoesNotExistError,
|
|
50
|
-
)
|
|
51
|
-
from snowflake.cli.plugins.nativeapp.manager import (
|
|
52
|
-
NativeAppCommandProcessor,
|
|
53
|
-
NativeAppManager,
|
|
54
|
-
ensure_correct_owner,
|
|
55
|
-
generic_sql_error_handler,
|
|
56
|
-
)
|
|
57
|
-
from snowflake.cli.plugins.nativeapp.policy import PolicyBase
|
|
58
|
-
from snowflake.cli.plugins.nativeapp.project_model import (
|
|
59
|
-
NativeAppProjectModel,
|
|
60
|
-
)
|
|
61
|
-
from snowflake.cli.plugins.stage.manager import StageManager
|
|
62
64
|
from snowflake.connector import ProgrammingError
|
|
63
65
|
from snowflake.connector.cursor import DictCursor, SnowflakeCursor
|
|
64
66
|
|
|
@@ -19,27 +19,27 @@ from textwrap import dedent
|
|
|
19
19
|
from typing import Dict, Optional
|
|
20
20
|
|
|
21
21
|
import typer
|
|
22
|
-
from snowflake.cli.
|
|
23
|
-
from snowflake.cli.api.errno import APPLICATION_NO_LONGER_AVAILABLE
|
|
24
|
-
from snowflake.cli.api.exceptions import SnowflakeSQLExecutionError
|
|
25
|
-
from snowflake.cli.plugins.nativeapp.constants import (
|
|
22
|
+
from snowflake.cli._plugins.nativeapp.constants import (
|
|
26
23
|
ALLOWED_SPECIAL_COMMENTS,
|
|
27
24
|
COMMENT_COL,
|
|
28
25
|
EXTERNAL_DISTRIBUTION,
|
|
29
26
|
INTERNAL_DISTRIBUTION,
|
|
30
27
|
OWNER_COL,
|
|
31
28
|
)
|
|
32
|
-
from snowflake.cli.
|
|
29
|
+
from snowflake.cli._plugins.nativeapp.exceptions import (
|
|
33
30
|
CouldNotDropApplicationPackageWithVersions,
|
|
34
31
|
)
|
|
35
|
-
from snowflake.cli.
|
|
32
|
+
from snowflake.cli._plugins.nativeapp.manager import (
|
|
36
33
|
NativeAppCommandProcessor,
|
|
37
34
|
NativeAppManager,
|
|
38
|
-
ensure_correct_owner,
|
|
39
35
|
)
|
|
40
|
-
from snowflake.cli.
|
|
36
|
+
from snowflake.cli._plugins.nativeapp.utils import (
|
|
41
37
|
needs_confirmation,
|
|
42
38
|
)
|
|
39
|
+
from snowflake.cli.api.console import cli_console as cc
|
|
40
|
+
from snowflake.cli.api.entities.utils import ensure_correct_owner
|
|
41
|
+
from snowflake.cli.api.errno import APPLICATION_NO_LONGER_AVAILABLE
|
|
42
|
+
from snowflake.cli.api.exceptions import SnowflakeSQLExecutionError
|
|
43
43
|
from snowflake.connector import ProgrammingError
|
|
44
44
|
from snowflake.connector.cursor import DictCursor
|
|
45
45
|
|
|
@@ -15,16 +15,18 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
from functools import wraps
|
|
18
|
-
from pathlib import Path
|
|
19
18
|
from typing import Any, Dict, Optional, Union
|
|
20
19
|
|
|
21
20
|
from click import ClickException
|
|
22
|
-
from snowflake.cli.api.cli_global_context import
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
from snowflake.cli.api.cli_global_context import (
|
|
22
|
+
get_cli_context,
|
|
23
|
+
get_cli_context_manager,
|
|
25
24
|
)
|
|
26
|
-
from snowflake.cli.api.project.schemas.entities.
|
|
27
|
-
|
|
25
|
+
from snowflake.cli.api.project.schemas.entities.application_entity_model import (
|
|
26
|
+
ApplicationEntityModel,
|
|
27
|
+
)
|
|
28
|
+
from snowflake.cli.api.project.schemas.entities.application_package_entity_model import (
|
|
29
|
+
ApplicationPackageEntityModel,
|
|
28
30
|
)
|
|
29
31
|
from snowflake.cli.api.project.schemas.native_app.path_mapping import PathMapping
|
|
30
32
|
from snowflake.cli.api.project.schemas.project_definition import (
|
|
@@ -35,7 +37,7 @@ from snowflake.cli.api.utils.definition_rendering import render_definition_templ
|
|
|
35
37
|
|
|
36
38
|
|
|
37
39
|
def _convert_v2_artifact_to_v1_dict(
|
|
38
|
-
v2_artifact: Union[PathMapping,
|
|
40
|
+
v2_artifact: Union[PathMapping, str]
|
|
39
41
|
) -> Union[Dict, str]:
|
|
40
42
|
if isinstance(v2_artifact, PathMapping):
|
|
41
43
|
return {
|
|
@@ -43,23 +45,23 @@ def _convert_v2_artifact_to_v1_dict(
|
|
|
43
45
|
"dest": v2_artifact.dest,
|
|
44
46
|
"processors": v2_artifact.processors,
|
|
45
47
|
}
|
|
46
|
-
return
|
|
48
|
+
return v2_artifact
|
|
47
49
|
|
|
48
50
|
|
|
49
51
|
def _pdf_v2_to_v1(v2_definition: DefinitionV20) -> DefinitionV11:
|
|
50
52
|
pdfv1: Dict[str, Any] = {"definition_version": "1.1", "native_app": {}}
|
|
51
53
|
|
|
52
|
-
app_package_definition:
|
|
53
|
-
app_definition: Optional[
|
|
54
|
+
app_package_definition: Optional[ApplicationPackageEntityModel] = None
|
|
55
|
+
app_definition: Optional[ApplicationEntityModel] = None
|
|
54
56
|
|
|
55
57
|
for key, entity in v2_definition.entities.items():
|
|
56
|
-
if entity.get_type() ==
|
|
58
|
+
if entity.get_type() == ApplicationPackageEntityModel.get_type():
|
|
57
59
|
if app_package_definition:
|
|
58
60
|
raise ClickException(
|
|
59
61
|
"More than one application package entity exists in the project definition file."
|
|
60
62
|
)
|
|
61
63
|
app_package_definition = entity
|
|
62
|
-
elif entity.get_type() ==
|
|
64
|
+
elif entity.get_type() == ApplicationEntityModel.get_type():
|
|
63
65
|
if app_definition:
|
|
64
66
|
raise ClickException(
|
|
65
67
|
"More than one application entity exists in the project definition file."
|
|
@@ -71,21 +73,24 @@ def _pdf_v2_to_v1(v2_definition: DefinitionV20) -> DefinitionV11:
|
|
|
71
73
|
)
|
|
72
74
|
|
|
73
75
|
# NativeApp
|
|
74
|
-
if app_definition and app_definition.
|
|
75
|
-
pdfv1["native_app"]["name"] = app_definition.
|
|
76
|
+
if app_definition and app_definition.fqn.identifier:
|
|
77
|
+
pdfv1["native_app"]["name"] = app_definition.fqn.identifier
|
|
76
78
|
else:
|
|
77
|
-
pdfv1["native_app"]["name"] = app_package_definition.
|
|
79
|
+
pdfv1["native_app"]["name"] = app_package_definition.fqn.identifier.split(
|
|
80
|
+
"_pkg_"
|
|
81
|
+
)[0]
|
|
78
82
|
pdfv1["native_app"]["artifacts"] = [
|
|
79
83
|
_convert_v2_artifact_to_v1_dict(a) for a in app_package_definition.artifacts
|
|
80
84
|
]
|
|
81
85
|
pdfv1["native_app"]["source_stage"] = app_package_definition.stage
|
|
82
|
-
pdfv1["native_app"]["bundle_root"] =
|
|
83
|
-
pdfv1["native_app"]["generated_root"] =
|
|
84
|
-
pdfv1["native_app"]["deploy_root"] =
|
|
86
|
+
pdfv1["native_app"]["bundle_root"] = app_package_definition.bundle_root
|
|
87
|
+
pdfv1["native_app"]["generated_root"] = app_package_definition.generated_root
|
|
88
|
+
pdfv1["native_app"]["deploy_root"] = app_package_definition.deploy_root
|
|
89
|
+
pdfv1["native_app"]["scratch_stage"] = app_package_definition.scratch_stage
|
|
85
90
|
|
|
86
91
|
# Package
|
|
87
92
|
pdfv1["native_app"]["package"] = {}
|
|
88
|
-
pdfv1["native_app"]["package"]["name"] = app_package_definition.
|
|
93
|
+
pdfv1["native_app"]["package"]["name"] = app_package_definition.fqn.identifier
|
|
89
94
|
if app_package_definition.distribution:
|
|
90
95
|
pdfv1["native_app"]["package"][
|
|
91
96
|
"distribution"
|
|
@@ -94,17 +99,31 @@ def _pdf_v2_to_v1(v2_definition: DefinitionV20) -> DefinitionV11:
|
|
|
94
99
|
pdfv1["native_app"]["package"][
|
|
95
100
|
"post_deploy"
|
|
96
101
|
] = app_package_definition.meta.post_deploy
|
|
102
|
+
if app_package_definition.meta:
|
|
103
|
+
if app_package_definition.meta.role:
|
|
104
|
+
pdfv1["native_app"]["package"]["role"] = app_package_definition.meta.role
|
|
105
|
+
if app_package_definition.meta.warehouse:
|
|
106
|
+
pdfv1["native_app"]["package"][
|
|
107
|
+
"warehouse"
|
|
108
|
+
] = app_package_definition.meta.warehouse
|
|
97
109
|
|
|
98
110
|
# Application
|
|
99
111
|
if app_definition:
|
|
100
112
|
pdfv1["native_app"]["application"] = {}
|
|
101
|
-
pdfv1["native_app"]["application"]["name"] = app_definition.
|
|
102
|
-
if app_definition.
|
|
103
|
-
pdfv1["native_app"]["application"]["
|
|
104
|
-
if app_definition.meta
|
|
105
|
-
|
|
106
|
-
"
|
|
107
|
-
|
|
113
|
+
pdfv1["native_app"]["application"]["name"] = app_definition.fqn.identifier
|
|
114
|
+
if app_definition.debug:
|
|
115
|
+
pdfv1["native_app"]["application"]["debug"] = app_definition.debug
|
|
116
|
+
if app_definition.meta:
|
|
117
|
+
if app_definition.meta.role:
|
|
118
|
+
pdfv1["native_app"]["application"]["role"] = app_definition.meta.role
|
|
119
|
+
if app_definition.meta.warehouse:
|
|
120
|
+
pdfv1["native_app"]["application"][
|
|
121
|
+
"warehouse"
|
|
122
|
+
] = app_definition.meta.warehouse
|
|
123
|
+
if app_definition.meta.post_deploy:
|
|
124
|
+
pdfv1["native_app"]["application"][
|
|
125
|
+
"post_deploy"
|
|
126
|
+
] = app_definition.meta.post_deploy
|
|
108
127
|
|
|
109
128
|
result = render_definition_template(pdfv1, {})
|
|
110
129
|
# Override the definition object in global context
|
|
@@ -122,14 +141,14 @@ def nativeapp_definition_v2_to_v1(func):
|
|
|
122
141
|
|
|
123
142
|
@wraps(func)
|
|
124
143
|
def wrapper(*args, **kwargs):
|
|
125
|
-
original_pdf: DefinitionV20 =
|
|
144
|
+
original_pdf: DefinitionV20 = get_cli_context().project_definition
|
|
126
145
|
if not original_pdf:
|
|
127
146
|
raise ValueError(
|
|
128
147
|
"Project definition could not be found. The nativeapp_definition_v2_to_v1 command decorator assumes with_project_definition() was called before it."
|
|
129
148
|
)
|
|
130
149
|
if original_pdf.definition_version == "2":
|
|
131
150
|
pdfv1 = _pdf_v2_to_v1(original_pdf)
|
|
132
|
-
|
|
151
|
+
get_cli_context_manager().set_project_definition(pdfv1)
|
|
133
152
|
return func(*args, **kwargs)
|
|
134
153
|
|
|
135
154
|
return wrapper
|
|
@@ -19,27 +19,27 @@ from typing import Optional
|
|
|
19
19
|
|
|
20
20
|
import typer
|
|
21
21
|
from click import MissingParameter
|
|
22
|
-
from snowflake.cli.
|
|
23
|
-
from snowflake.cli.
|
|
24
|
-
with_project_definition,
|
|
25
|
-
)
|
|
26
|
-
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
|
|
27
|
-
from snowflake.cli.api.output.types import CommandResult, MessageResult, QueryResult
|
|
28
|
-
from snowflake.cli.api.project.project_verification import assert_project_type
|
|
29
|
-
from snowflake.cli.plugins.nativeapp.common_flags import ForceOption, InteractiveOption
|
|
30
|
-
from snowflake.cli.plugins.nativeapp.policy import (
|
|
22
|
+
from snowflake.cli._plugins.nativeapp.common_flags import ForceOption, InteractiveOption
|
|
23
|
+
from snowflake.cli._plugins.nativeapp.policy import (
|
|
31
24
|
AllowAlwaysPolicy,
|
|
32
25
|
AskAlwaysPolicy,
|
|
33
26
|
DenyAlwaysPolicy,
|
|
34
27
|
)
|
|
35
|
-
from snowflake.cli.
|
|
36
|
-
from snowflake.cli.
|
|
28
|
+
from snowflake.cli._plugins.nativeapp.run_processor import NativeAppRunProcessor
|
|
29
|
+
from snowflake.cli._plugins.nativeapp.v2_conversions.v2_to_v1_decorator import (
|
|
37
30
|
nativeapp_definition_v2_to_v1,
|
|
38
31
|
)
|
|
39
|
-
from snowflake.cli.
|
|
32
|
+
from snowflake.cli._plugins.nativeapp.version.version_processor import (
|
|
40
33
|
NativeAppVersionCreateProcessor,
|
|
41
34
|
NativeAppVersionDropProcessor,
|
|
42
35
|
)
|
|
36
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
37
|
+
from snowflake.cli.api.commands.decorators import (
|
|
38
|
+
with_project_definition,
|
|
39
|
+
)
|
|
40
|
+
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
|
|
41
|
+
from snowflake.cli.api.output.types import CommandResult, MessageResult, QueryResult
|
|
42
|
+
from snowflake.cli.api.project.project_verification import assert_project_type
|
|
43
43
|
|
|
44
44
|
app = SnowTyperFactory(
|
|
45
45
|
name="version",
|
|
@@ -96,6 +96,7 @@ def create(
|
|
|
96
96
|
else:
|
|
97
97
|
git_policy = AllowAlwaysPolicy()
|
|
98
98
|
|
|
99
|
+
cli_context = get_cli_context()
|
|
99
100
|
processor = NativeAppVersionCreateProcessor(
|
|
100
101
|
project_definition=cli_context.project_definition.native_app,
|
|
101
102
|
project_root=cli_context.project_root,
|
|
@@ -126,6 +127,7 @@ def version_list(
|
|
|
126
127
|
|
|
127
128
|
assert_project_type("native_app")
|
|
128
129
|
|
|
130
|
+
cli_context = get_cli_context()
|
|
129
131
|
processor = NativeAppRunProcessor(
|
|
130
132
|
project_definition=cli_context.project_definition.native_app,
|
|
131
133
|
project_root=cli_context.project_root,
|
|
@@ -162,6 +164,7 @@ def drop(
|
|
|
162
164
|
else:
|
|
163
165
|
policy = DenyAlwaysPolicy()
|
|
164
166
|
|
|
167
|
+
cli_context = get_cli_context()
|
|
165
168
|
processor = NativeAppVersionDropProcessor(
|
|
166
169
|
project_definition=cli_context.project_definition.native_app,
|
|
167
170
|
project_root=cli_context.project_root,
|
|
@@ -20,30 +20,29 @@ from typing import Dict, List, Optional
|
|
|
20
20
|
|
|
21
21
|
import typer
|
|
22
22
|
from click import BadOptionUsage, ClickException
|
|
23
|
-
from snowflake.cli.
|
|
24
|
-
from snowflake.cli.api.exceptions import SnowflakeSQLExecutionError
|
|
25
|
-
from snowflake.cli.api.project.schemas.native_app.native_app import NativeApp
|
|
26
|
-
from snowflake.cli.api.project.util import unquote_identifier
|
|
27
|
-
from snowflake.cli.api.utils.cursor import (
|
|
28
|
-
find_all_rows,
|
|
29
|
-
find_first_row,
|
|
30
|
-
)
|
|
31
|
-
from snowflake.cli.plugins.nativeapp.artifacts import (
|
|
23
|
+
from snowflake.cli._plugins.nativeapp.artifacts import (
|
|
32
24
|
BundleMap,
|
|
33
25
|
find_version_info_in_manifest_file,
|
|
34
26
|
)
|
|
35
|
-
from snowflake.cli.
|
|
36
|
-
from snowflake.cli.
|
|
27
|
+
from snowflake.cli._plugins.nativeapp.constants import VERSION_COL
|
|
28
|
+
from snowflake.cli._plugins.nativeapp.exceptions import (
|
|
37
29
|
ApplicationPackageAlreadyExistsError,
|
|
38
30
|
ApplicationPackageDoesNotExistError,
|
|
39
31
|
)
|
|
40
|
-
from snowflake.cli.
|
|
32
|
+
from snowflake.cli._plugins.nativeapp.manager import (
|
|
41
33
|
NativeAppCommandProcessor,
|
|
42
34
|
NativeAppManager,
|
|
43
|
-
ensure_correct_owner,
|
|
44
35
|
)
|
|
45
|
-
from snowflake.cli.
|
|
46
|
-
from snowflake.cli.
|
|
36
|
+
from snowflake.cli._plugins.nativeapp.policy import PolicyBase
|
|
37
|
+
from snowflake.cli._plugins.nativeapp.run_processor import NativeAppRunProcessor
|
|
38
|
+
from snowflake.cli.api.console import cli_console as cc
|
|
39
|
+
from snowflake.cli.api.entities.utils import ensure_correct_owner
|
|
40
|
+
from snowflake.cli.api.exceptions import SnowflakeSQLExecutionError
|
|
41
|
+
from snowflake.cli.api.project.schemas.native_app.native_app import NativeApp
|
|
42
|
+
from snowflake.cli.api.project.util import to_identifier, unquote_identifier
|
|
43
|
+
from snowflake.cli.api.utils.cursor import (
|
|
44
|
+
find_all_rows,
|
|
45
|
+
)
|
|
47
46
|
from snowflake.connector import ProgrammingError
|
|
48
47
|
from snowflake.connector.cursor import DictCursor
|
|
49
48
|
|
|
@@ -121,6 +120,8 @@ class NativeAppVersionCreateProcessor(NativeAppRunProcessor):
|
|
|
121
120
|
"""
|
|
122
121
|
Defines a new version in an existing application package.
|
|
123
122
|
"""
|
|
123
|
+
# Make the version a valid identifier, adding quotes if necessary
|
|
124
|
+
version = to_identifier(version)
|
|
124
125
|
with self.use_role(self.package_role):
|
|
125
126
|
cc.step(
|
|
126
127
|
f"Defining a new version {version} in application package {self.package_name}"
|
|
@@ -141,6 +142,8 @@ class NativeAppVersionCreateProcessor(NativeAppRunProcessor):
|
|
|
141
142
|
"""
|
|
142
143
|
Add a new patch, optionally a custom one, to an existing version in an application package.
|
|
143
144
|
"""
|
|
145
|
+
# Make the version a valid identifier, adding quotes if necessary
|
|
146
|
+
version = to_identifier(version)
|
|
144
147
|
with self.use_role(self.package_role):
|
|
145
148
|
cc.step(
|
|
146
149
|
f"Adding new patch to version {version} defined in application package {self.package_name}"
|
|
@@ -156,11 +159,7 @@ class NativeAppVersionCreateProcessor(NativeAppRunProcessor):
|
|
|
156
159
|
add_version_query, cursor_class=DictCursor
|
|
157
160
|
)
|
|
158
161
|
|
|
159
|
-
show_row =
|
|
160
|
-
result_cursor,
|
|
161
|
-
lambda row: row[VERSION_COL] == unquote_identifier(version),
|
|
162
|
-
)
|
|
163
|
-
|
|
162
|
+
show_row = result_cursor.fetchall()[0]
|
|
164
163
|
new_patch = show_row["patch"]
|
|
165
164
|
cc.message(
|
|
166
165
|
f"Patch {new_patch} created for version {version} defined in application package {self.package_name}."
|
|
@@ -328,6 +327,9 @@ class NativeAppVersionDropProcessor(NativeAppManager, NativeAppCommandProcessor)
|
|
|
328
327
|
"Manifest.yml file does not contain a value for the version field."
|
|
329
328
|
)
|
|
330
329
|
|
|
330
|
+
# Make the version a valid identifier, adding quotes if necessary
|
|
331
|
+
version = to_identifier(version)
|
|
332
|
+
|
|
331
333
|
cc.step(
|
|
332
334
|
dedent(
|
|
333
335
|
f"""\
|
|
@@ -15,11 +15,12 @@
|
|
|
15
15
|
import logging
|
|
16
16
|
|
|
17
17
|
import typer
|
|
18
|
+
from snowflake.cli._plugins.notebook.manager import NotebookManager
|
|
19
|
+
from snowflake.cli._plugins.notebook.types import NotebookStagePath
|
|
18
20
|
from snowflake.cli.api.commands.flags import identifier_argument
|
|
19
21
|
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
|
|
22
|
+
from snowflake.cli.api.identifiers import FQN
|
|
20
23
|
from snowflake.cli.api.output.types import MessageResult
|
|
21
|
-
from snowflake.cli.plugins.notebook.manager import NotebookManager
|
|
22
|
-
from snowflake.cli.plugins.notebook.types import NotebookName, NotebookStagePath
|
|
23
24
|
from typing_extensions import Annotated
|
|
24
25
|
|
|
25
26
|
app = SnowTyperFactory(
|
|
@@ -33,12 +34,13 @@ NotebookFile: NotebookStagePath = typer.Option(
|
|
|
33
34
|
"--notebook-file",
|
|
34
35
|
"-f",
|
|
35
36
|
help="Stage path with notebook file. For example `@stage/path/to/notebook.ipynb`",
|
|
37
|
+
show_default=False,
|
|
36
38
|
)
|
|
37
39
|
|
|
38
40
|
|
|
39
41
|
@app.command(requires_connection=True)
|
|
40
42
|
def execute(
|
|
41
|
-
identifier:
|
|
43
|
+
identifier: FQN = NOTEBOOK_IDENTIFIER,
|
|
42
44
|
**options,
|
|
43
45
|
):
|
|
44
46
|
"""
|
|
@@ -51,7 +53,7 @@ def execute(
|
|
|
51
53
|
|
|
52
54
|
@app.command(requires_connection=True)
|
|
53
55
|
def get_url(
|
|
54
|
-
identifier:
|
|
56
|
+
identifier: FQN = NOTEBOOK_IDENTIFIER,
|
|
55
57
|
**options,
|
|
56
58
|
):
|
|
57
59
|
"""Return a url to a notebook."""
|
|
@@ -61,7 +63,7 @@ def get_url(
|
|
|
61
63
|
|
|
62
64
|
@app.command(name="open", requires_connection=True)
|
|
63
65
|
def open_cmd(
|
|
64
|
-
identifier:
|
|
66
|
+
identifier: FQN = NOTEBOOK_IDENTIFIER,
|
|
65
67
|
**options,
|
|
66
68
|
):
|
|
67
69
|
"""Opens a notebook in default browser"""
|
|
@@ -72,7 +74,7 @@ def open_cmd(
|
|
|
72
74
|
|
|
73
75
|
@app.command(requires_connection=True)
|
|
74
76
|
def create(
|
|
75
|
-
identifier: Annotated[
|
|
77
|
+
identifier: Annotated[FQN, NOTEBOOK_IDENTIFIER],
|
|
76
78
|
notebook_file: Annotated[NotebookStagePath, NotebookFile],
|
|
77
79
|
**options,
|
|
78
80
|
):
|
|
@@ -15,28 +15,28 @@
|
|
|
15
15
|
from pathlib import Path
|
|
16
16
|
from textwrap import dedent
|
|
17
17
|
|
|
18
|
-
from snowflake.cli.
|
|
18
|
+
from snowflake.cli._plugins.connection.util import make_snowsight_url
|
|
19
|
+
from snowflake.cli._plugins.notebook.exceptions import NotebookStagePathError
|
|
20
|
+
from snowflake.cli._plugins.notebook.types import NotebookStagePath
|
|
21
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
19
22
|
from snowflake.cli.api.identifiers import FQN
|
|
20
23
|
from snowflake.cli.api.sql_execution import SqlExecutionMixin
|
|
21
|
-
from snowflake.cli.plugins.connection.util import make_snowsight_url
|
|
22
|
-
from snowflake.cli.plugins.notebook.exceptions import NotebookStagePathError
|
|
23
|
-
from snowflake.cli.plugins.notebook.types import NotebookName, NotebookStagePath
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
class NotebookManager(SqlExecutionMixin):
|
|
27
|
-
def execute(self, notebook_name:
|
|
28
|
-
query = f"EXECUTE NOTEBOOK {notebook_name}()"
|
|
27
|
+
def execute(self, notebook_name: FQN):
|
|
28
|
+
query = f"EXECUTE NOTEBOOK {notebook_name.sql_identifier}()"
|
|
29
29
|
return self._execute_query(query=query)
|
|
30
30
|
|
|
31
|
-
def get_url(self, notebook_name:
|
|
32
|
-
fqn =
|
|
31
|
+
def get_url(self, notebook_name: FQN):
|
|
32
|
+
fqn = notebook_name.using_connection(self._conn)
|
|
33
33
|
return make_snowsight_url(
|
|
34
34
|
self._conn,
|
|
35
35
|
f"/#/notebooks/{fqn.url_identifier}",
|
|
36
36
|
)
|
|
37
37
|
|
|
38
38
|
@staticmethod
|
|
39
|
-
def parse_stage_as_path(notebook_file:
|
|
39
|
+
def parse_stage_as_path(notebook_file: str) -> Path:
|
|
40
40
|
"""Parses notebook file path to pathlib.Path."""
|
|
41
41
|
if not notebook_file.endswith(".ipynb"):
|
|
42
42
|
raise NotebookStagePathError(notebook_file)
|
|
@@ -48,19 +48,19 @@ class NotebookManager(SqlExecutionMixin):
|
|
|
48
48
|
|
|
49
49
|
def create(
|
|
50
50
|
self,
|
|
51
|
-
notebook_name:
|
|
51
|
+
notebook_name: FQN,
|
|
52
52
|
notebook_file: NotebookStagePath,
|
|
53
53
|
) -> str:
|
|
54
|
-
notebook_fqn =
|
|
54
|
+
notebook_fqn = notebook_name.using_connection(self._conn)
|
|
55
55
|
stage_path = self.parse_stage_as_path(notebook_file)
|
|
56
56
|
|
|
57
57
|
queries = dedent(
|
|
58
58
|
f"""
|
|
59
|
-
CREATE OR REPLACE NOTEBOOK {notebook_fqn.
|
|
59
|
+
CREATE OR REPLACE NOTEBOOK {notebook_fqn.sql_identifier}
|
|
60
60
|
FROM '{stage_path.parent}'
|
|
61
|
-
QUERY_WAREHOUSE = '{
|
|
61
|
+
QUERY_WAREHOUSE = '{get_cli_context().connection.warehouse}'
|
|
62
62
|
MAIN_FILE = '{stage_path.name}';
|
|
63
|
-
|
|
63
|
+
// Cannot use IDENTIFIER(...)
|
|
64
64
|
ALTER NOTEBOOK {notebook_fqn.identifier} ADD LIVE VERSION FROM LAST;
|
|
65
65
|
"""
|
|
66
66
|
)
|
|
@@ -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.notebook 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.notebook import commands
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
@plugin_hook_impl
|