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,30 +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 snowflake.cli.api.plugins.command import (
16
- SNOWCLI_ROOT_COMMAND_PATH,
17
- CommandSpec,
18
- CommandType,
19
- plugin_hook_impl,
20
- )
21
- from snowflake.cli.plugins.stage import commands
22
-
23
-
24
- @plugin_hook_impl
25
- def command_spec():
26
- return CommandSpec(
27
- parent_command_path=SNOWCLI_ROOT_COMMAND_PATH,
28
- command_type=CommandType.COMMAND_GROUP,
29
- typer_instance=commands.app.create_instance(),
30
- )
@@ -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,186 +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 pathlib import Path
19
-
20
- import click
21
- import typer
22
- from click import ClickException
23
- from snowflake.cli.api.cli_global_context import cli_context
24
- from snowflake.cli.api.commands.decorators import (
25
- with_experimental_behaviour,
26
- with_project_definition,
27
- )
28
- from snowflake.cli.api.commands.flags import ReplaceOption, like_option
29
- from snowflake.cli.api.commands.project_initialisation import add_init_command
30
- from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
31
- from snowflake.cli.api.constants import ObjectType
32
- from snowflake.cli.api.identifiers import FQN
33
- from snowflake.cli.api.output.types import (
34
- CommandResult,
35
- MessageResult,
36
- SingleQueryResult,
37
- )
38
- from snowflake.cli.api.project.project_verification import assert_project_type
39
- from snowflake.cli.api.project.schemas.streamlit.streamlit import Streamlit
40
- from snowflake.cli.plugins.object.command_aliases import (
41
- add_object_command_aliases,
42
- scope_option,
43
- )
44
- from snowflake.cli.plugins.streamlit.manager import StreamlitManager
45
-
46
- app = SnowTyperFactory(
47
- name="streamlit",
48
- help="Manages a Streamlit app in Snowflake.",
49
- )
50
- log = logging.getLogger(__name__)
51
-
52
-
53
- class IdentifierType(click.ParamType):
54
- name = "TEXT"
55
-
56
- def convert(self, value, param, ctx):
57
- return FQN.from_string(value)
58
-
59
-
60
- StreamlitNameArgument = typer.Argument(
61
- ...,
62
- help="Name of the Streamlit app.",
63
- show_default=False,
64
- click_type=IdentifierType(),
65
- )
66
- OpenOption = typer.Option(
67
- False,
68
- "--open",
69
- help="Whether to open the Streamlit app in a browser.",
70
- is_flag=True,
71
- )
72
-
73
- add_init_command(
74
- app,
75
- project_type="Streamlit",
76
- template="default_streamlit",
77
- help_message="Name of the Streamlit app project directory you want to create. Defaults to `example_streamlit`.",
78
- )
79
-
80
- add_object_command_aliases(
81
- app=app,
82
- object_type=ObjectType.STREAMLIT,
83
- name_argument=StreamlitNameArgument,
84
- like_option=like_option(
85
- help_example='`list --like "my%"` lists all streamlit apps that begin with “my”'
86
- ),
87
- scope_option=scope_option(help_example="`list --in database my_db`"),
88
- )
89
-
90
-
91
- @app.command("share", requires_connection=True)
92
- def streamlit_share(
93
- name: FQN = StreamlitNameArgument,
94
- to_role: str = typer.Argument(
95
- ..., help="Role with which to share the Streamlit app."
96
- ),
97
- **options,
98
- ) -> CommandResult:
99
- """
100
- Shares a Streamlit app with another role.
101
- """
102
- cursor = StreamlitManager().share(streamlit_name=name, to_role=to_role)
103
- return SingleQueryResult(cursor)
104
-
105
-
106
- def _default_file_callback(param_name: str):
107
- from click.core import ParameterSource # type: ignore
108
-
109
- def _check_file_exists_if_not_default(ctx: click.Context, value):
110
- if (
111
- ctx.get_parameter_source(param_name) != ParameterSource.DEFAULT # type: ignore
112
- and value
113
- and not Path(value).exists()
114
- ):
115
- raise ClickException(f"Provided file {value} does not exist")
116
- return Path(value)
117
-
118
- return _check_file_exists_if_not_default
119
-
120
-
121
- @app.command("deploy", requires_connection=True)
122
- @with_project_definition()
123
- @with_experimental_behaviour()
124
- def streamlit_deploy(
125
- replace: bool = ReplaceOption(
126
- help="Replace the Streamlit app if it already exists."
127
- ),
128
- open_: bool = OpenOption,
129
- **options,
130
- ) -> CommandResult:
131
- """
132
- Deploys a Streamlit app defined in the project definition file (snowflake.yml). By default, the command uploads
133
- environment.yml and any other pages or folders, if present. If you don’t specify a stage name, the `streamlit`
134
- stage is used. If the specified stage does not exist, the command creates it.
135
- """
136
-
137
- assert_project_type("streamlit")
138
-
139
- streamlit: Streamlit = cli_context.project_definition.streamlit
140
- if not streamlit:
141
- return MessageResult("No streamlit were specified in project definition.")
142
-
143
- environment_file = streamlit.env_file
144
- if environment_file and not Path(environment_file).exists():
145
- raise ClickException(f"Provided file {environment_file} does not exist")
146
- elif environment_file is None:
147
- environment_file = "environment.yml"
148
-
149
- pages_dir = streamlit.pages_dir
150
- if pages_dir and not Path(pages_dir).exists():
151
- raise ClickException(f"Provided file {pages_dir} does not exist")
152
- elif pages_dir is None:
153
- pages_dir = "pages"
154
-
155
- streamlit_id = FQN.from_identifier_model(streamlit).using_context()
156
-
157
- url = StreamlitManager().deploy(
158
- streamlit_id=streamlit_id,
159
- environment_file=Path(environment_file),
160
- pages_dir=Path(pages_dir),
161
- stage_name=streamlit.stage,
162
- main_file=Path(streamlit.main_file),
163
- replace=replace,
164
- query_warehouse=streamlit.query_warehouse,
165
- additional_source_files=streamlit.additional_source_files,
166
- title=streamlit.title,
167
- **options,
168
- )
169
-
170
- if open_:
171
- typer.launch(url)
172
-
173
- return MessageResult(f"Streamlit successfully deployed and available under {url}")
174
-
175
-
176
- @app.command("get-url", requires_connection=True)
177
- def get_url(
178
- name: FQN = StreamlitNameArgument,
179
- open_: bool = OpenOption,
180
- **options,
181
- ):
182
- """Returns a URL to the specified Streamlit app"""
183
- url = StreamlitManager().get_url(streamlit_name=name)
184
- if open_:
185
- typer.launch(url)
186
- return MessageResult(url)
@@ -1,222 +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
- import os
19
- from pathlib import Path
20
- from typing import List, Optional
21
-
22
- from snowflake.cli.api.commands.experimental_behaviour import (
23
- experimental_behaviour_enabled,
24
- )
25
- from snowflake.cli.api.feature_flags import FeatureFlag
26
- from snowflake.cli.api.identifiers import FQN
27
- from snowflake.cli.api.sql_execution import SqlExecutionMixin
28
- from snowflake.cli.plugins.connection.util import (
29
- MissingConnectionAccountError,
30
- MissingConnectionRegionError,
31
- make_snowsight_url,
32
- )
33
- from snowflake.cli.plugins.stage.manager import StageManager
34
- from snowflake.connector.cursor import SnowflakeCursor
35
- from snowflake.connector.errors import ProgrammingError
36
-
37
- log = logging.getLogger(__name__)
38
-
39
-
40
- class StreamlitManager(SqlExecutionMixin):
41
- def share(self, streamlit_name: FQN, to_role: str) -> SnowflakeCursor:
42
- return self._execute_query(
43
- f"grant usage on streamlit {streamlit_name.sql_identifier} to role {to_role}"
44
- )
45
-
46
- def _put_streamlit_files(
47
- self,
48
- root_location: str,
49
- main_file: Path,
50
- environment_file: Optional[Path],
51
- pages_dir: Optional[Path],
52
- additional_source_files: Optional[List[Path]],
53
- ):
54
- stage_manager = StageManager()
55
-
56
- stage_manager.put(main_file, root_location, 4, True)
57
-
58
- if environment_file and environment_file.exists():
59
- stage_manager.put(environment_file, root_location, 4, True)
60
-
61
- if pages_dir and pages_dir.exists():
62
- stage_manager.put(pages_dir / "*.py", f"{root_location}/pages", 4, True)
63
-
64
- if additional_source_files:
65
- for file in additional_source_files:
66
- if os.sep in str(file):
67
- destination = f"{root_location}/{str(file.parent)}"
68
- else:
69
- destination = root_location
70
- stage_manager.put(file, destination, 4, True)
71
-
72
- def _create_streamlit(
73
- self,
74
- streamlit_id: FQN,
75
- main_file: Path,
76
- replace: Optional[bool] = None,
77
- experimental: Optional[bool] = None,
78
- query_warehouse: Optional[str] = None,
79
- from_stage_name: Optional[str] = None,
80
- title: Optional[str] = None,
81
- ):
82
- query = []
83
- if replace:
84
- query.append(f"CREATE OR REPLACE STREAMLIT {streamlit_id.sql_identifier}")
85
- elif experimental:
86
- # For experimental behaviour, we need to use CREATE STREAMLIT IF NOT EXISTS
87
- # for a streamlit app with an embedded stage
88
- # because this is analogous to the behavior for non-experimental
89
- # deploy which does CREATE STAGE IF NOT EXISTS
90
- query.append(
91
- f"CREATE STREAMLIT IF NOT EXISTS {streamlit_id.sql_identifier}"
92
- )
93
- else:
94
- query.append(f"CREATE STREAMLIT {streamlit_id.sql_identifier}")
95
-
96
- if from_stage_name:
97
- query.append(f"ROOT_LOCATION = '{from_stage_name}'")
98
-
99
- query.append(f"MAIN_FILE = '{main_file.name}'")
100
-
101
- if query_warehouse:
102
- query.append(f"QUERY_WAREHOUSE = {query_warehouse}")
103
- if title:
104
- query.append(f"TITLE = '{title}'")
105
-
106
- self._execute_query("\n".join(query))
107
-
108
- def deploy(
109
- self,
110
- streamlit_id: FQN,
111
- main_file: Path,
112
- environment_file: Optional[Path] = None,
113
- pages_dir: Optional[Path] = None,
114
- stage_name: Optional[str] = None,
115
- query_warehouse: Optional[str] = None,
116
- replace: Optional[bool] = False,
117
- additional_source_files: Optional[List[Path]] = None,
118
- title: Optional[str] = None,
119
- **options,
120
- ):
121
- # for backwards compatibility - quoted stage path might be case-sensitive
122
- # https://docs.snowflake.com/en/sql-reference/identifiers-syntax#double-quoted-identifiers
123
- streamlit_name_for_root_location = streamlit_id.name
124
- use_versioned_stage = FeatureFlag.ENABLE_STREAMLIT_VERSIONED_STAGE.is_enabled()
125
- if (
126
- experimental_behaviour_enabled()
127
- or FeatureFlag.ENABLE_STREAMLIT_EMBEDDED_STAGE.is_enabled()
128
- or use_versioned_stage
129
- ):
130
- """
131
- 1. Create streamlit object
132
- 2. Upload files to embedded stage
133
- """
134
- # TODO: Support from_stage
135
- # from_stage_stmt = f"FROM_STAGE = '{stage_name}'" if stage_name else ""
136
- self._create_streamlit(
137
- streamlit_id,
138
- main_file,
139
- replace=replace,
140
- query_warehouse=query_warehouse,
141
- experimental=True,
142
- title=title,
143
- )
144
- try:
145
- if use_versioned_stage:
146
- self._execute_query(
147
- f"ALTER STREAMLIT {streamlit_id.identifier} ADD LIVE VERSION FROM LAST"
148
- )
149
- elif not FeatureFlag.ENABLE_STREAMLIT_NO_CHECKOUTS.is_enabled():
150
- self._execute_query(
151
- f"ALTER streamlit {streamlit_id.identifier} CHECKOUT"
152
- )
153
- except ProgrammingError as e:
154
- # If an error is raised because a CHECKOUT has already occurred or a LIVE VERSION already exists, simply skip it and continue
155
- if "Checkout already exists" in str(
156
- e
157
- ) or "There is already a live version" in str(e):
158
- log.info("Checkout already exists, continuing")
159
- else:
160
- raise
161
-
162
- stage_path = streamlit_id.identifier
163
- embedded_stage_name = f"snow://streamlit/{stage_path}"
164
- if use_versioned_stage:
165
- # "LIVE" is the only supported version for now, but this may change later.
166
- root_location = f"{embedded_stage_name}/versions/live"
167
- else:
168
- root_location = f"{embedded_stage_name}/default_checkout"
169
-
170
- self._put_streamlit_files(
171
- root_location,
172
- main_file,
173
- environment_file,
174
- pages_dir,
175
- additional_source_files,
176
- )
177
- else:
178
- """
179
- 1. Create stage
180
- 2. Upload files to created stage
181
- 3. Create streamlit from stage
182
- """
183
- stage_manager = StageManager()
184
-
185
- stage_name = stage_name or "streamlit"
186
- stage_name = FQN.from_string(stage_name).using_connection(self._conn)
187
-
188
- stage_manager.create(stage_name=stage_name)
189
-
190
- root_location = stage_manager.get_standard_stage_prefix(
191
- f"{stage_name}/{streamlit_name_for_root_location}"
192
- )
193
-
194
- self._put_streamlit_files(
195
- root_location,
196
- main_file,
197
- environment_file,
198
- pages_dir,
199
- additional_source_files,
200
- )
201
-
202
- self._create_streamlit(
203
- streamlit_id,
204
- main_file,
205
- replace=replace,
206
- query_warehouse=query_warehouse,
207
- from_stage_name=root_location,
208
- experimental=False,
209
- title=title,
210
- )
211
-
212
- return self.get_url(streamlit_name=streamlit_id)
213
-
214
- def get_url(self, streamlit_name: FQN) -> str:
215
- try:
216
- fqn = streamlit_name.using_connection(self._conn)
217
- return make_snowsight_url(
218
- self._conn,
219
- f"/#/streamlit-apps/{fqn.url_identifier}",
220
- )
221
- except (MissingConnectionRegionError, MissingConnectionAccountError) as e:
222
- return "https://app.snowflake.com"
@@ -1,30 +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 snowflake.cli.api.plugins.command import (
16
- SNOWCLI_ROOT_COMMAND_PATH,
17
- CommandSpec,
18
- CommandType,
19
- plugin_hook_impl,
20
- )
21
- from snowflake.cli.plugins.streamlit import commands
22
-
23
-
24
- @plugin_hook_impl
25
- def command_spec():
26
- return CommandSpec(
27
- parent_command_path=SNOWCLI_ROOT_COMMAND_PATH,
28
- command_type=CommandType.COMMAND_GROUP,
29
- typer_instance=commands.app.create_instance(),
30
- )
@@ -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,35 +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 snowflake.cli.api.commands.decorators import with_project_definition
18
- from snowflake.cli.api.commands.snow_typer import SnowTyper
19
- from snowflake.cli.api.output.types import MessageResult
20
-
21
- ws = SnowTyper(
22
- name="ws",
23
- hidden=True,
24
- help="Deploy and interact with snowflake.yml-based entities.",
25
- )
26
-
27
-
28
- @ws.command(requires_connection=True)
29
- @with_project_definition()
30
- def validate(
31
- **options,
32
- ):
33
- """Validates the project definition file."""
34
- # If we get to this point, @with_project_definition() has already validated the PDF schema
35
- return MessageResult("Project definition is valid.")
@@ -1,30 +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 snowflake.cli.api.plugins.command import (
16
- SNOWCLI_ROOT_COMMAND_PATH,
17
- CommandSpec,
18
- CommandType,
19
- plugin_hook_impl,
20
- )
21
- from snowflake.cli.plugins.workspace import commands
22
-
23
-
24
- @plugin_hook_impl
25
- def command_spec():
26
- return CommandSpec(
27
- parent_command_path=SNOWCLI_ROOT_COMMAND_PATH,
28
- command_type=CommandType.COMMAND_GROUP,
29
- typer_instance=commands.ws,
30
- )
@@ -1,4 +0,0 @@
1
- .packages/
2
- .venv/
3
- app.zip
4
- __pycache__
File without changes
@@ -1,2 +0,0 @@
1
- def print_hello(name: str):
2
- return f"Hello {name}!"
@@ -1,15 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import sys
4
-
5
- from common import print_hello
6
-
7
-
8
- def hello_function(name: str) -> str:
9
- return print_hello(name)
10
-
11
-
12
- # For local debugging
13
- # Be aware you may need to type-convert arguments if you add input parameters
14
- if __name__ == "__main__":
15
- print(hello_function(*sys.argv[1:])) # type: ignore
@@ -1,22 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import sys
4
-
5
- from common import print_hello
6
- from snowflake.snowpark import Session
7
-
8
-
9
- def hello_procedure(session: Session, name: str) -> str:
10
- return print_hello(name)
11
-
12
-
13
- def test_procedure(session: Session) -> str:
14
- return "Test procedure"
15
-
16
-
17
- # For local debugging
18
- # Beware you may need to type-convert arguments if you add input parameters
19
- if __name__ == "__main__":
20
- # Create a local Snowpark session
21
- with Session.builder.config("local_testing", True).getOrCreate() as session:
22
- print(hello_procedure(session, *sys.argv[1:])) # type: ignore
@@ -1 +0,0 @@
1
- snowflake-snowpark-python
@@ -1,23 +0,0 @@
1
- definition_version: "1.1"
2
- snowpark:
3
- project_name: "my_snowpark_project"
4
- stage_name: "dev_deployment"
5
- src: "app/"
6
- functions:
7
- - name: hello_function
8
- handler: "functions.hello_function"
9
- signature:
10
- - name: "name"
11
- type: "string"
12
- returns: string
13
- procedures:
14
- - name: hello_procedure
15
- handler: "procedures.hello_procedure"
16
- signature:
17
- - name: "name"
18
- type: "string"
19
- returns: string
20
- - name: test_procedure
21
- handler: "procedures.test_procedure"
22
- signature: ""
23
- returns: string
@@ -1,4 +0,0 @@
1
- .packages/
2
- .venv/
3
- app.zip
4
- __pycache__
@@ -1,2 +0,0 @@
1
- def say_hello():
2
- return "Hello!"
@@ -1,6 +0,0 @@
1
- name: sf_env
2
- channels:
3
- - snowflake
4
- dependencies:
5
- - streamlit
6
- - snowflake-snowpark-python
@@ -1,3 +0,0 @@
1
- import streamlit as st
2
-
3
- st.title("Example page")
@@ -1,10 +0,0 @@
1
- definition_version: "1.1"
2
- streamlit:
3
- name: streamlit_app
4
- stage: my_streamlit_stage
5
- query_warehouse: my_streamlit_warehouse
6
- main_file: streamlit_app.py
7
- env_file: environment.yml
8
- pages_dir: pages/
9
- additional_source_files:
10
- - common/hello.py
@@ -1,4 +0,0 @@
1
- import streamlit as st
2
- from common.hello import say_hello
3
-
4
- st.title(f"Example streamlit app. {say_hello()}")