snowflake-cli-labs 3.0.0rc4__py3-none-any.whl → 3.0.1__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.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/METADATA +6 -96
  3. snowflake_cli_labs-3.0.1.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 -61
  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 -395
  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.0rc4.dist-info/RECORD +0 -242
  242. snowflake_cli_labs-3.0.0rc4.dist-info/entry_points.txt +0 -2
  243. {snowflake_cli_labs-3.0.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/WHEEL +0 -0
  244. {snowflake_cli_labs-3.0.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/licenses/LICENSE +0 -0
@@ -1,134 +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
- from contextlib import contextmanager
18
- from typing import Optional
19
-
20
- from rich.style import Style
21
- from rich.text import Text
22
- from snowflake.cli.api.console.abc import AbstractConsole
23
- from snowflake.cli.api.console.enum import Output
24
-
25
- PHASE_STYLE: Style = Style(bold=True)
26
- STEP_STYLE: Style = Style(italic=True)
27
- INFO_STYLE: Style = Style()
28
- IMPORTANT_STYLE: Style = Style(bold=True, italic=True)
29
- INDENTATION_LEVEL: int = 2
30
-
31
-
32
- class CliConsoleNestingProhibitedError(RuntimeError):
33
- """CliConsole phase nesting not allowed."""
34
-
35
-
36
- class CliConsole(AbstractConsole):
37
- """An utility for displaying intermediate output.
38
-
39
- Provides following methods for handling displaying messages:
40
- - `step` - for more detailed information on steps
41
- - `warning` - for displaying messages in a style that makes it
42
- visually stand out from other output
43
- - `phase` a context manager for organising steps into logical group
44
- """
45
-
46
- _indentation_level: int = INDENTATION_LEVEL
47
- _extra_indent: int = 0
48
- _styles: dict = {
49
- "default": "",
50
- Output.PHASE: PHASE_STYLE,
51
- Output.STEP: STEP_STYLE,
52
- Output.INFO: None,
53
- Output.IMPORTANT: IMPORTANT_STYLE,
54
- }
55
-
56
- def _format_message(self, message: str, output: Output) -> Text:
57
- """Wraps message in rich Text object and applies formatting."""
58
- style = self._styles.get(output, "default")
59
- if style is not None:
60
- text = Text(message, style=style)
61
- else:
62
- text = Text.from_markup(message)
63
-
64
- current_indent = self._extra_indent
65
- if self.in_phase and output in {Output.STEP, Output.INFO, Output.IMPORTANT}:
66
- current_indent += 1
67
- text.pad_left(current_indent * self._indentation_level)
68
- return text
69
-
70
- @contextmanager
71
- def phase(self, enter_message: str, exit_message: Optional[str] = None):
72
- """A context manager for organising steps into logical group."""
73
- if self.in_phase:
74
- raise CliConsoleNestingProhibitedError("Only one phase allowed at a time.")
75
- if self._extra_indent > 0:
76
- raise CliConsoleNestingProhibitedError(
77
- "Phase cannot be used in an indented block."
78
- )
79
-
80
- self._print(self._format_message(enter_message, Output.PHASE))
81
- self._in_phase = True
82
-
83
- try:
84
- yield self.step
85
- finally:
86
- self._in_phase = False
87
- if exit_message:
88
- self._print(self._format_message(exit_message, Output.PHASE))
89
-
90
- @contextmanager
91
- def indented(self):
92
- """
93
- A context manager for temporarily indenting messages and warnings. Phases and steps cannot be used in indented blocks,
94
- but multiple indented blocks can be nested (use sparingly).
95
- """
96
- self._extra_indent += 1
97
- try:
98
- yield
99
- finally:
100
- self._extra_indent -= 1
101
-
102
- def step(self, message: str):
103
- """Displays a message to output.
104
-
105
- If called within a phase, the output will be indented.
106
- """
107
- if self._extra_indent > 0:
108
- raise CliConsoleNestingProhibitedError(
109
- "Step cannot be used in an indented block."
110
- )
111
- text = self._format_message(message, Output.STEP)
112
- self._print(text)
113
-
114
- def message(self, _message: str):
115
- """Displays an informational message to output.
116
-
117
- If called within a phase, the output will be indented."""
118
- text = self._format_message(_message, Output.INFO)
119
- self._print(text)
120
-
121
- def warning(self, message: str):
122
- """Displays message in a style that makes it visually stand out from other output.
123
-
124
- This should be used to display important messages to the console."""
125
- text = self._format_message(message, Output.IMPORTANT)
126
- self._print(text)
127
-
128
-
129
- def get_cli_console() -> AbstractConsole:
130
- console = CliConsole()
131
- return console
132
-
133
-
134
- cli_console = get_cli_console()
@@ -1,17 +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 enum import Enum
16
-
17
- Output = Enum("Output", ("PHASE", "STEP", "INFO", "IMPORTANT"))
@@ -1,90 +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
- from dataclasses import dataclass
18
- from enum import Enum
19
- from pathlib import Path
20
-
21
- TEMPLATES_PATH = Path(__file__).parent.parent / "templates"
22
- DEPLOYMENT_STAGE = "deployments"
23
- PYTHON_3_12 = (3, 12)
24
-
25
-
26
- @dataclass(frozen=True)
27
- class ObjectNames:
28
- cli_name: str
29
- sf_name: str
30
- sf_plural_name: str
31
-
32
- def __str__(self):
33
- return self.sf_name
34
-
35
-
36
- class ObjectType(Enum):
37
- COMPUTE_POOL = ObjectNames("compute-pool", "compute pool", "compute pools")
38
- DATABASE = ObjectNames("database", "database", "databases")
39
- FUNCTION = ObjectNames("function", "function", "functions")
40
- INTEGRATION = ObjectNames("integration", "integration", "integrations")
41
- EXTERNAL_ACCESS_INTEGRATION = ObjectNames(
42
- "external-access-integration",
43
- "external access integration",
44
- "external access integrations",
45
- )
46
- # JOB = ObjectNames("job", "job", "jobs")
47
- NETWORK_RULE = ObjectNames("network-rule", "network rule", "network rules")
48
- PROCEDURE = ObjectNames("procedure", "procedure", "procedures")
49
- ROLE = ObjectNames("role", "role", "roles")
50
- SCHEMA = ObjectNames("schema", "schema", "schemas")
51
- SERVICE = ObjectNames("service", "service", "services")
52
- SECRET = ObjectNames("secret", "secret", "secrets")
53
- STAGE = ObjectNames("stage", "stage", "stages")
54
- STREAM = ObjectNames("stream", "stream", "streams")
55
- STREAMLIT = ObjectNames("streamlit", "streamlit", "streamlits")
56
- TABLE = ObjectNames("table", "table", "tables")
57
- TASK = ObjectNames("task", "task", "tasks")
58
- USER = ObjectNames("user", "user", "users")
59
- WAREHOUSE = ObjectNames("warehouse", "warehouse", "warehouses")
60
- VIEW = ObjectNames("view", "view", "views")
61
- IMAGE_REPOSITORY = ObjectNames(
62
- "image-repository", "image repository", "image repositories"
63
- )
64
- GIT_REPOSITORY = ObjectNames("git-repository", "git repository", "git repositories")
65
-
66
- def __str__(self):
67
- """This makes using this Enum easier in formatted string"""
68
- return self.value.cli_name
69
-
70
-
71
- OBJECT_TO_NAMES = {o.value.cli_name: o.value for o in ObjectType}
72
- SUPPORTED_OBJECTS = sorted(OBJECT_TO_NAMES.keys())
73
-
74
- # Scope names here must replace spaces with '-'. For example 'compute pool' is 'compute-pool'.
75
- VALID_SCOPES = ["database", "schema", "compute-pool"]
76
-
77
- DEFAULT_SIZE_LIMIT_MB = 128
78
-
79
- SF_REST_API_URL_PREFIX = "/api/v2"
80
-
81
- PROJECT_TEMPLATE_VARIABLE_OPENING = "<%"
82
- PROJECT_TEMPLATE_VARIABLE_CLOSING = "%>"
83
-
84
- INIT_TEMPLATE_VARIABLE_OPENING = "<!"
85
- INIT_TEMPLATE_VARIABLE_CLOSING = "!>"
86
-
87
- SNOWPARK_SHARED_MIXIN = "snowpark_shared"
88
-
89
- DEFAULT_ENV_FILE = "environment.yml"
90
- DEFAULT_PAGES_DIR = "pages"
@@ -1,56 +0,0 @@
1
- from enum import Enum
2
- from typing import Generic, Type, TypeVar, get_args
3
-
4
- from snowflake.cli._plugins.workspace.action_context import ActionContext
5
- from snowflake.cli.api.sql_execution import SqlExecutor
6
-
7
-
8
- class EntityActions(str, Enum):
9
- BUNDLE = "action_bundle"
10
- DEPLOY = "action_deploy"
11
- DROP = "action_drop"
12
- VALIDATE = "action_validate"
13
-
14
- VERSION_LIST = "action_version_list"
15
- VERSION_CREATE = "action_version_create"
16
- VERSION_DROP = "action_version_drop"
17
-
18
-
19
- T = TypeVar("T")
20
-
21
-
22
- class EntityBase(Generic[T]):
23
- """
24
- Base class for the fully-featured entity classes.
25
- """
26
-
27
- def __init__(self, entity_model: T):
28
- self._entity_model = entity_model
29
-
30
- @classmethod
31
- def get_entity_model_type(cls) -> Type[T]:
32
- """
33
- Returns the generic model class specified in each entity class.
34
-
35
- For example, calling ApplicationEntity.get_entity_model_type() will return the ApplicationEntityModel class.
36
- """
37
- return get_args(cls.__orig_bases__[0])[0] # type: ignore[attr-defined]
38
-
39
- def supports(self, action: EntityActions) -> bool:
40
- """
41
- Checks whether this entity supports the given action. An entity is considered to support an action if it implements a method with the action name.
42
- """
43
- return callable(getattr(self, action, None))
44
-
45
- def perform(
46
- self, action: EntityActions, action_ctx: ActionContext, *args, **kwargs
47
- ):
48
- """
49
- Performs the requested action.
50
- """
51
- return getattr(self, action)(action_ctx, *args, **kwargs)
52
-
53
-
54
- def get_sql_executor() -> SqlExecutor:
55
- """Returns an SQL Executor that uses the connection from the current CLI context"""
56
- return SqlExecutor()
@@ -1,370 +0,0 @@
1
- import os
2
- from pathlib import Path
3
- from textwrap import dedent
4
- from typing import Any, List, NoReturn, Optional
5
-
6
- import jinja2
7
- from click import ClickException
8
- from snowflake.cli._plugins.nativeapp.artifacts import (
9
- BundleMap,
10
- resolve_without_follow,
11
- )
12
- from snowflake.cli._plugins.nativeapp.exceptions import (
13
- InvalidTemplateInFileError,
14
- MissingScriptError,
15
- )
16
- from snowflake.cli._plugins.nativeapp.utils import verify_exists, verify_no_directories
17
- from snowflake.cli._plugins.stage.diff import (
18
- DiffResult,
19
- StagePath,
20
- compute_stage_diff,
21
- preserve_from_diff,
22
- sync_local_diff_with_stage,
23
- to_stage_path,
24
- )
25
- from snowflake.cli._plugins.stage.utils import print_diff_to_console
26
- from snowflake.cli.api.cli_global_context import get_cli_context
27
- from snowflake.cli.api.console.abc import AbstractConsole
28
- from snowflake.cli.api.entities.common import get_sql_executor
29
- from snowflake.cli.api.errno import (
30
- DOES_NOT_EXIST_OR_CANNOT_BE_PERFORMED,
31
- NO_WAREHOUSE_SELECTED_IN_SESSION,
32
- )
33
- from snowflake.cli.api.exceptions import SnowflakeSQLExecutionError
34
- from snowflake.cli.api.metrics import CLICounterField
35
- from snowflake.cli.api.project.schemas.entities.common import PostDeployHook
36
- from snowflake.cli.api.rendering.sql_templates import (
37
- choose_sql_jinja_env_based_on_template_syntax,
38
- )
39
- from snowflake.cli.api.secure_path import UNLIMITED, SecurePath
40
- from snowflake.connector import ProgrammingError
41
- from snowflake.connector.cursor import SnowflakeCursor
42
-
43
-
44
- def generic_sql_error_handler(
45
- err: ProgrammingError, role: Optional[str] = None, warehouse: Optional[str] = None
46
- ) -> NoReturn:
47
- # Potential refactor: If moving away from Python 3.8 and 3.9 to >= 3.10, use match ... case
48
- if err.errno == DOES_NOT_EXIST_OR_CANNOT_BE_PERFORMED:
49
- raise ProgrammingError(
50
- msg=dedent(
51
- f"""\
52
- Received error message '{err.msg}' while executing SQL statement.
53
- '{role}' may not have access to warehouse '{warehouse}'.
54
- Please grant usage privilege on warehouse to this role.
55
- """
56
- ),
57
- errno=err.errno,
58
- )
59
- elif err.errno == NO_WAREHOUSE_SELECTED_IN_SESSION:
60
- raise ProgrammingError(
61
- msg=dedent(
62
- f"""\
63
- Received error message '{err.msg}' while executing SQL statement.
64
- Please provide a warehouse for the active session role in your project definition file, config.toml file, or via command line.
65
- """
66
- ),
67
- errno=err.errno,
68
- )
69
- elif "does not exist or not authorized" in err.msg:
70
- raise ProgrammingError(
71
- msg=dedent(
72
- f"""\
73
- Received error message '{err.msg}' while executing SQL statement.
74
- Please check the name of the resource you are trying to query or the permissions of the role you are using to run the query.
75
- """
76
- )
77
- )
78
- raise err
79
-
80
-
81
- def _get_stage_paths_to_sync(
82
- local_paths_to_sync: List[Path], deploy_root: Path
83
- ) -> List[StagePath]:
84
- """
85
- Takes a list of paths (files and directories), returning a list of all files recursively relative to the deploy root.
86
- """
87
-
88
- stage_paths = []
89
- for path in local_paths_to_sync:
90
- if path.is_dir():
91
- for current_dir, _dirs, files in os.walk(path):
92
- for file in files:
93
- deploy_path = Path(current_dir, file).relative_to(deploy_root)
94
- stage_paths.append(to_stage_path(deploy_path))
95
- else:
96
- stage_paths.append(to_stage_path(path.relative_to(deploy_root)))
97
- return stage_paths
98
-
99
-
100
- def sync_deploy_root_with_stage(
101
- console: AbstractConsole,
102
- deploy_root: Path,
103
- package_name: str,
104
- stage_schema: str,
105
- bundle_map: BundleMap,
106
- role: str,
107
- prune: bool,
108
- recursive: bool,
109
- stage_fqn: str,
110
- local_paths_to_sync: List[Path] | None = None,
111
- print_diff: bool = True,
112
- ) -> DiffResult:
113
- """
114
- Ensures that the files on our remote stage match the artifacts we have in
115
- the local filesystem.
116
-
117
- Args:
118
- bundle_map (BundleMap): The artifact mapping computed by the `build_bundle` function.
119
- role (str): The name of the role to use for queries and commands.
120
- prune (bool): Whether to prune artifacts from the stage that don't exist locally.
121
- recursive (bool): Whether to traverse directories recursively.
122
- stage_fqn (str): The name of the stage to diff against and upload to.
123
- local_paths_to_sync (List[Path], optional): List of local paths to sync. Defaults to None to sync all
124
- local paths. Note that providing an empty list here is equivalent to None.
125
- print_diff (bool): Whether to print the diff between the local files and the remote stage. Defaults to True
126
-
127
- Returns:
128
- A `DiffResult` instance describing the changes that were performed.
129
- """
130
-
131
- sql_executor = get_sql_executor()
132
- # Does a stage already exist within the application package, or we need to create one?
133
- # Using "if not exists" should take care of either case.
134
- console.step(
135
- f"Checking if stage {stage_fqn} exists, or creating a new one if none exists."
136
- )
137
- with sql_executor.use_role(role):
138
- sql_executor.execute_query(
139
- f"create schema if not exists {package_name}.{stage_schema}"
140
- )
141
- sql_executor.execute_query(
142
- f"""
143
- create stage if not exists {stage_fqn}
144
- encryption = (TYPE = 'SNOWFLAKE_SSE')
145
- DIRECTORY = (ENABLE = TRUE)"""
146
- )
147
-
148
- # Perform a diff operation and display results to the user for informational purposes
149
- if print_diff:
150
- console.step(
151
- "Performing a diff between the Snowflake stage and your local deploy_root ('%s') directory."
152
- % deploy_root.resolve()
153
- )
154
- diff: DiffResult = compute_stage_diff(deploy_root, stage_fqn)
155
-
156
- if local_paths_to_sync:
157
- # Deploying specific files/directories
158
- resolved_paths_to_sync = [
159
- resolve_without_follow(p) for p in local_paths_to_sync
160
- ]
161
- if not recursive:
162
- verify_no_directories(resolved_paths_to_sync)
163
-
164
- deploy_paths_to_sync = []
165
- for resolved_path in resolved_paths_to_sync:
166
- verify_exists(resolved_path)
167
- deploy_paths = bundle_map.to_deploy_paths(resolved_path)
168
- if not deploy_paths:
169
- if resolved_path.is_dir() and recursive:
170
- # No direct artifact mapping found for this path. Check to see
171
- # if there are subpaths of this directory that are matches. We
172
- # loop over sources because it's likely a much smaller list
173
- # than the project directory.
174
- for src in bundle_map.all_sources(absolute=True):
175
- if resolved_path in src.parents:
176
- # There is a source that contains this path, get its dest path(s)
177
- deploy_paths.extend(bundle_map.to_deploy_paths(src))
178
-
179
- if not deploy_paths:
180
- raise ClickException(f"No artifact found for {resolved_path}")
181
- deploy_paths_to_sync.extend(deploy_paths)
182
-
183
- stage_paths_to_sync = _get_stage_paths_to_sync(
184
- deploy_paths_to_sync, resolve_without_follow(deploy_root)
185
- )
186
- diff = preserve_from_diff(diff, stage_paths_to_sync)
187
- else:
188
- # Full deploy
189
- if not recursive:
190
- verify_no_directories(deploy_root.resolve().iterdir())
191
-
192
- if not prune:
193
- files_not_removed = [str(path) for path in diff.only_on_stage]
194
- diff.only_on_stage = []
195
-
196
- if len(files_not_removed) > 0:
197
- files_not_removed_str = "\n".join(files_not_removed)
198
- console.warning(
199
- f"The following files exist only on the stage:\n{files_not_removed_str}\n\nUse the --prune flag to delete them from the stage."
200
- )
201
-
202
- if print_diff:
203
- print_diff_to_console(diff, bundle_map)
204
-
205
- # Upload diff-ed files to application package stage
206
- if diff.has_changes():
207
- console.step(
208
- "Updating the Snowflake stage from your local %s directory."
209
- % deploy_root.resolve(),
210
- )
211
- sync_local_diff_with_stage(
212
- role=role,
213
- deploy_root_path=deploy_root,
214
- diff_result=diff,
215
- stage_fqn=stage_fqn,
216
- )
217
- return diff
218
-
219
-
220
- def _execute_sql_script(
221
- script_content: str,
222
- database_name: Optional[str] = None,
223
- ) -> None:
224
- """
225
- Executing the provided SQL script content.
226
- This assumes that a relevant warehouse is already active.
227
- If database_name is passed in, it will be used first.
228
- """
229
- try:
230
- sql_executor = get_sql_executor()
231
- if database_name is not None:
232
- sql_executor.execute_query(f"use database {database_name}")
233
- sql_executor.execute_queries(script_content)
234
- except ProgrammingError as err:
235
- generic_sql_error_handler(err)
236
-
237
-
238
- def execute_post_deploy_hooks(
239
- console: AbstractConsole,
240
- project_root: Path,
241
- post_deploy_hooks: Optional[List[PostDeployHook]],
242
- deployed_object_type: str,
243
- database_name: str,
244
- ) -> None:
245
- """
246
- Executes post-deploy hooks for the given object type.
247
- While executing SQL post deploy hooks, it first switches to the database provided in the input.
248
- All post deploy scripts templates will first be expanded using the global template context.
249
- """
250
- if not post_deploy_hooks:
251
- return
252
-
253
- get_cli_context().metrics.set_counter(CLICounterField.POST_DEPLOY_SCRIPTS, 1)
254
-
255
- with console.phase(f"Executing {deployed_object_type} post-deploy actions"):
256
- sql_scripts_paths = []
257
- for hook in post_deploy_hooks:
258
- if hook.sql_script:
259
- sql_scripts_paths.append(hook.sql_script)
260
- else:
261
- raise ValueError(
262
- f"Unsupported {deployed_object_type} post-deploy hook type: {hook}"
263
- )
264
-
265
- scripts_content_list = render_script_templates(
266
- project_root,
267
- get_cli_context().template_context,
268
- sql_scripts_paths,
269
- )
270
-
271
- for index, sql_script_path in enumerate(sql_scripts_paths):
272
- console.step(f"Executing SQL script: {sql_script_path}")
273
- _execute_sql_script(
274
- script_content=scripts_content_list[index],
275
- database_name=database_name,
276
- )
277
-
278
-
279
- def render_script_templates(
280
- project_root: Path,
281
- jinja_context: dict[str, Any],
282
- scripts: List[str],
283
- override_env: Optional[jinja2.Environment] = None,
284
- ) -> List[str]:
285
- """
286
- Input:
287
- - project_root: path to project root
288
- - jinja_context: a dictionary with the jinja context
289
- - scripts: list of script paths relative to the project root
290
- - override_env: optional jinja environment to use for rendering,
291
- if not provided, the environment will be chosen based on the template syntax
292
- Returns:
293
- - List of rendered scripts content
294
- Size of the return list is the same as the size of the input scripts list.
295
- """
296
- return [
297
- render_script_template(project_root, jinja_context, script, override_env)
298
- for script in scripts
299
- ]
300
-
301
-
302
- def render_script_template(
303
- project_root: Path,
304
- jinja_context: dict[str, Any],
305
- script: str,
306
- override_env: Optional[jinja2.Environment] = None,
307
- ) -> str:
308
- script_full_path = SecurePath(project_root) / script
309
- try:
310
- template_content = script_full_path.read_text(file_size_limit_mb=UNLIMITED)
311
- env = override_env or choose_sql_jinja_env_based_on_template_syntax(
312
- template_content, reference_name=script
313
- )
314
- return env.from_string(template_content).render(jinja_context)
315
-
316
- except FileNotFoundError as e:
317
- raise MissingScriptError(script) from e
318
-
319
- except jinja2.TemplateSyntaxError as e:
320
- raise InvalidTemplateInFileError(script, e, e.lineno) from e
321
-
322
- except jinja2.UndefinedError as e:
323
- raise InvalidTemplateInFileError(script, e) from e
324
-
325
-
326
- def validation_item_to_str(item: dict[str, str | int]):
327
- s = item["message"]
328
- if item["errorCode"]:
329
- s = f"{s} (error code {item['errorCode']})"
330
- return s
331
-
332
-
333
- def drop_generic_object(
334
- console: AbstractConsole,
335
- object_type: str,
336
- object_name: str,
337
- role: str,
338
- cascade: bool = False,
339
- ):
340
- """
341
- Drop object using the given role.
342
- """
343
- sql_executor = get_sql_executor()
344
- with sql_executor.use_role(role):
345
- console.step(f"Dropping {object_type} {object_name} now.")
346
- drop_query = f"drop {object_type} {object_name}"
347
- if cascade:
348
- drop_query += " cascade"
349
- try:
350
- sql_executor.execute_query(drop_query)
351
- except:
352
- raise SnowflakeSQLExecutionError(drop_query)
353
-
354
- console.message(f"Dropped {object_type} {object_name} successfully.")
355
-
356
-
357
- def print_messages(
358
- console: AbstractConsole, create_or_upgrade_cursor: Optional[SnowflakeCursor]
359
- ):
360
- """
361
- Shows messages in the console returned by the CREATE or UPGRADE
362
- APPLICATION command.
363
- """
364
- if not create_or_upgrade_cursor:
365
- return
366
-
367
- messages = [row[0] for row in create_or_upgrade_cursor.fetchall()]
368
- for message in messages:
369
- console.warning(message)
370
- console.message("")
@@ -1,28 +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
- # General errors
16
- NO_WAREHOUSE_SELECTED_IN_SESSION = 606
17
-
18
- DOES_NOT_EXIST_OR_NOT_AUTHORIZED = 2003
19
- DOES_NOT_EXIST_OR_CANNOT_BE_PERFORMED = 2043
20
- INSUFFICIENT_PRIVILEGES = 3001
21
-
22
- # Native Apps
23
- CANNOT_UPGRADE_FROM_LOOSE_FILES_TO_VERSION = 93044
24
- CANNOT_UPGRADE_FROM_VERSION_TO_LOOSE_FILES = 93045
25
- ONLY_SUPPORTED_ON_DEV_MODE_APPLICATIONS = 93046
26
- NOT_SUPPORTED_ON_DEV_MODE_APPLICATIONS = 93055
27
- APPLICATION_NO_LONGER_AVAILABLE = 93079
28
- APPLICATION_OWNS_EXTERNAL_OBJECTS = 93128