snowflake-cli-labs 3.0.0rc5__py3-none-any.whl → 3.0.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 (244) hide show
  1. README.md +21 -0
  2. {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/METADATA +6 -96
  3. snowflake_cli_labs-3.0.2.dist-info/RECORD +5 -0
  4. snowflake/cli/__about__.py +0 -17
  5. snowflake/cli/__init__.py +0 -13
  6. snowflake/cli/_app/__init__.py +0 -22
  7. snowflake/cli/_app/__main__.py +0 -31
  8. snowflake/cli/_app/api_impl/__init__.py +0 -13
  9. snowflake/cli/_app/api_impl/plugin/__init__.py +0 -13
  10. snowflake/cli/_app/api_impl/plugin/plugin_config_provider_impl.py +0 -66
  11. snowflake/cli/_app/cli_app.py +0 -252
  12. snowflake/cli/_app/commands_registration/__init__.py +0 -33
  13. snowflake/cli/_app/commands_registration/builtin_plugins.py +0 -50
  14. snowflake/cli/_app/commands_registration/command_plugins_loader.py +0 -169
  15. snowflake/cli/_app/commands_registration/commands_registration_with_callbacks.py +0 -105
  16. snowflake/cli/_app/commands_registration/exception_logging.py +0 -26
  17. snowflake/cli/_app/commands_registration/threadsafe.py +0 -48
  18. snowflake/cli/_app/commands_registration/typer_registration.py +0 -153
  19. snowflake/cli/_app/constants.py +0 -19
  20. snowflake/cli/_app/dev/__init__.py +0 -13
  21. snowflake/cli/_app/dev/commands_structure.py +0 -48
  22. snowflake/cli/_app/dev/docs/__init__.py +0 -13
  23. snowflake/cli/_app/dev/docs/commands_docs_generator.py +0 -118
  24. snowflake/cli/_app/dev/docs/generator.py +0 -35
  25. snowflake/cli/_app/dev/docs/project_definition_docs_generator.py +0 -58
  26. snowflake/cli/_app/dev/docs/project_definition_generate_json_schema.py +0 -227
  27. snowflake/cli/_app/dev/docs/template_utils.py +0 -23
  28. snowflake/cli/_app/dev/docs/templates/definition_description.rst.jinja2 +0 -38
  29. snowflake/cli/_app/dev/docs/templates/overview.rst.jinja2 +0 -9
  30. snowflake/cli/_app/dev/docs/templates/usage.rst.jinja2 +0 -67
  31. snowflake/cli/_app/dev/pycharm_remote_debug.py +0 -46
  32. snowflake/cli/_app/loggers.py +0 -199
  33. snowflake/cli/_app/main_typer.py +0 -62
  34. snowflake/cli/_app/printing.py +0 -181
  35. snowflake/cli/_app/secret.py +0 -9
  36. snowflake/cli/_app/snow_connector.py +0 -309
  37. snowflake/cli/_app/telemetry.py +0 -220
  38. snowflake/cli/_app/version_check.py +0 -74
  39. snowflake/cli/_plugins/__init__.py +0 -13
  40. snowflake/cli/_plugins/connection/__init__.py +0 -13
  41. snowflake/cli/_plugins/connection/commands.py +0 -353
  42. snowflake/cli/_plugins/connection/plugin_spec.py +0 -30
  43. snowflake/cli/_plugins/connection/util.py +0 -195
  44. snowflake/cli/_plugins/cortex/__init__.py +0 -13
  45. snowflake/cli/_plugins/cortex/commands.py +0 -332
  46. snowflake/cli/_plugins/cortex/constants.py +0 -17
  47. snowflake/cli/_plugins/cortex/manager.py +0 -189
  48. snowflake/cli/_plugins/cortex/plugin_spec.py +0 -30
  49. snowflake/cli/_plugins/cortex/types.py +0 -22
  50. snowflake/cli/_plugins/git/__init__.py +0 -13
  51. snowflake/cli/_plugins/git/commands.py +0 -358
  52. snowflake/cli/_plugins/git/manager.py +0 -151
  53. snowflake/cli/_plugins/git/plugin_spec.py +0 -30
  54. snowflake/cli/_plugins/helpers/__init__.py +0 -13
  55. snowflake/cli/_plugins/helpers/commands.py +0 -90
  56. snowflake/cli/_plugins/helpers/plugin_spec.py +0 -30
  57. snowflake/cli/_plugins/init/__init__.py +0 -13
  58. snowflake/cli/_plugins/init/commands.py +0 -248
  59. snowflake/cli/_plugins/init/plugin_spec.py +0 -30
  60. snowflake/cli/_plugins/nativeapp/__init__.py +0 -13
  61. snowflake/cli/_plugins/nativeapp/artifacts.py +0 -757
  62. snowflake/cli/_plugins/nativeapp/bundle_context.py +0 -31
  63. snowflake/cli/_plugins/nativeapp/codegen/__init__.py +0 -13
  64. snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py +0 -91
  65. snowflake/cli/_plugins/nativeapp/codegen/compiler.py +0 -149
  66. snowflake/cli/_plugins/nativeapp/codegen/sandbox.py +0 -306
  67. snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -249
  68. snowflake/cli/_plugins/nativeapp/codegen/setup/setup_driver.py.source +0 -59
  69. snowflake/cli/_plugins/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -181
  70. snowflake/cli/_plugins/nativeapp/codegen/snowpark/extension_function_utils.py +0 -217
  71. snowflake/cli/_plugins/nativeapp/codegen/snowpark/models.py +0 -61
  72. snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py +0 -523
  73. snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +0 -114
  74. snowflake/cli/_plugins/nativeapp/commands.py +0 -559
  75. snowflake/cli/_plugins/nativeapp/common_flags.py +0 -44
  76. snowflake/cli/_plugins/nativeapp/constants.py +0 -27
  77. snowflake/cli/_plugins/nativeapp/entities/__init__.py +0 -0
  78. snowflake/cli/_plugins/nativeapp/entities/application.py +0 -878
  79. snowflake/cli/_plugins/nativeapp/entities/application_package.py +0 -1392
  80. snowflake/cli/_plugins/nativeapp/exceptions.py +0 -113
  81. snowflake/cli/_plugins/nativeapp/feature_flags.py +0 -24
  82. snowflake/cli/_plugins/nativeapp/manager.py +0 -415
  83. snowflake/cli/_plugins/nativeapp/plugin_spec.py +0 -30
  84. snowflake/cli/_plugins/nativeapp/policy.py +0 -53
  85. snowflake/cli/_plugins/nativeapp/project_model.py +0 -211
  86. snowflake/cli/_plugins/nativeapp/run_processor.py +0 -184
  87. snowflake/cli/_plugins/nativeapp/same_account_install_method.py +0 -70
  88. snowflake/cli/_plugins/nativeapp/teardown_processor.py +0 -70
  89. snowflake/cli/_plugins/nativeapp/utils.py +0 -98
  90. snowflake/cli/_plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -262
  91. snowflake/cli/_plugins/nativeapp/version/__init__.py +0 -13
  92. snowflake/cli/_plugins/nativeapp/version/commands.py +0 -141
  93. snowflake/cli/_plugins/nativeapp/version/version_processor.py +0 -98
  94. snowflake/cli/_plugins/notebook/__init__.py +0 -13
  95. snowflake/cli/_plugins/notebook/commands.py +0 -86
  96. snowflake/cli/_plugins/notebook/exceptions.py +0 -20
  97. snowflake/cli/_plugins/notebook/manager.py +0 -71
  98. snowflake/cli/_plugins/notebook/plugin_spec.py +0 -30
  99. snowflake/cli/_plugins/notebook/types.py +0 -15
  100. snowflake/cli/_plugins/object/__init__.py +0 -13
  101. snowflake/cli/_plugins/object/command_aliases.py +0 -95
  102. snowflake/cli/_plugins/object/commands.py +0 -180
  103. snowflake/cli/_plugins/object/common.py +0 -85
  104. snowflake/cli/_plugins/object/manager.py +0 -118
  105. snowflake/cli/_plugins/object/plugin_spec.py +0 -30
  106. snowflake/cli/_plugins/snowpark/__init__.py +0 -13
  107. snowflake/cli/_plugins/snowpark/commands.py +0 -450
  108. snowflake/cli/_plugins/snowpark/common.py +0 -268
  109. snowflake/cli/_plugins/snowpark/models.py +0 -150
  110. snowflake/cli/_plugins/snowpark/package/__init__.py +0 -13
  111. snowflake/cli/_plugins/snowpark/package/anaconda_packages.py +0 -199
  112. snowflake/cli/_plugins/snowpark/package/commands.py +0 -195
  113. snowflake/cli/_plugins/snowpark/package/manager.py +0 -44
  114. snowflake/cli/_plugins/snowpark/package/utils.py +0 -26
  115. snowflake/cli/_plugins/snowpark/package_utils.py +0 -354
  116. snowflake/cli/_plugins/snowpark/plugin_spec.py +0 -30
  117. snowflake/cli/_plugins/snowpark/snowpark_entity.py +0 -29
  118. snowflake/cli/_plugins/snowpark/snowpark_entity_model.py +0 -173
  119. snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +0 -109
  120. snowflake/cli/_plugins/snowpark/snowpark_shared.py +0 -59
  121. snowflake/cli/_plugins/snowpark/zipper.py +0 -89
  122. snowflake/cli/_plugins/spcs/__init__.py +0 -33
  123. snowflake/cli/_plugins/spcs/common.py +0 -99
  124. snowflake/cli/_plugins/spcs/compute_pool/__init__.py +0 -13
  125. snowflake/cli/_plugins/spcs/compute_pool/commands.py +0 -241
  126. snowflake/cli/_plugins/spcs/compute_pool/manager.py +0 -121
  127. snowflake/cli/_plugins/spcs/image_registry/__init__.py +0 -13
  128. snowflake/cli/_plugins/spcs/image_registry/commands.py +0 -65
  129. snowflake/cli/_plugins/spcs/image_registry/manager.py +0 -105
  130. snowflake/cli/_plugins/spcs/image_repository/__init__.py +0 -13
  131. snowflake/cli/_plugins/spcs/image_repository/commands.py +0 -202
  132. snowflake/cli/_plugins/spcs/image_repository/manager.py +0 -84
  133. snowflake/cli/_plugins/spcs/plugin_spec.py +0 -30
  134. snowflake/cli/_plugins/spcs/services/__init__.py +0 -13
  135. snowflake/cli/_plugins/spcs/services/commands.py +0 -345
  136. snowflake/cli/_plugins/spcs/services/manager.py +0 -208
  137. snowflake/cli/_plugins/sql/__init__.py +0 -13
  138. snowflake/cli/_plugins/sql/commands.py +0 -86
  139. snowflake/cli/_plugins/sql/manager.py +0 -92
  140. snowflake/cli/_plugins/sql/plugin_spec.py +0 -30
  141. snowflake/cli/_plugins/sql/snowsql_templating.py +0 -28
  142. snowflake/cli/_plugins/stage/__init__.py +0 -13
  143. snowflake/cli/_plugins/stage/commands.py +0 -264
  144. snowflake/cli/_plugins/stage/diff.py +0 -280
  145. snowflake/cli/_plugins/stage/manager.py +0 -582
  146. snowflake/cli/_plugins/stage/md5.py +0 -160
  147. snowflake/cli/_plugins/stage/plugin_spec.py +0 -30
  148. snowflake/cli/_plugins/stage/utils.py +0 -54
  149. snowflake/cli/_plugins/streamlit/__init__.py +0 -13
  150. snowflake/cli/_plugins/streamlit/commands.py +0 -195
  151. snowflake/cli/_plugins/streamlit/manager.py +0 -220
  152. snowflake/cli/_plugins/streamlit/plugin_spec.py +0 -30
  153. snowflake/cli/_plugins/streamlit/streamlit_entity.py +0 -12
  154. snowflake/cli/_plugins/streamlit/streamlit_entity_model.py +0 -66
  155. snowflake/cli/_plugins/workspace/__init__.py +0 -13
  156. snowflake/cli/_plugins/workspace/action_context.py +0 -18
  157. snowflake/cli/_plugins/workspace/commands.py +0 -306
  158. snowflake/cli/_plugins/workspace/manager.py +0 -74
  159. snowflake/cli/_plugins/workspace/plugin_spec.py +0 -30
  160. snowflake/cli/api/__init__.py +0 -48
  161. snowflake/cli/api/cli_global_context.py +0 -247
  162. snowflake/cli/api/commands/__init__.py +0 -13
  163. snowflake/cli/api/commands/alias.py +0 -23
  164. snowflake/cli/api/commands/common.py +0 -25
  165. snowflake/cli/api/commands/decorators.py +0 -369
  166. snowflake/cli/api/commands/execution_metadata.py +0 -40
  167. snowflake/cli/api/commands/experimental_behaviour.py +0 -18
  168. snowflake/cli/api/commands/flags.py +0 -561
  169. snowflake/cli/api/commands/overrideable_parameter.py +0 -143
  170. snowflake/cli/api/commands/snow_typer.py +0 -247
  171. snowflake/cli/api/commands/utils.py +0 -18
  172. snowflake/cli/api/config.py +0 -380
  173. snowflake/cli/api/connections.py +0 -216
  174. snowflake/cli/api/console/__init__.py +0 -17
  175. snowflake/cli/api/console/abc.py +0 -94
  176. snowflake/cli/api/console/console.py +0 -134
  177. snowflake/cli/api/console/enum.py +0 -17
  178. snowflake/cli/api/constants.py +0 -90
  179. snowflake/cli/api/entities/common.py +0 -56
  180. snowflake/cli/api/entities/utils.py +0 -370
  181. snowflake/cli/api/errno.py +0 -28
  182. snowflake/cli/api/exceptions.py +0 -190
  183. snowflake/cli/api/feature_flags.py +0 -54
  184. snowflake/cli/api/identifiers.py +0 -190
  185. snowflake/cli/api/metrics.py +0 -92
  186. snowflake/cli/api/output/__init__.py +0 -13
  187. snowflake/cli/api/output/formats.py +0 -20
  188. snowflake/cli/api/output/types.py +0 -118
  189. snowflake/cli/api/plugins/__init__.py +0 -13
  190. snowflake/cli/api/plugins/command/__init__.py +0 -72
  191. snowflake/cli/api/plugins/command/plugin_hook_specs.py +0 -21
  192. snowflake/cli/api/plugins/plugin_config.py +0 -32
  193. snowflake/cli/api/project/__init__.py +0 -13
  194. snowflake/cli/api/project/definition.py +0 -126
  195. snowflake/cli/api/project/definition_conversion.py +0 -400
  196. snowflake/cli/api/project/definition_manager.py +0 -145
  197. snowflake/cli/api/project/errors.py +0 -56
  198. snowflake/cli/api/project/project_verification.py +0 -23
  199. snowflake/cli/api/project/schemas/__init__.py +0 -13
  200. snowflake/cli/api/project/schemas/entities/__init__.py +0 -13
  201. snowflake/cli/api/project/schemas/entities/common.py +0 -153
  202. snowflake/cli/api/project/schemas/entities/entities.py +0 -61
  203. snowflake/cli/api/project/schemas/project_definition.py +0 -330
  204. snowflake/cli/api/project/schemas/template.py +0 -77
  205. snowflake/cli/api/project/schemas/updatable_model.py +0 -202
  206. snowflake/cli/api/project/schemas/v1/__init__.py +0 -0
  207. snowflake/cli/api/project/schemas/v1/identifier_model.py +0 -51
  208. snowflake/cli/api/project/schemas/v1/native_app/__init__.py +0 -0
  209. snowflake/cli/api/project/schemas/v1/native_app/application.py +0 -61
  210. snowflake/cli/api/project/schemas/v1/native_app/native_app.py +0 -93
  211. snowflake/cli/api/project/schemas/v1/native_app/package.py +0 -84
  212. snowflake/cli/api/project/schemas/v1/native_app/path_mapping.py +0 -65
  213. snowflake/cli/api/project/schemas/v1/snowpark/__init__.py +0 -0
  214. snowflake/cli/api/project/schemas/v1/snowpark/argument.py +0 -28
  215. snowflake/cli/api/project/schemas/v1/snowpark/callable.py +0 -69
  216. snowflake/cli/api/project/schemas/v1/snowpark/snowpark.py +0 -36
  217. snowflake/cli/api/project/schemas/v1/streamlit/__init__.py +0 -0
  218. snowflake/cli/api/project/schemas/v1/streamlit/streamlit.py +0 -47
  219. snowflake/cli/api/project/util.py +0 -278
  220. snowflake/cli/api/rendering/__init__.py +0 -13
  221. snowflake/cli/api/rendering/jinja.py +0 -118
  222. snowflake/cli/api/rendering/project_definition_templates.py +0 -43
  223. snowflake/cli/api/rendering/project_templates.py +0 -98
  224. snowflake/cli/api/rendering/sql_templates.py +0 -105
  225. snowflake/cli/api/rest_api.py +0 -178
  226. snowflake/cli/api/sanitizers.py +0 -43
  227. snowflake/cli/api/secure_path.py +0 -360
  228. snowflake/cli/api/secure_utils.py +0 -118
  229. snowflake/cli/api/sql_execution.py +0 -280
  230. snowflake/cli/api/utils/__init__.py +0 -13
  231. snowflake/cli/api/utils/cursor.py +0 -34
  232. snowflake/cli/api/utils/definition_rendering.py +0 -415
  233. snowflake/cli/api/utils/dict_utils.py +0 -73
  234. snowflake/cli/api/utils/error_handling.py +0 -23
  235. snowflake/cli/api/utils/graph.py +0 -97
  236. snowflake/cli/api/utils/models.py +0 -63
  237. snowflake/cli/api/utils/naming_utils.py +0 -13
  238. snowflake/cli/api/utils/path_utils.py +0 -36
  239. snowflake/cli/api/utils/templating_functions.py +0 -144
  240. snowflake/cli/api/utils/types.py +0 -35
  241. snowflake_cli_labs-3.0.0rc5.dist-info/RECORD +0 -242
  242. snowflake_cli_labs-3.0.0rc5.dist-info/entry_points.txt +0 -2
  243. {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/WHEEL +0 -0
  244. {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/licenses/LICENSE +0 -0
@@ -1,249 +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 json
18
- import logging
19
- import os.path
20
- from pathlib import Path
21
- from typing import List, Optional
22
-
23
- import yaml
24
- from click import ClickException
25
- from snowflake.cli._plugins.nativeapp.artifacts import (
26
- BundleMap,
27
- find_manifest_file,
28
- find_setup_script_file,
29
- )
30
- from snowflake.cli._plugins.nativeapp.codegen.artifact_processor import (
31
- ArtifactProcessor,
32
- is_python_file_artifact,
33
- )
34
- from snowflake.cli._plugins.nativeapp.codegen.sandbox import (
35
- ExecutionEnvironmentType,
36
- SandboxEnvBuilder,
37
- execute_script_in_sandbox,
38
- )
39
- from snowflake.cli._plugins.stage.diff import to_stage_path
40
- from snowflake.cli.api.console import cli_console as cc
41
- from snowflake.cli.api.project.schemas.v1.native_app.path_mapping import (
42
- PathMapping,
43
- ProcessorMapping,
44
- )
45
-
46
- DEFAULT_TIMEOUT = 30
47
- DRIVER_PATH = Path(__file__).parent / "setup_driver.py.source"
48
-
49
- log = logging.getLogger(__name__)
50
-
51
-
52
- def safe_set(d: dict, *keys: str, **kwargs) -> None:
53
- """
54
- Sets a value in a nested dictionary structure, creating intermediate dictionaries as needed.
55
- Sample usage:
56
-
57
- d = {}
58
- safe_set(d, "a", "b", "c", value=42)
59
-
60
- d is now:
61
- {
62
- "a": {
63
- "b": {
64
- "c": 42
65
- }
66
- }
67
- }
68
- """
69
- curr = d
70
- for k in keys[:-1]:
71
- curr = curr.setdefault(k, {})
72
-
73
- curr[keys[-1]] = kwargs.get("value")
74
-
75
-
76
- class NativeAppSetupProcessor(ArtifactProcessor):
77
- def __init__(self, *args, **kwargs):
78
- super().__init__(*args, **kwargs)
79
-
80
- def process(
81
- self,
82
- artifact_to_process: PathMapping,
83
- processor_mapping: Optional[ProcessorMapping],
84
- **kwargs,
85
- ) -> None:
86
- """
87
- Processes a Python setup script and generates the corresponding SQL commands.
88
- """
89
- bundle_map = BundleMap(
90
- project_root=self._bundle_ctx.project_root,
91
- deploy_root=self._bundle_ctx.deploy_root,
92
- )
93
- bundle_map.add(artifact_to_process)
94
-
95
- self._create_or_update_sandbox()
96
-
97
- cc.step("Processing Python setup files")
98
-
99
- files_to_process = []
100
- for src_file, dest_file in bundle_map.all_mappings(
101
- absolute=True, expand_directories=True, predicate=is_python_file_artifact
102
- ):
103
- cc.message(
104
- f"Found Python setup file: {src_file.relative_to(self._bundle_ctx.project_root)}"
105
- )
106
- files_to_process.append(src_file)
107
-
108
- result = self._execute_in_sandbox(files_to_process)
109
- if not result:
110
- return # nothing to do
111
-
112
- logs = result.get("logs", [])
113
- for msg in logs:
114
- log.debug(msg)
115
-
116
- warnings = result.get("warnings", [])
117
- for msg in warnings:
118
- cc.warning(msg)
119
-
120
- schema_version = result.get("schema_version")
121
- if schema_version != "1":
122
- raise ClickException(
123
- f"Unsupported schema version returned from snowflake-app-python library: {schema_version}"
124
- )
125
-
126
- setup_script_mods = [
127
- mod
128
- for mod in result.get("modifications", [])
129
- if mod.get("target") == "native_app:setup_script"
130
- ]
131
- if setup_script_mods:
132
- self._edit_setup_sql(setup_script_mods)
133
-
134
- manifest_mods = [
135
- mod
136
- for mod in result.get("modifications", [])
137
- if mod.get("target") == "native_app:manifest"
138
- ]
139
- if manifest_mods:
140
- self._edit_manifest(manifest_mods)
141
-
142
- def _execute_in_sandbox(self, py_files: List[Path]) -> dict:
143
- file_count = len(py_files)
144
- cc.step(f"Processing {file_count} setup file{'s' if file_count > 1 else ''}")
145
-
146
- manifest_path = find_manifest_file(deploy_root=self._bundle_ctx.deploy_root)
147
-
148
- generated_root = self._bundle_ctx.generated_root
149
- generated_root.mkdir(exist_ok=True, parents=True)
150
-
151
- env_vars = {
152
- "_SNOWFLAKE_CLI_PROJECT_PATH": str(self._bundle_ctx.project_root),
153
- "_SNOWFLAKE_CLI_SETUP_FILES": os.pathsep.join(map(str, py_files)),
154
- "_SNOWFLAKE_CLI_APP_NAME": str(self._bundle_ctx.package_name),
155
- "_SNOWFLAKE_CLI_SQL_DEST_DIR": str(generated_root),
156
- "_SNOWFLAKE_CLI_MANIFEST_PATH": str(manifest_path),
157
- }
158
-
159
- try:
160
- result = execute_script_in_sandbox(
161
- script_source=DRIVER_PATH.read_text(),
162
- env_type=ExecutionEnvironmentType.VENV,
163
- cwd=self._bundle_ctx.bundle_root,
164
- timeout=DEFAULT_TIMEOUT,
165
- path=self.sandbox_root,
166
- env_vars=env_vars,
167
- )
168
- except Exception as e:
169
- raise ClickException(
170
- f"Exception while executing python setup script logic: {e}"
171
- )
172
-
173
- if result.returncode == 0:
174
- return json.loads(result.stdout)
175
- else:
176
- raise ClickException(
177
- f"Failed to execute python setup script logic: {result.stderr}"
178
- )
179
-
180
- def _edit_setup_sql(self, modifications: List[dict]) -> None:
181
- cc.step("Patching setup script")
182
- setup_file_path = find_setup_script_file(
183
- deploy_root=self._bundle_ctx.deploy_root
184
- )
185
-
186
- with self.edit_file(setup_file_path) as f:
187
- prepended = []
188
- appended = []
189
-
190
- for mod in modifications:
191
- for inst in mod.get("instructions", []):
192
- if inst.get("type") == "insert":
193
- default_loc = inst.get("default_location")
194
- if default_loc == "end":
195
- appended.append(self._setup_mod_instruction_to_sql(inst))
196
- elif default_loc == "start":
197
- prepended.append(self._setup_mod_instruction_to_sql(inst))
198
-
199
- if prepended or appended:
200
- f.edited_contents = "\n".join(prepended + [f.contents] + appended)
201
-
202
- def _edit_manifest(self, modifications: List[dict]) -> None:
203
- cc.step("Patching manifest")
204
- manifest_path = find_manifest_file(deploy_root=self._bundle_ctx.deploy_root)
205
-
206
- with self.edit_file(manifest_path) as f:
207
- manifest = yaml.safe_load(f.contents)
208
-
209
- for mod in modifications:
210
- for inst in mod.get("instructions", []):
211
- if inst.get("type") == "set":
212
- payload = inst.get("payload")
213
- if payload:
214
- key = payload.get("key")
215
- value = payload.get("value")
216
- safe_set(manifest, *key.split("."), value=value)
217
- f.edited_contents = yaml.safe_dump(manifest, sort_keys=False)
218
-
219
- def _setup_mod_instruction_to_sql(self, mod_inst: dict) -> str:
220
- payload = mod_inst.get("payload")
221
- if not payload:
222
- raise ClickException("Unsupported instruction received: no payload found")
223
-
224
- payload_type = payload.get("type")
225
- if payload_type == "execute immediate":
226
- file_path = payload.get("file_path")
227
- if file_path:
228
- sql_file_path = self._bundle_ctx.generated_root / file_path
229
- return f"EXECUTE IMMEDIATE FROM '/{to_stage_path(sql_file_path.relative_to(self._bundle_ctx.deploy_root))}';"
230
-
231
- raise ClickException(f"Unsupported instruction type received: {payload_type}")
232
-
233
- @property
234
- def sandbox_root(self):
235
- return self._bundle_ctx.bundle_root / "venv"
236
-
237
- def _create_or_update_sandbox(self):
238
- sandbox_root = self.sandbox_root
239
- env_builder = SandboxEnvBuilder(sandbox_root, with_pip=True)
240
- if sandbox_root.exists():
241
- cc.step("Virtual environment found")
242
- else:
243
- cc.step(
244
- f"Creating virtual environment in {sandbox_root.relative_to(self._bundle_ctx.project_root)}"
245
- )
246
- env_builder.ensure_created()
247
-
248
- # Temporarily fetch the library from a location specified via env vars
249
- env_builder.pip_install(os.environ["SNOWFLAKE_APP_PYTHON_LOC"])
@@ -1,59 +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
- import contextlib
16
- import os
17
- import sys
18
- from pathlib import Path
19
-
20
- import snowflake.app.context as ctx
21
- from snowflake.app.sql import SQLGenerator
22
-
23
- ctx.configure("project_path", os.environ.get("_SNOWFLAKE_CLI_PROJECT_PATH", None))
24
- ctx.configure("manifest_path", os.environ.get("_SNOWFLAKE_CLI_MANIFEST_PATH", None))
25
- ctx.configure("current_app_name", os.environ.get("_SNOWFLAKE_CLI_APP_NAME", None))
26
- ctx.configure("enable_sql_generation", True)
27
-
28
- __snowflake_internal_py_files = os.environ["_SNOWFLAKE_CLI_SETUP_FILES"].split(
29
- os.pathsep
30
- )
31
- __snowflake_internal_sql_dest_dir = os.environ["_SNOWFLAKE_CLI_SQL_DEST_DIR"]
32
-
33
- try:
34
- import importlib
35
-
36
- with contextlib.redirect_stdout(None):
37
- with contextlib.redirect_stderr(None):
38
- for __snowflake_internal_py_file in __snowflake_internal_py_files:
39
- __snowflake_internal_spec = importlib.util.spec_from_file_location(
40
- "<string>", __snowflake_internal_py_file
41
- )
42
- __snowflake_internal_module = importlib.util.module_from_spec(
43
- __snowflake_internal_spec
44
- )
45
- __snowflake_internal_spec.loader.exec_module(
46
- __snowflake_internal_module
47
- )
48
- except Exception as exc: # Catch any error
49
- print("An exception occurred while executing file: ", exc, file=sys.stderr)
50
- sys.exit(1)
51
-
52
-
53
- import json
54
-
55
- output_dir = Path(__snowflake_internal_sql_dest_dir)
56
- output_dir.mkdir(exist_ok=True, parents=True)
57
- path_mappings = SQLGenerator(dest_dir=output_dir).generate()
58
-
59
- print(json.dumps(path_mappings, default=str))
@@ -1,181 +0,0 @@
1
- import contextlib
2
- import functools
3
- import inspect
4
- import sys
5
- from typing import Callable, Tuple
6
-
7
- try:
8
- import snowflake.snowpark
9
- except ModuleNotFoundError as exc:
10
- print(
11
- "An exception occurred while importing snowflake-snowpark-python package: ",
12
- exc,
13
- file=sys.stderr,
14
- )
15
- sys.exit(1)
16
-
17
- __snowflake_internal_found_correct_version = hasattr(
18
- snowflake.snowpark.context, "_is_execution_environment_sandboxed_for_client"
19
- ) and hasattr(snowflake.snowpark.context, "_should_continue_registration")
20
-
21
- if not __snowflake_internal_found_correct_version:
22
- print(
23
- "Did not find the minimum required version for snowflake-snowpark-python package. Please upgrade to v1.15.0 or higher.",
24
- file=sys.stderr,
25
- )
26
- sys.exit(1)
27
-
28
- __snowflake_global_collected_extension_fn_json = []
29
-
30
- def __snowflake_internal_create_extension_fn_registration_callback():
31
- def __snowflake_internal_try_extract_lineno(extension_fn):
32
- try:
33
- return inspect.getsourcelines(extension_fn)[1]
34
- except Exception:
35
- return None
36
-
37
- def __snowflake_internal_extract_extension_fn_name(extension_fn):
38
- try:
39
- import snowflake.snowpark._internal.utils as snowpark_utils
40
-
41
- if hasattr(snowpark_utils, 'TEMP_OBJECT_NAME_PREFIX'):
42
- if extension_fn.object_name.startswith(snowpark_utils.TEMP_OBJECT_NAME_PREFIX):
43
- # The object name is a generated one, don't use it
44
- return None
45
-
46
- except Exception:
47
- # ignore any exception and fall back to using the object name reported from Snowpark
48
- pass
49
-
50
- return extension_fn.object_name
51
-
52
- def __snowflake_internal_create_package_list(extension_fn):
53
- if not extension_fn.all_packages.strip():
54
- return []
55
- return [pkg_spec.strip() for pkg_spec in extension_fn.all_packages.split(",")]
56
-
57
- def __snowflake_internal_make_extension_fn_signature(extension_fn):
58
- # Try to fetch the original argument names from the extension function
59
- try:
60
- args_spec = inspect.getfullargspec(extension_fn.func)
61
- original_arg_names = args_spec[0]
62
- start_index = len(original_arg_names) - len(extension_fn.input_sql_types)
63
- signature = []
64
- defaults_start_index = len(original_arg_names) - len(args_spec.defaults or [])
65
- for i in range(len(extension_fn.input_sql_types)):
66
- arg = {
67
- 'name': original_arg_names[start_index + i],
68
- 'type': extension_fn.input_sql_types[i]
69
- }
70
- if i >= defaults_start_index:
71
- arg['default'] = args_spec.defaults[defaults_start_index + i]
72
- signature.append(arg)
73
-
74
- return signature
75
- except Exception as e:
76
- msg = str(e)
77
- pass # ignore, we'll use the fallback strategy
78
-
79
- # Failed to extract the original arguments through reflection, fall back to alternative approach
80
- return [
81
- {"name": input_arg.name, "type": input_type}
82
- for (input_arg, input_type) in zip(extension_fn.input_args, extension_fn.input_sql_types)
83
- ]
84
-
85
- def __snowflake_internal_to_extension_fn_type(object_type):
86
- if object_type.name == "AGGREGATE_FUNCTION":
87
- return "aggregate function"
88
- if object_type.name == "TABLE_FUNCTION":
89
- return "table function"
90
- return object_type.name.lower()
91
-
92
- def __snowflake_internal_imports_union_to_str_type(raw_imports):
93
- final_imports = []
94
- if raw_imports:
95
- for raw_import in raw_imports:
96
- if isinstance(raw_import, str):
97
- final_imports.append(raw_import)
98
- else:
99
- final_imports.append(raw_import[0])
100
- return final_imports
101
-
102
-
103
- def __snowflake_internal_extension_fn_to_json(extension_fn):
104
- if not (isinstance(extension_fn.func, Callable) or isinstance(extension_fn.func, Tuple)):
105
- return
106
-
107
- if extension_fn.anonymous:
108
- # unsupported, native application extension functions need to be explicitly named
109
- return
110
-
111
- # Collect basic properties of the extension function
112
- extension_fn_json = {
113
- "type": __snowflake_internal_to_extension_fn_type(extension_fn.object_type),
114
- "lineno": __snowflake_internal_try_extract_lineno(extension_fn.func),
115
- "name": __snowflake_internal_extract_extension_fn_name(extension_fn),
116
- "handler": extension_fn.func.__name__,
117
- "imports": __snowflake_internal_imports_union_to_str_type(extension_fn.raw_imports),
118
- "packages": __snowflake_internal_create_package_list(extension_fn),
119
- "runtime": extension_fn.runtime_version,
120
- "returns": extension_fn.return_sql.upper().replace("RETURNS ", "").strip(),
121
- "signature": __snowflake_internal_make_extension_fn_signature(extension_fn),
122
- "external_access_integrations": extension_fn.external_access_integrations or [],
123
- "secrets": extension_fn.secrets or {},
124
- }
125
-
126
- if extension_fn.object_type.name == "PROCEDURE" and extension_fn.execute_as is not None:
127
- extension_fn_json['execute_as_caller'] = (extension_fn.execute_as == 'caller')
128
-
129
- if extension_fn.native_app_params is not None:
130
- schema = extension_fn.native_app_params.get("schema")
131
- if schema is not None:
132
- extension_fn_json["schema"] = schema
133
- app_roles = extension_fn.native_app_params.get("application_roles")
134
- if app_roles is not None:
135
- extension_fn_json["application_roles"] = app_roles
136
-
137
- return extension_fn_json
138
-
139
- def __snowflake_internal_collect_extension_fn(
140
- collected_extension_fn_json_list, extension_function_properties
141
- ):
142
- extension_fn_json = __snowflake_internal_extension_fn_to_json(extension_function_properties)
143
- if extension_fn_json: # Do not append if extension_fn_json is None
144
- collected_extension_fn_json_list.append(extension_fn_json)
145
- return False
146
-
147
- return functools.partial(
148
- __snowflake_internal_collect_extension_fn,
149
- __snowflake_global_collected_extension_fn_json,
150
- )
151
-
152
- snowflake.snowpark.context._is_execution_environment_sandboxed_for_client = ( # noqa: SLF001
153
- True
154
- )
155
- snowflake.snowpark.context._should_continue_registration = ( # noqa: SLF001
156
- __snowflake_internal_create_extension_fn_registration_callback()
157
- )
158
- snowflake.snowpark.session._is_execution_environment_sandboxed_for_client = ( # noqa: SLF001
159
- True
160
- )
161
-
162
- for global_key in list(globals().keys()):
163
- if global_key.startswith("__snowflake_internal"):
164
- del globals()[global_key]
165
-
166
- del globals()["global_key"] # make sure to clean up the loop variable as well
167
-
168
- try:
169
- import importlib
170
- with contextlib.redirect_stdout(None):
171
- with contextlib.redirect_stderr(None):
172
- __snowflake_internal_spec = importlib.util.spec_from_file_location("<string>", r"{{py_file}}")
173
- __snowflake_internal_module = importlib.util.module_from_spec(__snowflake_internal_spec)
174
- __snowflake_internal_spec.loader.exec_module(__snowflake_internal_module)
175
- except Exception as exc: # Catch any error
176
- print("An exception occurred while executing file: ", exc, file=sys.stderr)
177
- sys.exit(1)
178
-
179
-
180
- import json
181
- print(json.dumps(__snowflake_global_collected_extension_fn_json))