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,170 +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 typing import Optional
19
-
20
- import typer
21
- from click import MissingParameter
22
- from snowflake.cli.api.cli_global_context import cli_context
23
- from snowflake.cli.api.commands.decorators import (
24
- with_project_definition,
25
- )
26
- from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
27
- from snowflake.cli.api.output.types import CommandResult, MessageResult, QueryResult
28
- from snowflake.cli.api.project.project_verification import assert_project_type
29
- from snowflake.cli.plugins.nativeapp.common_flags import ForceOption, InteractiveOption
30
- from snowflake.cli.plugins.nativeapp.policy import (
31
- AllowAlwaysPolicy,
32
- AskAlwaysPolicy,
33
- DenyAlwaysPolicy,
34
- )
35
- from snowflake.cli.plugins.nativeapp.run_processor import NativeAppRunProcessor
36
- from snowflake.cli.plugins.nativeapp.v2_conversions.v2_to_v1_decorator import (
37
- nativeapp_definition_v2_to_v1,
38
- )
39
- from snowflake.cli.plugins.nativeapp.version.version_processor import (
40
- NativeAppVersionCreateProcessor,
41
- NativeAppVersionDropProcessor,
42
- )
43
-
44
- app = SnowTyperFactory(
45
- name="version",
46
- help="Manages versions defined in an application package",
47
- )
48
-
49
- log = logging.getLogger(__name__)
50
-
51
-
52
- @app.command(requires_connection=True)
53
- @with_project_definition()
54
- @nativeapp_definition_v2_to_v1
55
- def create(
56
- version: Optional[str] = typer.Argument(
57
- None,
58
- help=f"""Version to define in your application package. If the version already exists, an auto-incremented patch is added to the version instead. Defaults to the version specified in the `manifest.yml` file.""",
59
- ),
60
- patch: Optional[int] = typer.Option(
61
- None,
62
- "--patch",
63
- help=f"""The patch number you want to create for an existing version.
64
- Defaults to undefined if it is not set, which means the Snowflake CLI either uses the patch specified in the `manifest.yml` file or automatically generates a new patch number.""",
65
- ),
66
- skip_git_check: Optional[bool] = typer.Option(
67
- False,
68
- "--skip-git-check",
69
- help="When enabled, the Snowflake CLI skips checking if your project has any untracked or stages files in git. Default: unset.",
70
- is_flag=True,
71
- ),
72
- interactive: bool = InteractiveOption,
73
- force: Optional[bool] = ForceOption,
74
- **options,
75
- ) -> CommandResult:
76
- """
77
- Adds a new patch to the provided version defined in your application package. If the version does not exist, creates a version with patch 0.
78
- """
79
-
80
- assert_project_type("native_app")
81
-
82
- if version is None and patch is not None:
83
- raise MissingParameter("Cannot provide a patch without version!")
84
-
85
- is_interactive = False
86
- if force:
87
- policy = AllowAlwaysPolicy()
88
- elif interactive:
89
- is_interactive = True
90
- policy = AskAlwaysPolicy()
91
- else:
92
- policy = DenyAlwaysPolicy()
93
-
94
- if skip_git_check:
95
- git_policy = DenyAlwaysPolicy()
96
- else:
97
- git_policy = AllowAlwaysPolicy()
98
-
99
- processor = NativeAppVersionCreateProcessor(
100
- project_definition=cli_context.project_definition.native_app,
101
- project_root=cli_context.project_root,
102
- )
103
-
104
- # We need build_bundle() to (optionally) find version in manifest.yml and create an application package
105
- bundle_map = processor.build_bundle()
106
- processor.process(
107
- bundle_map=bundle_map,
108
- version=version,
109
- patch=patch,
110
- policy=policy,
111
- git_policy=git_policy,
112
- is_interactive=is_interactive,
113
- )
114
- return MessageResult(f"Version create is now complete.")
115
-
116
-
117
- @app.command("list", requires_connection=True)
118
- @with_project_definition()
119
- @nativeapp_definition_v2_to_v1
120
- def version_list(
121
- **options,
122
- ) -> CommandResult:
123
- """
124
- Lists all versions defined in an application package.
125
- """
126
-
127
- assert_project_type("native_app")
128
-
129
- processor = NativeAppRunProcessor(
130
- project_definition=cli_context.project_definition.native_app,
131
- project_root=cli_context.project_root,
132
- )
133
- cursor = processor.get_all_existing_versions()
134
- return QueryResult(cursor)
135
-
136
-
137
- @app.command(requires_connection=True)
138
- @with_project_definition()
139
- @nativeapp_definition_v2_to_v1
140
- def drop(
141
- version: Optional[str] = typer.Argument(
142
- None,
143
- help="Version defined in an application package that you want to drop. Defaults to the version specified in the `manifest.yml` file.",
144
- ),
145
- interactive: bool = InteractiveOption,
146
- force: Optional[bool] = ForceOption,
147
- **options,
148
- ) -> CommandResult:
149
- """
150
- Drops a version defined in your application package. Versions can either be passed in as an argument to the command or read from the `manifest.yml` file.
151
- Dropping patches is not allowed.
152
- """
153
-
154
- assert_project_type("native_app")
155
-
156
- is_interactive = False
157
- if force:
158
- policy = AllowAlwaysPolicy()
159
- elif interactive:
160
- is_interactive = True
161
- policy = AskAlwaysPolicy()
162
- else:
163
- policy = DenyAlwaysPolicy()
164
-
165
- processor = NativeAppVersionDropProcessor(
166
- project_definition=cli_context.project_definition.native_app,
167
- project_root=cli_context.project_root,
168
- )
169
- processor.process(version, policy, is_interactive)
170
- return MessageResult(f"Version drop is now complete.")
@@ -1,362 +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 pathlib import Path
18
- from textwrap import dedent
19
- from typing import Dict, List, Optional
20
-
21
- import typer
22
- from click import BadOptionUsage, ClickException
23
- from snowflake.cli.api.console import cli_console as cc
24
- from snowflake.cli.api.exceptions import SnowflakeSQLExecutionError
25
- from snowflake.cli.api.project.schemas.native_app.native_app import NativeApp
26
- from snowflake.cli.api.project.util import unquote_identifier
27
- from snowflake.cli.api.utils.cursor import (
28
- find_all_rows,
29
- find_first_row,
30
- )
31
- from snowflake.cli.plugins.nativeapp.artifacts import (
32
- BundleMap,
33
- find_version_info_in_manifest_file,
34
- )
35
- from snowflake.cli.plugins.nativeapp.constants import VERSION_COL
36
- from snowflake.cli.plugins.nativeapp.exceptions import (
37
- ApplicationPackageAlreadyExistsError,
38
- ApplicationPackageDoesNotExistError,
39
- )
40
- from snowflake.cli.plugins.nativeapp.manager import (
41
- NativeAppCommandProcessor,
42
- NativeAppManager,
43
- ensure_correct_owner,
44
- )
45
- from snowflake.cli.plugins.nativeapp.policy import PolicyBase
46
- from snowflake.cli.plugins.nativeapp.run_processor import NativeAppRunProcessor
47
- from snowflake.connector import ProgrammingError
48
- from snowflake.connector.cursor import DictCursor
49
-
50
-
51
- def check_index_changes_in_git_repo(
52
- project_root: Path, policy: PolicyBase, is_interactive: bool
53
- ) -> None:
54
- """
55
- Checks if the project root, i.e. the native apps project is a git repository. If it is a git repository,
56
- it also checks if there any local changes to the directory that may not be on the application package stage.
57
- """
58
- from git import Repo
59
- from git.exc import InvalidGitRepositoryError
60
-
61
- try:
62
- repo = Repo(project_root, search_parent_directories=True)
63
- assert repo.git_dir is not None
64
-
65
- # Check if the repo has any changes, including untracked files
66
- if repo.is_dirty(untracked_files=True):
67
- cc.warning(
68
- "Changes detected in the git repository. "
69
- "(Rerun your command with --skip-git-check flag to ignore this check)"
70
- )
71
- repo.git.execute(["git", "status"])
72
-
73
- user_prompt = (
74
- "You have local changes in this repository that are not part of a previous commit. "
75
- "Do you still want to continue?"
76
- )
77
- if not policy.should_proceed(user_prompt):
78
- if is_interactive:
79
- cc.message("Not creating a new version.")
80
- raise typer.Exit(0)
81
- else:
82
- cc.message(
83
- "Cannot create a new version non-interactively without --force."
84
- )
85
- raise typer.Exit(1)
86
-
87
- except InvalidGitRepositoryError:
88
- pass # not a git repository, which is acceptable
89
-
90
-
91
- class NativeAppVersionCreateProcessor(NativeAppRunProcessor):
92
- def __init__(self, project_definition: Dict, project_root: Path):
93
- super().__init__(project_definition, project_root)
94
-
95
- def get_existing_release_directive_info_for_version(
96
- self, version: str
97
- ) -> List[dict]:
98
- """
99
- Get all existing release directives, if present, set on the version defined in an application package.
100
- It executes a 'show release directives in application package' query and returns the filtered results, if they exist.
101
- """
102
- with self.use_role(self.package_role):
103
- show_obj_query = (
104
- f"show release directives in application package {self.package_name}"
105
- )
106
- show_obj_cursor = self._execute_query(
107
- show_obj_query, cursor_class=DictCursor
108
- )
109
-
110
- if show_obj_cursor.rowcount is None:
111
- raise SnowflakeSQLExecutionError(show_obj_query)
112
-
113
- show_obj_rows = find_all_rows(
114
- show_obj_cursor,
115
- lambda row: row[VERSION_COL] == unquote_identifier(version),
116
- )
117
-
118
- return show_obj_rows
119
-
120
- def add_new_version(self, version: str) -> None:
121
- """
122
- Defines a new version in an existing application package.
123
- """
124
- with self.use_role(self.package_role):
125
- cc.step(
126
- f"Defining a new version {version} in application package {self.package_name}"
127
- )
128
- add_version_query = dedent(
129
- f"""\
130
- alter application package {self.package_name}
131
- add version {version}
132
- using @{self.stage_fqn}
133
- """
134
- )
135
- self._execute_query(add_version_query, cursor_class=DictCursor)
136
- cc.message(
137
- f"Version {version} created for application package {self.package_name}."
138
- )
139
-
140
- def add_new_patch_to_version(self, version: str, patch: Optional[int] = None):
141
- """
142
- Add a new patch, optionally a custom one, to an existing version in an application package.
143
- """
144
- with self.use_role(self.package_role):
145
- cc.step(
146
- f"Adding new patch to version {version} defined in application package {self.package_name}"
147
- )
148
- add_version_query = dedent(
149
- f"""\
150
- alter application package {self.package_name}
151
- add patch {patch if patch else ""} for version {version}
152
- using @{self.stage_fqn}
153
- """
154
- )
155
- result_cursor = self._execute_query(
156
- add_version_query, cursor_class=DictCursor
157
- )
158
-
159
- show_row = find_first_row(
160
- result_cursor,
161
- lambda row: row[VERSION_COL] == unquote_identifier(version),
162
- )
163
-
164
- new_patch = show_row["patch"]
165
- cc.message(
166
- f"Patch {new_patch} created for version {version} defined in application package {self.package_name}."
167
- )
168
-
169
- def process(
170
- self,
171
- bundle_map: BundleMap,
172
- version: Optional[str],
173
- patch: Optional[int],
174
- policy: PolicyBase,
175
- git_policy: PolicyBase,
176
- is_interactive: bool,
177
- *args,
178
- **kwargs,
179
- ):
180
- """
181
- Perform bundle, application package creation, stage upload, version and/or patch to an application package.
182
- """
183
-
184
- # Make sure version is not None before proceeding any further.
185
- # This will raise an exception if version information is not found. Patch can be None.
186
- if not version:
187
- cc.message(
188
- "Version was not provided through the Snowflake CLI. Checking version in the manifest.yml instead."
189
- )
190
-
191
- version, patch = find_version_info_in_manifest_file(self.deploy_root)
192
- if not version:
193
- raise ClickException(
194
- "Manifest.yml file does not contain a value for the version field."
195
- )
196
-
197
- # Check if --patch needs to throw a bad option error, either if application package does not exist or if version does not exist
198
- if patch:
199
- try:
200
- if not self.get_existing_version_info(version):
201
- raise BadOptionUsage(
202
- option_name="patch",
203
- message=f"Cannot create a custom patch when version {version} is not defined in the application package {self.package_name}. Try again without using --patch.",
204
- )
205
- except ApplicationPackageDoesNotExistError as app_err:
206
- raise BadOptionUsage(
207
- option_name="patch",
208
- message=f"Cannot create a custom patch when application package {self.package_name} does not exist. Try again without using --patch.",
209
- )
210
-
211
- if git_policy.should_proceed():
212
- check_index_changes_in_git_repo(
213
- project_root=self.project_root,
214
- policy=policy,
215
- is_interactive=is_interactive,
216
- )
217
-
218
- # TODO: consider using self.deploy() instead
219
-
220
- try:
221
- self.create_app_package()
222
- except ApplicationPackageAlreadyExistsError as e:
223
- cc.warning(e.message)
224
- if not policy.should_proceed("Proceed with using this package?"):
225
- raise typer.Abort() from e
226
-
227
- with self.use_role(self.package_role):
228
- # Now that the application package exists, create shared data
229
- self._apply_package_scripts()
230
-
231
- # Upload files from deploy root local folder to the above stage
232
- self.sync_deploy_root_with_stage(
233
- bundle_map=bundle_map,
234
- role=self.package_role,
235
- prune=True,
236
- recursive=True,
237
- stage_fqn=self.stage_fqn,
238
- )
239
- with self.use_package_warehouse():
240
- self.execute_package_post_deploy_hooks()
241
-
242
- # Warn if the version exists in a release directive(s)
243
- existing_release_directives = (
244
- self.get_existing_release_directive_info_for_version(version)
245
- )
246
- if existing_release_directives:
247
- release_directive_names = ", ".join(
248
- row["name"] for row in existing_release_directives
249
- )
250
- cc.warning(
251
- dedent(
252
- f"""\
253
- Version {version} already defined in application package {self.package_name} and in release directive(s): {release_directive_names}.
254
- """
255
- )
256
- )
257
-
258
- user_prompt = (
259
- f"Are you sure you want to create a new patch for version {version} in application "
260
- f"package {self.package_name}? Once added, this operation cannot be undone."
261
- )
262
- if not policy.should_proceed(user_prompt):
263
- if is_interactive:
264
- cc.message("Not creating a new patch.")
265
- raise typer.Exit(0)
266
- else:
267
- cc.message(
268
- "Cannot create a new patch non-interactively without --force."
269
- )
270
- raise typer.Exit(1)
271
-
272
- # Define a new version in the application package
273
- if not self.get_existing_version_info(version):
274
- self.add_new_version(version=version)
275
- return # A new version created automatically has patch 0, we do not need to further increment the patch.
276
-
277
- # Add a new patch to an existing (old) version
278
- self.add_new_patch_to_version(version=version, patch=patch)
279
-
280
-
281
- class NativeAppVersionDropProcessor(NativeAppManager, NativeAppCommandProcessor):
282
- def __init__(self, project_definition: NativeApp, project_root: Path):
283
- super().__init__(project_definition, project_root)
284
-
285
- def process(
286
- self,
287
- version: Optional[str],
288
- policy: PolicyBase,
289
- is_interactive: bool,
290
- *args,
291
- **kwargs,
292
- ):
293
- """
294
- Drops a version defined in an application package. If --force is provided, then no user prompts will be executed.
295
- """
296
-
297
- # 1. Check for existing an existing application package
298
- show_obj_row = self.get_existing_app_pkg_info()
299
- if show_obj_row:
300
- # Check for the right owner role
301
- ensure_correct_owner(
302
- row=show_obj_row, role=self.package_role, obj_name=self.package_name
303
- )
304
- else:
305
- raise ApplicationPackageDoesNotExistError(self.package_name)
306
-
307
- # 2. Check distribution of the existing application package
308
- actual_distribution = self.get_app_pkg_distribution_in_snowflake
309
- if not self.verify_project_distribution(actual_distribution):
310
- cc.warning(
311
- f"Continuing to execute `snow app version drop` on application package {self.package_name} with distribution '{actual_distribution}'."
312
- )
313
-
314
- # 3. If the user did not pass in a version string, determine from manifest.yml
315
- if not version:
316
- cc.message(
317
- dedent(
318
- f"""\
319
- Version was not provided through the Snowflake CLI. Checking version in the manifest.yml instead.
320
- This step will bundle your app artifacts to determine the location of the manifest.yml file.
321
- """
322
- )
323
- )
324
- self.build_bundle()
325
- version, _ = find_version_info_in_manifest_file(self.deploy_root)
326
- if not version:
327
- raise ClickException(
328
- "Manifest.yml file does not contain a value for the version field."
329
- )
330
-
331
- cc.step(
332
- dedent(
333
- f"""\
334
- About to drop version {version} in application package {self.package_name}.
335
- """
336
- )
337
- )
338
-
339
- # If user did not provide --force, ask for confirmation
340
- user_prompt = (
341
- f"Are you sure you want to drop version {version} in application package {self.package_name}? Once dropped, this operation cannot be undone.",
342
- )
343
- if not policy.should_proceed(user_prompt):
344
- if is_interactive:
345
- cc.message("Not dropping version.")
346
- raise typer.Exit(0)
347
- else:
348
- cc.message("Cannot drop version non-interactively without --force.")
349
- raise typer.Exit(1)
350
-
351
- # Drop the version
352
- with self.use_role(self.package_role):
353
- try:
354
- self._execute_query(
355
- f"alter application package {self.package_name} drop version {version}"
356
- )
357
- except ProgrammingError as err:
358
- raise err # e.g. version is referenced in a release directive(s)
359
-
360
- cc.message(
361
- f"Version {version} in application package {self.package_name} dropped successfully."
362
- )
@@ -1,13 +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.
@@ -1,84 +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 logging
16
-
17
- import typer
18
- from snowflake.cli.api.commands.flags import identifier_argument
19
- from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
20
- from snowflake.cli.api.output.types import MessageResult
21
- from snowflake.cli.plugins.notebook.manager import NotebookManager
22
- from snowflake.cli.plugins.notebook.types import NotebookName, NotebookStagePath
23
- from typing_extensions import Annotated
24
-
25
- app = SnowTyperFactory(
26
- name="notebook",
27
- help="Manages notebooks in Snowflake.",
28
- )
29
- log = logging.getLogger(__name__)
30
-
31
- NOTEBOOK_IDENTIFIER = identifier_argument(sf_object="notebook", example="MY_NOTEBOOK")
32
- NotebookFile: NotebookStagePath = typer.Option(
33
- "--notebook-file",
34
- "-f",
35
- help="Stage path with notebook file. For example `@stage/path/to/notebook.ipynb`",
36
- )
37
-
38
-
39
- @app.command(requires_connection=True)
40
- def execute(
41
- identifier: str = NOTEBOOK_IDENTIFIER,
42
- **options,
43
- ):
44
- """
45
- Executes a notebook in a headless mode.
46
- """
47
- # Execution does not return any meaningful result
48
- _ = NotebookManager().execute(notebook_name=identifier)
49
- return MessageResult(f"Notebook {identifier} executed.")
50
-
51
-
52
- @app.command(requires_connection=True)
53
- def get_url(
54
- identifier: str = NOTEBOOK_IDENTIFIER,
55
- **options,
56
- ):
57
- """Return a url to a notebook."""
58
- url = NotebookManager().get_url(notebook_name=identifier)
59
- return MessageResult(message=url)
60
-
61
-
62
- @app.command(name="open", requires_connection=True)
63
- def open_cmd(
64
- identifier: str = NOTEBOOK_IDENTIFIER,
65
- **options,
66
- ):
67
- """Opens a notebook in default browser"""
68
- url = NotebookManager().get_url(notebook_name=identifier)
69
- typer.launch(url)
70
- return MessageResult(message=url)
71
-
72
-
73
- @app.command(requires_connection=True)
74
- def create(
75
- identifier: Annotated[NotebookName, NOTEBOOK_IDENTIFIER],
76
- notebook_file: Annotated[NotebookStagePath, NotebookFile],
77
- **options,
78
- ):
79
- """Creates notebook from stage."""
80
- notebook_url = NotebookManager().create(
81
- notebook_name=identifier,
82
- notebook_file=notebook_file,
83
- )
84
- return MessageResult(message=notebook_url)
@@ -1,20 +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 click.exceptions import ClickException
16
-
17
-
18
- class NotebookStagePathError(ClickException):
19
- def __init__(self, path: str):
20
- super().__init__(f"Cannot extract notebook file name from {path=}")