snowflake-cli-labs 2.8.0rc1__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.
Files changed (219) hide show
  1. snowflake/cli/__about__.py +1 -1
  2. snowflake/cli/{app → _app}/__main__.py +1 -1
  3. snowflake/cli/{app → _app}/cli_app.py +12 -12
  4. snowflake/cli/{app → _app}/commands_registration/builtin_plugins.py +13 -19
  5. snowflake/cli/{app → _app}/commands_registration/command_plugins_loader.py +9 -9
  6. snowflake/cli/{app → _app}/commands_registration/commands_registration_with_callbacks.py +4 -4
  7. snowflake/cli/{app → _app}/commands_registration/exception_logging.py +2 -2
  8. snowflake/cli/{app → _app}/commands_registration/typer_registration.py +2 -2
  9. snowflake/cli/{app → _app}/dev/docs/commands_docs_generator.py +30 -12
  10. snowflake/cli/{app → _app}/dev/docs/generator.py +3 -3
  11. snowflake/cli/{app → _app}/dev/docs/project_definition_docs_generator.py +4 -4
  12. snowflake/cli/{app → _app}/dev/docs/templates/usage.rst.jinja2 +14 -4
  13. snowflake/cli/{app → _app}/main_typer.py +2 -2
  14. snowflake/cli/{app → _app}/printing.py +2 -2
  15. snowflake/cli/{app → _app}/snow_connector.py +6 -6
  16. snowflake/cli/{app → _app}/telemetry.py +4 -5
  17. snowflake/cli/{plugins → _plugins}/connection/commands.py +22 -5
  18. snowflake/cli/_plugins/connection/plugin_spec.py +30 -0
  19. snowflake/cli/{plugins → _plugins}/connection/util.py +16 -0
  20. snowflake/cli/{plugins → _plugins}/cortex/commands.py +54 -49
  21. snowflake/cli/{plugins → _plugins}/cortex/constants.py +1 -1
  22. snowflake/cli/{plugins → _plugins}/cortex/manager.py +5 -5
  23. snowflake/cli/{plugins → _plugins}/cortex/plugin_spec.py +1 -1
  24. snowflake/cli/{plugins → _plugins}/git/commands.py +32 -20
  25. snowflake/cli/{plugins → _plugins}/git/manager.py +6 -5
  26. snowflake/cli/{plugins → _plugins}/git/plugin_spec.py +1 -1
  27. snowflake/cli/{plugins → _plugins}/init/commands.py +10 -6
  28. snowflake/cli/{plugins → _plugins}/init/plugin_spec.py +1 -1
  29. snowflake/cli/{plugins → _plugins}/nativeapp/artifacts.py +14 -0
  30. snowflake/cli/_plugins/nativeapp/bundle_context.py +31 -0
  31. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/artifact_processor.py +3 -3
  32. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/compiler.py +16 -18
  33. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/setup/native_app_setup_processor.py +24 -28
  34. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/extension_function_utils.py +4 -4
  35. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/python_processor.py +20 -24
  36. snowflake/cli/{plugins → _plugins}/nativeapp/commands.py +171 -42
  37. snowflake/cli/{plugins → _plugins}/nativeapp/common_flags.py +1 -1
  38. snowflake/cli/{plugins → _plugins}/nativeapp/init.py +1 -1
  39. snowflake/cli/_plugins/nativeapp/manager.py +601 -0
  40. snowflake/cli/{plugins/connection → _plugins/nativeapp}/plugin_spec.py +1 -1
  41. snowflake/cli/{plugins → _plugins}/nativeapp/project_model.py +34 -11
  42. snowflake/cli/{plugins → _plugins}/nativeapp/run_processor.py +25 -23
  43. snowflake/cli/{plugins → _plugins}/nativeapp/teardown_processor.py +8 -8
  44. snowflake/cli/{plugins → _plugins}/nativeapp/v2_conversions/v2_to_v1_decorator.py +47 -28
  45. snowflake/cli/{plugins → _plugins}/nativeapp/version/commands.py +15 -12
  46. snowflake/cli/{plugins → _plugins}/nativeapp/version/version_processor.py +22 -20
  47. snowflake/cli/{plugins → _plugins}/notebook/commands.py +8 -6
  48. snowflake/cli/{plugins → _plugins}/notebook/manager.py +14 -14
  49. snowflake/cli/{plugins → _plugins}/notebook/plugin_spec.py +1 -1
  50. snowflake/cli/{plugins → _plugins}/notebook/types.py +0 -1
  51. snowflake/cli/{plugins → _plugins}/object/command_aliases.py +6 -5
  52. snowflake/cli/{plugins → _plugins}/object/commands.py +16 -10
  53. snowflake/cli/{plugins → _plugins}/object/manager.py +7 -6
  54. snowflake/cli/{plugins → _plugins}/object/plugin_spec.py +1 -1
  55. snowflake/cli/_plugins/snowpark/commands.py +510 -0
  56. snowflake/cli/_plugins/snowpark/common.py +252 -0
  57. snowflake/cli/{plugins → _plugins}/snowpark/models.py +0 -7
  58. snowflake/cli/{plugins → _plugins}/snowpark/package/anaconda_packages.py +1 -1
  59. snowflake/cli/{plugins → _plugins}/snowpark/package/commands.py +13 -74
  60. snowflake/cli/{plugins → _plugins}/snowpark/package/manager.py +4 -3
  61. snowflake/cli/{plugins → _plugins}/snowpark/package_utils.py +5 -5
  62. snowflake/cli/{plugins/nativeapp → _plugins/snowpark}/plugin_spec.py +1 -1
  63. snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +109 -0
  64. snowflake/cli/{plugins → _plugins}/snowpark/snowpark_shared.py +0 -36
  65. snowflake/cli/{plugins → _plugins}/snowpark/zipper.py +16 -8
  66. snowflake/cli/{plugins → _plugins}/spcs/__init__.py +5 -7
  67. snowflake/cli/{plugins → _plugins}/spcs/compute_pool/commands.py +29 -28
  68. snowflake/cli/{plugins → _plugins}/spcs/compute_pool/manager.py +3 -3
  69. snowflake/cli/{plugins → _plugins}/spcs/image_registry/commands.py +3 -3
  70. snowflake/cli/{plugins → _plugins}/spcs/image_repository/commands.py +25 -19
  71. snowflake/cli/{plugins → _plugins}/spcs/image_repository/manager.py +1 -1
  72. snowflake/cli/{plugins → _plugins}/spcs/plugin_spec.py +1 -1
  73. snowflake/cli/{plugins → _plugins}/spcs/services/commands.py +66 -32
  74. snowflake/cli/{plugins → _plugins}/spcs/services/manager.py +43 -5
  75. snowflake/cli/{plugins → _plugins}/sql/commands.py +19 -15
  76. snowflake/cli/{plugins → _plugins}/sql/manager.py +1 -1
  77. snowflake/cli/{plugins → _plugins}/sql/plugin_spec.py +1 -1
  78. snowflake/cli/{plugins → _plugins}/stage/commands.py +20 -17
  79. snowflake/cli/{plugins → _plugins}/stage/diff.py +1 -47
  80. snowflake/cli/{plugins → _plugins}/stage/manager.py +8 -6
  81. snowflake/cli/{plugins → _plugins}/stage/plugin_spec.py +1 -1
  82. snowflake/cli/_plugins/stage/utils.py +54 -0
  83. snowflake/cli/_plugins/streamlit/commands.py +242 -0
  84. snowflake/cli/{plugins → _plugins}/streamlit/manager.py +47 -70
  85. snowflake/cli/_plugins/streamlit/plugin_spec.py +30 -0
  86. snowflake/cli/_plugins/workspace/action_context.py +11 -0
  87. snowflake/cli/_plugins/workspace/commands.py +113 -0
  88. snowflake/cli/_plugins/workspace/manager.py +57 -0
  89. snowflake/cli/{plugins → _plugins}/workspace/plugin_spec.py +1 -1
  90. snowflake/cli/api/cli_global_context.py +34 -7
  91. snowflake/cli/api/commands/common.py +25 -0
  92. snowflake/cli/api/commands/decorators.py +4 -3
  93. snowflake/cli/api/commands/experimental_behaviour.py +2 -3
  94. snowflake/cli/api/commands/flags.py +73 -174
  95. snowflake/cli/api/commands/overrideable_parameter.py +143 -0
  96. snowflake/cli/api/commands/snow_typer.py +5 -4
  97. snowflake/cli/api/commands/typer_pre_execute.py +3 -3
  98. snowflake/cli/api/commands/utils.py +18 -0
  99. snowflake/cli/api/config.py +1 -1
  100. snowflake/cli/api/console/abc.py +5 -2
  101. snowflake/cli/api/entities/application_entity.py +12 -0
  102. snowflake/cli/api/entities/application_package_entity.py +260 -0
  103. snowflake/cli/api/entities/common.py +47 -0
  104. snowflake/cli/api/entities/snowpark_entity.py +29 -0
  105. snowflake/cli/api/entities/streamlit_entity.py +12 -0
  106. snowflake/cli/api/entities/utils.py +321 -0
  107. snowflake/cli/api/exceptions.py +19 -3
  108. snowflake/cli/api/feature_flags.py +2 -1
  109. snowflake/cli/api/identifiers.py +41 -9
  110. snowflake/cli/api/project/definition.py +13 -5
  111. snowflake/cli/api/project/definition_manager.py +12 -1
  112. snowflake/cli/api/project/project_verification.py +3 -3
  113. snowflake/cli/api/project/schemas/entities/{application_entity.py → application_entity_model.py} +21 -9
  114. snowflake/cli/api/project/schemas/entities/{application_package_entity.py → application_package_entity_model.py} +26 -15
  115. snowflake/cli/api/project/schemas/entities/common.py +80 -6
  116. snowflake/cli/api/project/schemas/entities/entities.py +38 -8
  117. snowflake/cli/api/project/schemas/entities/snowpark_entity.py +176 -0
  118. snowflake/cli/api/project/schemas/entities/streamlit_entity_model.py +73 -0
  119. snowflake/cli/api/project/schemas/identifier_model.py +10 -1
  120. snowflake/cli/api/project/schemas/native_app/application.py +8 -9
  121. snowflake/cli/api/project/schemas/native_app/package.py +7 -1
  122. snowflake/cli/api/project/schemas/project_definition.py +97 -23
  123. snowflake/cli/api/project/schemas/updatable_model.py +11 -3
  124. snowflake/cli/api/project/util.py +23 -6
  125. snowflake/cli/api/rendering/jinja.py +28 -8
  126. snowflake/cli/api/rendering/sql_templates.py +41 -12
  127. snowflake/cli/api/secure_path.py +3 -0
  128. snowflake/cli/api/sql_execution.py +35 -19
  129. snowflake/cli/api/utils/definition_rendering.py +14 -2
  130. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0rc0.dist-info}/METADATA +12 -12
  131. snowflake_cli_labs-3.0.0rc0.dist-info/RECORD +234 -0
  132. snowflake_cli_labs-3.0.0rc0.dist-info/entry_points.txt +2 -0
  133. snowflake/cli/api/commands/project_initialisation.py +0 -65
  134. snowflake/cli/app/build_and_push.sh +0 -8
  135. snowflake/cli/plugins/nativeapp/manager.py +0 -823
  136. snowflake/cli/plugins/object_stage_deprecated/__init__.py +0 -15
  137. snowflake/cli/plugins/object_stage_deprecated/commands.py +0 -122
  138. snowflake/cli/plugins/object_stage_deprecated/plugin_spec.py +0 -32
  139. snowflake/cli/plugins/snowpark/commands.py +0 -548
  140. snowflake/cli/plugins/snowpark/common.py +0 -307
  141. snowflake/cli/plugins/snowpark/manager.py +0 -109
  142. snowflake/cli/plugins/snowpark/plugin_spec.py +0 -30
  143. snowflake/cli/plugins/snowpark/snowpark_package_paths.py +0 -65
  144. snowflake/cli/plugins/spcs/jobs/commands.py +0 -78
  145. snowflake/cli/plugins/spcs/jobs/manager.py +0 -53
  146. snowflake/cli/plugins/streamlit/commands.py +0 -186
  147. snowflake/cli/plugins/streamlit/plugin_spec.py +0 -30
  148. snowflake/cli/plugins/workspace/commands.py +0 -35
  149. snowflake/cli/templates/default_snowpark/.gitignore +0 -4
  150. snowflake/cli/templates/default_snowpark/app/__init__.py +0 -0
  151. snowflake/cli/templates/default_snowpark/app/common.py +0 -2
  152. snowflake/cli/templates/default_snowpark/app/functions.py +0 -15
  153. snowflake/cli/templates/default_snowpark/app/procedures.py +0 -22
  154. snowflake/cli/templates/default_snowpark/requirements.txt +0 -1
  155. snowflake/cli/templates/default_snowpark/snowflake.yml +0 -23
  156. snowflake/cli/templates/default_streamlit/.gitignore +0 -4
  157. snowflake/cli/templates/default_streamlit/common/hello.py +0 -2
  158. snowflake/cli/templates/default_streamlit/environment.yml +0 -6
  159. snowflake/cli/templates/default_streamlit/pages/my_page.py +0 -3
  160. snowflake/cli/templates/default_streamlit/snowflake.yml +0 -10
  161. snowflake/cli/templates/default_streamlit/streamlit_app.py +0 -4
  162. snowflake_cli_labs-2.8.0rc1.dist-info/RECORD +0 -240
  163. snowflake_cli_labs-2.8.0rc1.dist-info/entry_points.txt +0 -2
  164. /snowflake/cli/{app → _app}/__init__.py +0 -0
  165. /snowflake/cli/{app → _app}/api_impl/__init__.py +0 -0
  166. /snowflake/cli/{app → _app}/api_impl/plugin/__init__.py +0 -0
  167. /snowflake/cli/{app → _app}/api_impl/plugin/plugin_config_provider_impl.py +0 -0
  168. /snowflake/cli/{app → _app}/commands_registration/__init__.py +0 -0
  169. /snowflake/cli/{app → _app}/commands_registration/threadsafe.py +0 -0
  170. /snowflake/cli/{app → _app}/constants.py +0 -0
  171. /snowflake/cli/{app → _app}/dev/__init__.py +0 -0
  172. /snowflake/cli/{app → _app}/dev/commands_structure.py +0 -0
  173. /snowflake/cli/{app → _app}/dev/docs/__init__.py +0 -0
  174. /snowflake/cli/{app → _app}/dev/docs/project_definition_generate_json_schema.py +0 -0
  175. /snowflake/cli/{app → _app}/dev/docs/template_utils.py +0 -0
  176. /snowflake/cli/{app → _app}/dev/docs/templates/definition_description.rst.jinja2 +0 -0
  177. /snowflake/cli/{app → _app}/dev/docs/templates/overview.rst.jinja2 +0 -0
  178. /snowflake/cli/{app → _app}/dev/pycharm_remote_debug.py +0 -0
  179. /snowflake/cli/{app → _app}/loggers.py +0 -0
  180. /snowflake/cli/{plugins → _plugins}/__init__.py +0 -0
  181. /snowflake/cli/{plugins → _plugins}/connection/__init__.py +0 -0
  182. /snowflake/cli/{plugins → _plugins}/cortex/__init__.py +0 -0
  183. /snowflake/cli/{plugins → _plugins}/cortex/types.py +0 -0
  184. /snowflake/cli/{plugins → _plugins}/git/__init__.py +0 -0
  185. /snowflake/cli/{plugins → _plugins}/init/__init__.py +0 -0
  186. /snowflake/cli/{plugins → _plugins}/nativeapp/__init__.py +0 -0
  187. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/__init__.py +0 -0
  188. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/sandbox.py +0 -0
  189. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/setup/setup_driver.py.source +0 -0
  190. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -0
  191. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/models.py +0 -0
  192. /snowflake/cli/{plugins → _plugins}/nativeapp/constants.py +0 -0
  193. /snowflake/cli/{plugins → _plugins}/nativeapp/exceptions.py +0 -0
  194. /snowflake/cli/{plugins → _plugins}/nativeapp/feature_flags.py +0 -0
  195. /snowflake/cli/{plugins → _plugins}/nativeapp/policy.py +0 -0
  196. /snowflake/cli/{plugins → _plugins}/nativeapp/utils.py +0 -0
  197. /snowflake/cli/{plugins → _plugins}/nativeapp/version/__init__.py +0 -0
  198. /snowflake/cli/{plugins → _plugins}/notebook/__init__.py +0 -0
  199. /snowflake/cli/{plugins → _plugins}/notebook/exceptions.py +0 -0
  200. /snowflake/cli/{plugins → _plugins}/object/__init__.py +0 -0
  201. /snowflake/cli/{plugins → _plugins}/object/common.py +0 -0
  202. /snowflake/cli/{plugins → _plugins}/snowpark/__init__.py +0 -0
  203. /snowflake/cli/{plugins → _plugins}/snowpark/package/__init__.py +0 -0
  204. /snowflake/cli/{plugins → _plugins}/snowpark/package/utils.py +0 -0
  205. /snowflake/cli/{plugins → _plugins}/spcs/common.py +0 -0
  206. /snowflake/cli/{plugins → _plugins}/spcs/compute_pool/__init__.py +0 -0
  207. /snowflake/cli/{plugins → _plugins}/spcs/image_registry/__init__.py +0 -0
  208. /snowflake/cli/{plugins → _plugins}/spcs/image_registry/manager.py +0 -0
  209. /snowflake/cli/{plugins → _plugins}/spcs/image_repository/__init__.py +0 -0
  210. /snowflake/cli/{plugins/spcs/jobs → _plugins/spcs/services}/__init__.py +0 -0
  211. /snowflake/cli/{plugins/spcs/services → _plugins/sql}/__init__.py +0 -0
  212. /snowflake/cli/{plugins → _plugins}/sql/snowsql_templating.py +0 -0
  213. /snowflake/cli/{plugins/sql → _plugins/stage}/__init__.py +0 -0
  214. /snowflake/cli/{plugins → _plugins}/stage/md5.py +0 -0
  215. /snowflake/cli/{plugins/stage → _plugins/streamlit}/__init__.py +0 -0
  216. /snowflake/cli/{plugins/streamlit → _plugins/workspace}/__init__.py +0 -0
  217. /snowflake/cli/{plugins/workspace → api/project/schemas/entities}/__init__.py +0 -0
  218. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0rc0.dist-info}/WHEEL +0 -0
  219. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0rc0.dist-info}/licenses/LICENSE +0 -0
