snowflake-cli-labs 2.8.0rc1__py3-none-any.whl → 2.8.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. README.md +21 -0
  2. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-2.8.2.dist-info}/METADATA +7 -95
  3. snowflake_cli_labs-2.8.2.dist-info/RECORD +5 -0
  4. snowflake/cli/__about__.py +0 -17
  5. snowflake/cli/__init__.py +0 -13
  6. snowflake/cli/api/__init__.py +0 -48
  7. snowflake/cli/api/cli_global_context.py +0 -390
  8. snowflake/cli/api/commands/__init__.py +0 -13
  9. snowflake/cli/api/commands/alias.py +0 -23
  10. snowflake/cli/api/commands/decorators.py +0 -354
  11. snowflake/cli/api/commands/execution_metadata.py +0 -40
  12. snowflake/cli/api/commands/experimental_behaviour.py +0 -19
  13. snowflake/cli/api/commands/flags.py +0 -640
  14. snowflake/cli/api/commands/project_initialisation.py +0 -65
  15. snowflake/cli/api/commands/snow_typer.py +0 -237
  16. snowflake/cli/api/commands/typer_pre_execute.py +0 -26
  17. snowflake/cli/api/config.py +0 -348
  18. snowflake/cli/api/console/__init__.py +0 -17
  19. snowflake/cli/api/console/abc.py +0 -89
  20. snowflake/cli/api/console/console.py +0 -134
  21. snowflake/cli/api/console/enum.py +0 -17
  22. snowflake/cli/api/constants.py +0 -79
  23. snowflake/cli/api/errno.py +0 -27
  24. snowflake/cli/api/exceptions.py +0 -164
  25. snowflake/cli/api/feature_flags.py +0 -55
  26. snowflake/cli/api/identifiers.py +0 -154
  27. snowflake/cli/api/output/__init__.py +0 -13
  28. snowflake/cli/api/output/formats.py +0 -20
  29. snowflake/cli/api/output/types.py +0 -118
  30. snowflake/cli/api/plugins/__init__.py +0 -13
  31. snowflake/cli/api/plugins/command/__init__.py +0 -72
  32. snowflake/cli/api/plugins/command/plugin_hook_specs.py +0 -21
  33. snowflake/cli/api/plugins/plugin_config.py +0 -32
  34. snowflake/cli/api/project/__init__.py +0 -13
  35. snowflake/cli/api/project/definition.py +0 -84
  36. snowflake/cli/api/project/definition_manager.py +0 -134
  37. snowflake/cli/api/project/errors.py +0 -56
  38. snowflake/cli/api/project/project_verification.py +0 -23
  39. snowflake/cli/api/project/schemas/__init__.py +0 -13
  40. snowflake/cli/api/project/schemas/entities/application_entity.py +0 -44
  41. snowflake/cli/api/project/schemas/entities/application_package_entity.py +0 -66
  42. snowflake/cli/api/project/schemas/entities/common.py +0 -78
  43. snowflake/cli/api/project/schemas/entities/entities.py +0 -30
  44. snowflake/cli/api/project/schemas/identifier_model.py +0 -49
  45. snowflake/cli/api/project/schemas/native_app/__init__.py +0 -13
  46. snowflake/cli/api/project/schemas/native_app/application.py +0 -62
  47. snowflake/cli/api/project/schemas/native_app/native_app.py +0 -93
  48. snowflake/cli/api/project/schemas/native_app/package.py +0 -78
  49. snowflake/cli/api/project/schemas/native_app/path_mapping.py +0 -65
  50. snowflake/cli/api/project/schemas/project_definition.py +0 -199
  51. snowflake/cli/api/project/schemas/snowpark/__init__.py +0 -13
  52. snowflake/cli/api/project/schemas/snowpark/argument.py +0 -28
  53. snowflake/cli/api/project/schemas/snowpark/callable.py +0 -69
  54. snowflake/cli/api/project/schemas/snowpark/snowpark.py +0 -36
  55. snowflake/cli/api/project/schemas/streamlit/__init__.py +0 -13
  56. snowflake/cli/api/project/schemas/streamlit/streamlit.py +0 -46
  57. snowflake/cli/api/project/schemas/template.py +0 -77
  58. snowflake/cli/api/project/schemas/updatable_model.py +0 -194
  59. snowflake/cli/api/project/util.py +0 -261
  60. snowflake/cli/api/rendering/__init__.py +0 -13
  61. snowflake/cli/api/rendering/jinja.py +0 -112
  62. snowflake/cli/api/rendering/project_definition_templates.py +0 -39
  63. snowflake/cli/api/rendering/project_templates.py +0 -98
  64. snowflake/cli/api/rendering/sql_templates.py +0 -60
  65. snowflake/cli/api/rest_api.py +0 -172
  66. snowflake/cli/api/sanitizers.py +0 -43
  67. snowflake/cli/api/secure_path.py +0 -362
  68. snowflake/cli/api/secure_utils.py +0 -29
  69. snowflake/cli/api/sql_execution.py +0 -260
  70. snowflake/cli/api/utils/__init__.py +0 -13
  71. snowflake/cli/api/utils/cursor.py +0 -34
  72. snowflake/cli/api/utils/definition_rendering.py +0 -383
  73. snowflake/cli/api/utils/dict_utils.py +0 -73
  74. snowflake/cli/api/utils/error_handling.py +0 -23
  75. snowflake/cli/api/utils/graph.py +0 -97
  76. snowflake/cli/api/utils/models.py +0 -63
  77. snowflake/cli/api/utils/naming_utils.py +0 -13
  78. snowflake/cli/api/utils/path_utils.py +0 -36
  79. snowflake/cli/api/utils/templating_functions.py +0 -144
  80. snowflake/cli/api/utils/types.py +0 -35
  81. snowflake/cli/app/__init__.py +0 -22
  82. snowflake/cli/app/__main__.py +0 -31
  83. snowflake/cli/app/api_impl/__init__.py +0 -13
  84. snowflake/cli/app/api_impl/plugin/__init__.py +0 -13
  85. snowflake/cli/app/api_impl/plugin/plugin_config_provider_impl.py +0 -66
  86. snowflake/cli/app/build_and_push.sh +0 -8
  87. snowflake/cli/app/cli_app.py +0 -243
  88. snowflake/cli/app/commands_registration/__init__.py +0 -33
  89. snowflake/cli/app/commands_registration/builtin_plugins.py +0 -54
  90. snowflake/cli/app/commands_registration/command_plugins_loader.py +0 -169
  91. snowflake/cli/app/commands_registration/commands_registration_with_callbacks.py +0 -105
  92. snowflake/cli/app/commands_registration/exception_logging.py +0 -26
  93. snowflake/cli/app/commands_registration/threadsafe.py +0 -48
  94. snowflake/cli/app/commands_registration/typer_registration.py +0 -153
  95. snowflake/cli/app/constants.py +0 -19
  96. snowflake/cli/app/dev/__init__.py +0 -13
  97. snowflake/cli/app/dev/commands_structure.py +0 -48
  98. snowflake/cli/app/dev/docs/__init__.py +0 -13
  99. snowflake/cli/app/dev/docs/commands_docs_generator.py +0 -100
  100. snowflake/cli/app/dev/docs/generator.py +0 -35
  101. snowflake/cli/app/dev/docs/project_definition_docs_generator.py +0 -58
  102. snowflake/cli/app/dev/docs/project_definition_generate_json_schema.py +0 -227
  103. snowflake/cli/app/dev/docs/template_utils.py +0 -23
  104. snowflake/cli/app/dev/docs/templates/definition_description.rst.jinja2 +0 -38
  105. snowflake/cli/app/dev/docs/templates/overview.rst.jinja2 +0 -9
  106. snowflake/cli/app/dev/docs/templates/usage.rst.jinja2 +0 -57
  107. snowflake/cli/app/dev/pycharm_remote_debug.py +0 -46
  108. snowflake/cli/app/loggers.py +0 -199
  109. snowflake/cli/app/main_typer.py +0 -62
  110. snowflake/cli/app/printing.py +0 -181
  111. snowflake/cli/app/snow_connector.py +0 -243
  112. snowflake/cli/app/telemetry.py +0 -189
  113. snowflake/cli/plugins/__init__.py +0 -13
  114. snowflake/cli/plugins/connection/__init__.py +0 -13
  115. snowflake/cli/plugins/connection/commands.py +0 -330
  116. snowflake/cli/plugins/connection/plugin_spec.py +0 -30
  117. snowflake/cli/plugins/connection/util.py +0 -179
  118. snowflake/cli/plugins/cortex/__init__.py +0 -13
  119. snowflake/cli/plugins/cortex/commands.py +0 -327
  120. snowflake/cli/plugins/cortex/constants.py +0 -17
  121. snowflake/cli/plugins/cortex/manager.py +0 -189
  122. snowflake/cli/plugins/cortex/plugin_spec.py +0 -30
  123. snowflake/cli/plugins/cortex/types.py +0 -22
  124. snowflake/cli/plugins/git/__init__.py +0 -13
  125. snowflake/cli/plugins/git/commands.py +0 -305
  126. snowflake/cli/plugins/git/manager.py +0 -96
  127. snowflake/cli/plugins/git/plugin_spec.py +0 -30
  128. snowflake/cli/plugins/init/__init__.py +0 -13
  129. snowflake/cli/plugins/init/commands.py +0 -244
  130. snowflake/cli/plugins/init/plugin_spec.py +0 -30
  131. snowflake/cli/plugins/nativeapp/__init__.py +0 -13
  132. snowflake/cli/plugins/nativeapp/artifacts.py +0 -742
  133. snowflake/cli/plugins/nativeapp/codegen/__init__.py +0 -13
  134. snowflake/cli/plugins/nativeapp/codegen/artifact_processor.py +0 -91
  135. snowflake/cli/plugins/nativeapp/codegen/compiler.py +0 -130
  136. snowflake/cli/plugins/nativeapp/codegen/sandbox.py +0 -306
  137. snowflake/cli/plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -172
  138. snowflake/cli/plugins/nativeapp/codegen/setup/setup_driver.py.source +0 -56
  139. snowflake/cli/plugins/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -181
  140. snowflake/cli/plugins/nativeapp/codegen/snowpark/extension_function_utils.py +0 -217
  141. snowflake/cli/plugins/nativeapp/codegen/snowpark/models.py +0 -61
  142. snowflake/cli/plugins/nativeapp/codegen/snowpark/python_processor.py +0 -528
  143. snowflake/cli/plugins/nativeapp/commands.py +0 -439
  144. snowflake/cli/plugins/nativeapp/common_flags.py +0 -44
  145. snowflake/cli/plugins/nativeapp/constants.py +0 -27
  146. snowflake/cli/plugins/nativeapp/exceptions.py +0 -122
  147. snowflake/cli/plugins/nativeapp/feature_flags.py +0 -24
  148. snowflake/cli/plugins/nativeapp/init.py +0 -345
  149. snowflake/cli/plugins/nativeapp/manager.py +0 -823
  150. snowflake/cli/plugins/nativeapp/plugin_spec.py +0 -30
  151. snowflake/cli/plugins/nativeapp/policy.py +0 -50
  152. snowflake/cli/plugins/nativeapp/project_model.py +0 -195
  153. snowflake/cli/plugins/nativeapp/run_processor.py +0 -389
  154. snowflake/cli/plugins/nativeapp/teardown_processor.py +0 -301
  155. snowflake/cli/plugins/nativeapp/utils.py +0 -98
  156. snowflake/cli/plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -135
  157. snowflake/cli/plugins/nativeapp/version/__init__.py +0 -13
  158. snowflake/cli/plugins/nativeapp/version/commands.py +0 -170
  159. snowflake/cli/plugins/nativeapp/version/version_processor.py +0 -362
  160. snowflake/cli/plugins/notebook/__init__.py +0 -13
  161. snowflake/cli/plugins/notebook/commands.py +0 -84
  162. snowflake/cli/plugins/notebook/exceptions.py +0 -20
  163. snowflake/cli/plugins/notebook/manager.py +0 -71
  164. snowflake/cli/plugins/notebook/plugin_spec.py +0 -30
  165. snowflake/cli/plugins/notebook/types.py +0 -16
  166. snowflake/cli/plugins/object/__init__.py +0 -13
  167. snowflake/cli/plugins/object/command_aliases.py +0 -94
  168. snowflake/cli/plugins/object/commands.py +0 -174
  169. snowflake/cli/plugins/object/common.py +0 -85
  170. snowflake/cli/plugins/object/manager.py +0 -96
  171. snowflake/cli/plugins/object/plugin_spec.py +0 -30
  172. snowflake/cli/plugins/object_stage_deprecated/__init__.py +0 -15
  173. snowflake/cli/plugins/object_stage_deprecated/commands.py +0 -122
  174. snowflake/cli/plugins/object_stage_deprecated/plugin_spec.py +0 -32
  175. snowflake/cli/plugins/snowpark/__init__.py +0 -13
  176. snowflake/cli/plugins/snowpark/commands.py +0 -548
  177. snowflake/cli/plugins/snowpark/common.py +0 -307
  178. snowflake/cli/plugins/snowpark/manager.py +0 -109
  179. snowflake/cli/plugins/snowpark/models.py +0 -156
  180. snowflake/cli/plugins/snowpark/package/__init__.py +0 -13
  181. snowflake/cli/plugins/snowpark/package/anaconda_packages.py +0 -233
  182. snowflake/cli/plugins/snowpark/package/commands.py +0 -256
  183. snowflake/cli/plugins/snowpark/package/manager.py +0 -43
  184. snowflake/cli/plugins/snowpark/package/utils.py +0 -26
  185. snowflake/cli/plugins/snowpark/package_utils.py +0 -354
  186. snowflake/cli/plugins/snowpark/plugin_spec.py +0 -30
  187. snowflake/cli/plugins/snowpark/snowpark_package_paths.py +0 -65
  188. snowflake/cli/plugins/snowpark/snowpark_shared.py +0 -95
  189. snowflake/cli/plugins/snowpark/zipper.py +0 -81
  190. snowflake/cli/plugins/spcs/__init__.py +0 -35
  191. snowflake/cli/plugins/spcs/common.py +0 -99
  192. snowflake/cli/plugins/spcs/compute_pool/__init__.py +0 -13
  193. snowflake/cli/plugins/spcs/compute_pool/commands.py +0 -240
  194. snowflake/cli/plugins/spcs/compute_pool/manager.py +0 -121
  195. snowflake/cli/plugins/spcs/image_registry/__init__.py +0 -13
  196. snowflake/cli/plugins/spcs/image_registry/commands.py +0 -65
  197. snowflake/cli/plugins/spcs/image_registry/manager.py +0 -105
  198. snowflake/cli/plugins/spcs/image_repository/__init__.py +0 -13
  199. snowflake/cli/plugins/spcs/image_repository/commands.py +0 -196
  200. snowflake/cli/plugins/spcs/image_repository/manager.py +0 -84
  201. snowflake/cli/plugins/spcs/jobs/__init__.py +0 -13
  202. snowflake/cli/plugins/spcs/jobs/commands.py +0 -78
  203. snowflake/cli/plugins/spcs/jobs/manager.py +0 -53
  204. snowflake/cli/plugins/spcs/plugin_spec.py +0 -30
  205. snowflake/cli/plugins/spcs/services/__init__.py +0 -13
  206. snowflake/cli/plugins/spcs/services/commands.py +0 -311
  207. snowflake/cli/plugins/spcs/services/manager.py +0 -170
  208. snowflake/cli/plugins/sql/__init__.py +0 -13
  209. snowflake/cli/plugins/sql/commands.py +0 -83
  210. snowflake/cli/plugins/sql/manager.py +0 -92
  211. snowflake/cli/plugins/sql/plugin_spec.py +0 -30
  212. snowflake/cli/plugins/sql/snowsql_templating.py +0 -28
  213. snowflake/cli/plugins/stage/__init__.py +0 -13
  214. snowflake/cli/plugins/stage/commands.py +0 -261
  215. snowflake/cli/plugins/stage/diff.py +0 -326
  216. snowflake/cli/plugins/stage/manager.py +0 -544
  217. snowflake/cli/plugins/stage/md5.py +0 -160
  218. snowflake/cli/plugins/stage/plugin_spec.py +0 -30
  219. snowflake/cli/plugins/streamlit/__init__.py +0 -13
  220. snowflake/cli/plugins/streamlit/commands.py +0 -186
  221. snowflake/cli/plugins/streamlit/manager.py +0 -222
  222. snowflake/cli/plugins/streamlit/plugin_spec.py +0 -30
  223. snowflake/cli/plugins/workspace/__init__.py +0 -13
  224. snowflake/cli/plugins/workspace/commands.py +0 -35
  225. snowflake/cli/plugins/workspace/plugin_spec.py +0 -30
  226. snowflake/cli/templates/default_snowpark/.gitignore +0 -4
  227. snowflake/cli/templates/default_snowpark/app/__init__.py +0 -0
  228. snowflake/cli/templates/default_snowpark/app/common.py +0 -2
  229. snowflake/cli/templates/default_snowpark/app/functions.py +0 -15
  230. snowflake/cli/templates/default_snowpark/app/procedures.py +0 -22
  231. snowflake/cli/templates/default_snowpark/requirements.txt +0 -1
  232. snowflake/cli/templates/default_snowpark/snowflake.yml +0 -23
  233. snowflake/cli/templates/default_streamlit/.gitignore +0 -4
  234. snowflake/cli/templates/default_streamlit/common/hello.py +0 -2
  235. snowflake/cli/templates/default_streamlit/environment.yml +0 -6
  236. snowflake/cli/templates/default_streamlit/pages/my_page.py +0 -3
  237. snowflake/cli/templates/default_streamlit/snowflake.yml +0 -10
  238. snowflake/cli/templates/default_streamlit/streamlit_app.py +0 -4
  239. snowflake_cli_labs-2.8.0rc1.dist-info/RECORD +0 -240
  240. snowflake_cli_labs-2.8.0rc1.dist-info/entry_points.txt +0 -2
  241. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-2.8.2.dist-info}/WHEEL +0 -0
  242. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-2.8.2.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
- )