@@ -1,548 +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 enum import Enum
19
- from typing import Dict, List, Optional, Set, Tuple
20
-
21
- import typer
22
- from click import ClickException
23
- from snowflake.cli.api.cli_global_context import cli_context
24
- from snowflake.cli.api.commands.decorators import (
25
- with_project_definition,
26
- )
27
- from snowflake.cli.api.commands.flags import (
28
- ReplaceOption,
29
- deprecated_flag_callback_enum,
30
- execution_identifier_argument,
31
- identifier_argument,
32
- like_option,
33
- )
34
- from snowflake.cli.api.commands.project_initialisation import add_init_command
35
- from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
36
- from snowflake.cli.api.constants import (
37
- DEFAULT_SIZE_LIMIT_MB,
38
- DEPLOYMENT_STAGE,
39
- ObjectType,
40
- )
41
- from snowflake.cli.api.exceptions import SecretsWithoutExternalAccessIntegrationError
42
- from snowflake.cli.api.identifiers import FQN
43
- from snowflake.cli.api.output.types import (
44
- CollectionResult,
45
- CommandResult,
46
- MessageResult,
47
- SingleQueryResult,
48
- )
49
- from snowflake.cli.api.project.project_verification import assert_project_type
50
- from snowflake.cli.api.project.schemas.snowpark.callable import (
51
- FunctionSchema,
52
- ProcedureSchema,
53
- )
54
- from snowflake.cli.api.secure_path import SecurePath
55
- from snowflake.cli.plugins.object.commands import (
56
- describe as object_describe,
57
- )
58
- from snowflake.cli.plugins.object.commands import (
59
- drop as object_drop,
60
- )
61
- from snowflake.cli.plugins.object.commands import (
62
- list_ as object_list,
63
- )
64
- from snowflake.cli.plugins.object.commands import (
65
- scope_option,
66
- )
67
- from snowflake.cli.plugins.object.manager import ObjectManager
68
- from snowflake.cli.plugins.snowpark import package_utils
69
- from snowflake.cli.plugins.snowpark.common import (
70
- FunctionOrProcedure,
71
- UdfSprocIdentifier,
72
- check_if_replace_is_required,
73
- )
74
- from snowflake.cli.plugins.snowpark.manager import FunctionManager, ProcedureManager
75
- from snowflake.cli.plugins.snowpark.models import YesNoAsk
76
- from snowflake.cli.plugins.snowpark.package.anaconda_packages import (
77
- AnacondaPackages,
78
- AnacondaPackagesManager,
79
- )
80
- from snowflake.cli.plugins.snowpark.package.commands import app as package_app
81
- from snowflake.cli.plugins.snowpark.snowpark_package_paths import SnowparkPackagePaths
82
- from snowflake.cli.plugins.snowpark.snowpark_shared import (
83
- AllowSharedLibrariesOption,
84
- DeprecatedCheckAnacondaForPyPiDependencies,
85
- IgnoreAnacondaOption,
86
- IndexUrlOption,
87
- SkipVersionCheckOption,
88
- deprecated_allow_native_libraries_option,
89
- resolve_allow_shared_libraries_yes_no_ask,
90
- )
91
- from snowflake.cli.plugins.snowpark.zipper import zip_dir
92
- from snowflake.cli.plugins.stage.manager import StageManager
93
- from snowflake.connector import DictCursor, ProgrammingError
94
-
95
- log = logging.getLogger(__name__)
96
-
97
- app = SnowTyperFactory(
98
- name="snowpark",
99
- help="Manages procedures and functions.",
100
- )
101
- app.add_typer(package_app)
102
-
103
- ObjectTypeArgument = typer.Argument(
104
- help="Type of Snowpark object",
105
- case_sensitive=False,
106
- show_default=False,
107
- )
108
- IdentifierArgument = identifier_argument(
109
- "function/procedure",
110
- example="hello(int, string)",
111
- )
112
- LikeOption = like_option(
113
- help_example='`list function --like "my%"` lists all functions that begin with “my”',
114
- )
115
- add_init_command(app, project_type="Snowpark", template="default_snowpark")
116
-
117
-
118
- @app.command("deploy", requires_connection=True)
119
- @with_project_definition()
120
- def deploy(
121
- replace: bool = ReplaceOption(
122
- help="Replaces procedure or function, even if no detected changes to metadata"
123
- ),
124
- **options,
125
- ) -> CommandResult:
126
- """
127
- Deploys procedures and functions defined in project. Deploying the project alters all objects defined in it.
128
- By default, if any of the objects exist already the commands will fail unless `--replace` flag is provided.
129
- All deployed objects use the same artifact which is deployed only once.
130
- """
131
-
132
- assert_project_type("snowpark")
133
-
134
- snowpark = cli_context.project_definition.snowpark
135
- paths = SnowparkPackagePaths.for_snowpark_project(
136
- project_root=SecurePath(cli_context.project_root),
137
- snowpark_project_definition=snowpark,
138
- )
139
-
140
- procedures = snowpark.procedures
141
- functions = snowpark.functions
142
-
143
- if not procedures and not functions:
144
- raise ClickException(
145
- "No procedures or functions were specified in the project definition."
146
- )
147
-
148
- if not paths.artifact_file.exists():
149
- raise ClickException(
150
- "Artifact required for deploying the project does not exist in this directory. "
151
- "Please use build command to create it."
152
- )
153
-
154
- pm = ProcedureManager()
155
- fm = FunctionManager()
156
- om = ObjectManager()
157
-
158
- _assert_object_definitions_are_correct("function", functions)
159
- _assert_object_definitions_are_correct("procedure", procedures)
160
- _check_if_all_defined_integrations_exists(om, functions, procedures)
161
-
162
- existing_functions = _find_existing_objects(ObjectType.FUNCTION, functions, om)
163
- existing_procedures = _find_existing_objects(ObjectType.PROCEDURE, procedures, om)
164
-
165
- if (existing_functions or existing_procedures) and not replace:
166
- msg = "Following objects already exists. Consider using --replace.\n"
167
- msg += "\n".join(f"function: {n}" for n in existing_functions)
168
- msg += "\n" if existing_functions and existing_procedures else ""
169
- msg += "\n".join(f"procedure: {n}" for n in existing_procedures)
170
- raise ClickException(msg)
171
-
172
- # Create stage
173
- stage_name = snowpark.stage_name
174
- stage_manager = StageManager()
175
- stage_name = FQN.from_string(stage_name).using_context()
176
- stage_manager.create(
177
- stage_name=stage_name, comment="deployments managed by Snowflake CLI"
178
- )
179
-
180
- snowflake_dependencies = _read_snowflake_requrements_file(
181
- paths.snowflake_requirements_file
182
- )
183
-
184
- artifact_stage_directory = get_app_stage_path(stage_name, snowpark.project_name)
185
- artifact_stage_target = (
186
- f"{artifact_stage_directory}/{paths.artifact_file.path.name}"
187
- )
188
-
189
- stage_manager.put(
190
- local_path=paths.artifact_file.path,
191
- stage_path=artifact_stage_directory,
192
- overwrite=True,
193
- )
194
-
195
- deploy_status = []
196
- # Procedures
197
- for procedure in procedures:
198
- operation_result = _deploy_single_object(
199
- manager=pm,
200
- object_type=ObjectType.PROCEDURE,
201
- object_definition=procedure,
202
- existing_objects=existing_procedures,
203
- snowflake_dependencies=snowflake_dependencies,
204
- stage_artifact_path=artifact_stage_target,
205
- )
206
- deploy_status.append(operation_result)
207
-
208
- # Functions
209
- for function in functions:
210
- operation_result = _deploy_single_object(
211
- manager=fm,
212
- object_type=ObjectType.FUNCTION,
213
- object_definition=function,
214
- existing_objects=existing_functions,
215
- snowflake_dependencies=snowflake_dependencies,
216
- stage_artifact_path=artifact_stage_target,
217
- )
218
- deploy_status.append(operation_result)
219
-
220
- return CollectionResult(deploy_status)
221
-
222
-
223
- def _assert_object_definitions_are_correct(
224
- object_type, object_definitions: List[FunctionOrProcedure]
225
- ):
226
- for definition in object_definitions:
227
- database = definition.database
228
- schema = definition.schema_name
229
- name = definition.name
230
- fqn_parts = len(name.split("."))
231
- if fqn_parts == 3 and database:
232
- raise ClickException(
233
- f"database of {object_type} {name} is redefined in its name"
234
- )
235
- if fqn_parts >= 2 and schema:
236
- raise ClickException(
237
- f"schema of {object_type} {name} is redefined in its name"
238
- )
239
-
240
-
241
- def _find_existing_objects(
242
- object_type: ObjectType,
243
- objects: List[FunctionOrProcedure],
244
- om: ObjectManager,
245
- ):
246
- existing_objects = {}
247
- for object_definition in objects:
248
- identifier = UdfSprocIdentifier.from_definition(
249
- object_definition
250
- ).identifier_with_arg_types
251
- try:
252
- current_state = om.describe(
253
- object_type=object_type.value.sf_name,
254
- name=identifier,
255
- )
256
- existing_objects[identifier] = current_state
257
- except ProgrammingError:
258
- pass
259
- return existing_objects
260
-
261
-
262
- def _check_if_all_defined_integrations_exists(
263
- om: ObjectManager,
264
- functions: List[FunctionSchema],
265
- procedures: List[ProcedureSchema],
266
- ):
267
- existing_integrations = {
268
- i["name"].lower()
269
- for i in om.show(object_type="integration", cursor_class=DictCursor, like=None)
270
- if i["type"] == "EXTERNAL_ACCESS"
271
- }
272
- declared_integration: Set[str] = set()
273
- for object_definition in [*functions, *procedures]:
274
- external_access_integrations = {
275
- s.lower() for s in object_definition.external_access_integrations
276
- }
277
- secrets = [s.lower() for s in object_definition.secrets]
278
-
279
- if not external_access_integrations and secrets:
280
- raise SecretsWithoutExternalAccessIntegrationError(object_definition.name)
281
-
282
- declared_integration = declared_integration | external_access_integrations
283
-
284
- missing = declared_integration - existing_integrations
285
- if missing:
286
- raise ClickException(
287
- f"Following external access integration does not exists in Snowflake: {', '.join(missing)}"
288
- )
289
-
290
-
291
- def get_app_stage_path(stage_name: Optional[str], project_name: str) -> str:
292
- artifact_stage_directory = f"@{(stage_name or DEPLOYMENT_STAGE)}/{project_name}"
293
- return artifact_stage_directory
294
-
295
-
296
- def _deploy_single_object(
297
- manager: FunctionManager | ProcedureManager,
298
- object_type: ObjectType,
299
- object_definition: FunctionOrProcedure,
300
- existing_objects: Dict[str, Dict],
301
- snowflake_dependencies: List[str],
302
- stage_artifact_path: str,
303
- ):
304
-
305
- identifiers = UdfSprocIdentifier.from_definition(object_definition)
306
-
307
- log.info(
308
- "Deploying %s: %s", object_type, identifiers.identifier_with_arg_names_types
309
- )
310
-
311
- handler = object_definition.handler
312
- returns = object_definition.returns
313
- imports = object_definition.imports
314
- external_access_integrations = object_definition.external_access_integrations
315
- runtime_ver = object_definition.runtime
316
- execute_as_caller = None
317
- if object_type == ObjectType.PROCEDURE:
318
- execute_as_caller = object_definition.execute_as_caller
319
- replace_object = False
320
-
321
- object_exists = identifiers.identifier_with_arg_types in existing_objects
322
- if object_exists:
323
- replace_object = check_if_replace_is_required(
324
- object_type=object_type,
325
- current_state=existing_objects[identifiers.identifier_with_arg_types],
326
- handler=handler,
327
- return_type=returns,
328
- snowflake_dependencies=snowflake_dependencies,
329
- external_access_integrations=external_access_integrations,
330
- imports=imports,
331
- stage_artifact_file=stage_artifact_path,
332
- runtime_ver=runtime_ver,
333
- execute_as_caller=execute_as_caller,
334
- )
335
-
336
- if object_exists and not replace_object:
337
- return {
338
- "object": identifiers.identifier_with_arg_names_types_defaults,
339
- "type": str(object_type),
340
- "status": "packages updated",
341
- }
342
-
343
- create_or_replace_kwargs = {
344
- "identifier": identifiers,
345
- "handler": handler,
346
- "return_type": returns,
347
- "artifact_file": stage_artifact_path,
348
- "packages": snowflake_dependencies,
349
- "runtime": object_definition.runtime,
350
- "external_access_integrations": object_definition.external_access_integrations,
351
- "secrets": object_definition.secrets,
352
- "imports": imports,
353
- }
354
- if object_type == ObjectType.PROCEDURE:
355
- create_or_replace_kwargs[
356
- "execute_as_caller"
357
- ] = object_definition.execute_as_caller
358
- manager.create_or_replace(**create_or_replace_kwargs)
359
-
360
- status = "created" if not object_exists else "definition updated"
361
- return {
362
- "object": identifiers.identifier_with_arg_names_types_defaults,
363
- "type": str(object_type),
364
- "status": status,
365
- }
366
-
367
-
368
- deprecated_pypi_download_option = typer.Option(
369
- YesNoAsk.NO.value,
370
- "--pypi-download",
371
- help="Whether to download non-Anaconda packages from PyPi.",
372
- hidden=True,
373
- callback=deprecated_flag_callback_enum(
374
- "--pypi-download flag is deprecated. Snowpark build command"
375
- " always tries to download non-Anaconda packages from external index (PyPi by default)."
376
- ),
377
- )
378
-
379
-
380
- def _read_snowflake_requrements_file(file_path: SecurePath):
381
- if not file_path.exists():
382
- return []
383
- return file_path.read_text(file_size_limit_mb=DEFAULT_SIZE_LIMIT_MB).splitlines()
384
-
385
-
386
- @app.command("build", requires_connection=True)
387
- @with_project_definition()
388
- def build(
389
- ignore_anaconda: bool = IgnoreAnacondaOption,
390
- allow_shared_libraries: bool = AllowSharedLibrariesOption,
391
- index_url: Optional[str] = IndexUrlOption,
392
- skip_version_check: bool = SkipVersionCheckOption,
393
- deprecated_package_native_libraries: YesNoAsk = deprecated_allow_native_libraries_option(
394
- "--package-native-libraries"
395
- ),
396
- deprecated_check_anaconda_for_pypi_deps: bool = DeprecatedCheckAnacondaForPyPiDependencies,
397
- _deprecated_pypi_download: YesNoAsk = deprecated_pypi_download_option,
398
- **options,
399
- ) -> CommandResult:
400
- """
401
- Builds the Snowpark project as a `.zip` archive that can be used by `deploy` command.
402
- The archive is built using only the `src` directory specified in the project file.
403
- """
404
-
405
- assert_project_type("snowpark")
406
-
407
- if not deprecated_check_anaconda_for_pypi_deps:
408
- ignore_anaconda = True
409
- snowpark_paths = SnowparkPackagePaths.for_snowpark_project(
410
- project_root=SecurePath(cli_context.project_root),
411
- snowpark_project_definition=cli_context.project_definition.snowpark,
412
- )
413
- log.info("Building package using sources from: %s", snowpark_paths.source.path)
414
-
415
- anaconda_packages_manager = AnacondaPackagesManager()
416
-
417
- with SecurePath.temporary_directory() as packages_dir:
418
- if snowpark_paths.defined_requirements_file.exists():
419
- log.info("Resolving any requirements from requirements.txt...")
420
- requirements = package_utils.parse_requirements(
421
- requirements_file=snowpark_paths.defined_requirements_file,
422
- )
423
- anaconda_packages = (
424
- AnacondaPackages.empty()
425
- if ignore_anaconda
426
- else anaconda_packages_manager.find_packages_available_in_snowflake_anaconda()
427
- )
428
- download_result = package_utils.download_unavailable_packages(
429
- requirements=requirements,
430
- target_dir=packages_dir,
431
- anaconda_packages=anaconda_packages,
432
- skip_version_check=skip_version_check,
433
- pip_index_url=index_url,
434
- )
435
- if not download_result.succeeded:
436
- raise ClickException(download_result.error_message)
437
-
438
- log.info("Checking to see if packages have shared (.so/.dll) libraries...")
439
- if package_utils.detect_and_log_shared_libraries(
440
- download_result.downloaded_packages_details
441
- ):
442
- # TODO: yes/no/ask logic should be removed in 3.0
443
- if not (
444
- allow_shared_libraries
445
- or resolve_allow_shared_libraries_yes_no_ask(
446
- deprecated_package_native_libraries
447
- )
448
- ):
449
- raise ClickException(
450
- "Some packages contain shared (.so/.dll) libraries. "
451
- "Try again with --allow-shared-libraries."
452
- )
453
- if download_result.anaconda_packages:
454
- anaconda_packages.write_requirements_file_in_snowflake_format( # type: ignore
455
- file_path=snowpark_paths.snowflake_requirements_file,
456
- requirements=download_result.anaconda_packages,
457
- )
458
-
459
- zip_dir(
460
- source=snowpark_paths.source.path,
461
- dest_zip=snowpark_paths.artifact_file.path,
462
- )
463
- if any(packages_dir.iterdir()):
464
- # if any packages were generated, append them to the .zip
465
- zip_dir(
466
- source=packages_dir.path,
467
- dest_zip=snowpark_paths.artifact_file.path,
468
- mode="a",
469
- )
470
-
471
- log.info("Package now ready: %s", snowpark_paths.artifact_file.path)
472
-
473
- return MessageResult(
474
- f"Build done. Artifact path: {snowpark_paths.artifact_file.path}"
475
- )
476
-
477
-
478
- class _SnowparkObject(Enum):
479
- """This clas is used only for Snowpark execute where choice is limited."""
480
-
481
- PROCEDURE = str(ObjectType.PROCEDURE)
482
- FUNCTION = str(ObjectType.FUNCTION)
483
-
484
-
485
- def _execute_object_method(
486
- method_name: str,
487
- object_type: _SnowparkObject,
488
- **kwargs,
489
- ):
490
- if object_type == _SnowparkObject.PROCEDURE:
491
- manager = ProcedureManager()
492
- elif object_type == _SnowparkObject.FUNCTION:
493
- manager = FunctionManager()
494
- else:
495
- raise ClickException(f"Unknown object type: {object_type}")
496
-
497
- return getattr(manager, method_name)(**kwargs)
498
-
499
-
500
- @app.command("execute", requires_connection=True)
501
- def execute(
502
- object_type: _SnowparkObject = ObjectTypeArgument,
503
- execution_identifier: str = execution_identifier_argument(
504
- "procedure/function", "hello(1, 'world')"
505
- ),
506
- **options,
507
- ) -> CommandResult:
508
- """Executes a procedure or function in a specified environment."""
509
- cursor = _execute_object_method(
510
- "execute", object_type=object_type, execution_identifier=execution_identifier
511
- )
512
- return SingleQueryResult(cursor)
513
-
514
-
515
- @app.command("list", requires_connection=True)
516
- def list_(
517
- object_type: _SnowparkObject = ObjectTypeArgument,
518
- like: str = LikeOption,
519
- scope: Tuple[str, str] = scope_option(
520
- help_example="`list function --in database my_db`"
521
- ),
522
- **options,
523
- ):
524
- """Lists all available procedures or functions."""
525
- return object_list(object_type=object_type.value, like=like, scope=scope, **options)
526
-
527
-
528
- @app.command("drop", requires_connection=True)
529
- def drop(
530
- object_type: _SnowparkObject = ObjectTypeArgument,
531
- identifier: str = IdentifierArgument,
532
- **options,
533
- ):
534
- """Drop procedure or function."""
535
- return object_drop(object_type=object_type.value, object_name=identifier, **options)
536
-
537
-
538
- @app.command("describe", requires_connection=True)
539
- def describe(
540
- object_type: _SnowparkObject = ObjectTypeArgument,
541
- identifier: str = IdentifierArgument,
542
- **options,
543
- ):
544
- """Provides description of a procedure or function."""
545
-
546
- return object_describe(
547
- object_type=object_type.value, object_name=identifier, **options
548
- )