snowflake-cli-labs 2.8.0rc1__py3-none-any.whl → 3.0.0__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 (251) hide show
  1. snowflake/cli/__about__.py +1 -1
  2. snowflake/cli/{app → _app}/__main__.py +1 -1
  3. snowflake/cli/{app → _app}/cli_app.py +22 -13
  4. snowflake/cli/{app → _app}/commands_registration/builtin_plugins.py +15 -19
  5. snowflake/cli/{app → _app}/commands_registration/command_plugins_loader.py +9 -9
  6. snowflake/cli/{app → _app}/commands_registration/commands_registration_with_callbacks.py +4 -4
  7. snowflake/cli/{app → _app}/commands_registration/exception_logging.py +2 -2
  8. snowflake/cli/{app → _app}/commands_registration/typer_registration.py +2 -2
  9. snowflake/cli/{app → _app}/dev/docs/commands_docs_generator.py +30 -12
  10. snowflake/cli/{app → _app}/dev/docs/generator.py +3 -3
  11. snowflake/cli/{app → _app}/dev/docs/project_definition_docs_generator.py +4 -4
  12. snowflake/cli/{app → _app}/dev/docs/templates/usage.rst.jinja2 +14 -4
  13. snowflake/cli/{app → _app}/main_typer.py +2 -2
  14. snowflake/cli/{app → _app}/printing.py +2 -2
  15. snowflake/cli/_app/secret.py +9 -0
  16. snowflake/cli/{app → _app}/snow_connector.py +127 -61
  17. snowflake/cli/{app → _app}/telemetry.py +38 -7
  18. snowflake/cli/_app/version_check.py +74 -0
  19. snowflake/cli/{plugins → _plugins}/connection/commands.py +34 -11
  20. snowflake/cli/_plugins/connection/plugin_spec.py +30 -0
  21. snowflake/cli/{plugins → _plugins}/connection/util.py +16 -0
  22. snowflake/cli/{plugins → _plugins}/cortex/commands.py +54 -49
  23. snowflake/cli/{plugins → _plugins}/cortex/constants.py +1 -1
  24. snowflake/cli/{plugins → _plugins}/cortex/manager.py +5 -5
  25. snowflake/cli/{plugins → _plugins}/cortex/plugin_spec.py +1 -1
  26. snowflake/cli/{plugins → _plugins}/git/commands.py +79 -26
  27. snowflake/cli/{plugins → _plugins}/git/manager.py +72 -17
  28. snowflake/cli/{plugins → _plugins}/git/plugin_spec.py +1 -1
  29. snowflake/cli/_plugins/helpers/commands.py +90 -0
  30. snowflake/cli/{plugins/notebook → _plugins/helpers}/plugin_spec.py +1 -1
  31. snowflake/cli/{plugins → _plugins}/init/commands.py +10 -6
  32. snowflake/cli/{plugins → _plugins}/init/plugin_spec.py +1 -1
  33. snowflake/cli/{plugins → _plugins}/nativeapp/artifacts.py +24 -9
  34. snowflake/cli/_plugins/nativeapp/bundle_context.py +31 -0
  35. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/artifact_processor.py +4 -4
  36. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/compiler.py +37 -18
  37. snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +249 -0
  38. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/setup/setup_driver.py.source +5 -2
  39. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/extension_function_utils.py +5 -5
  40. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/models.py +1 -1
  41. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/python_processor.py +29 -34
  42. snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +114 -0
  43. snowflake/cli/{plugins → _plugins}/nativeapp/commands.py +252 -132
  44. snowflake/cli/{plugins → _plugins}/nativeapp/common_flags.py +1 -1
  45. snowflake/cli/_plugins/nativeapp/entities/application.py +878 -0
  46. snowflake/cli/_plugins/nativeapp/entities/application_package.py +1392 -0
  47. snowflake/cli/{plugins → _plugins}/nativeapp/exceptions.py +3 -12
  48. snowflake/cli/_plugins/nativeapp/manager.py +415 -0
  49. snowflake/cli/{plugins/connection → _plugins/nativeapp}/plugin_spec.py +1 -1
  50. snowflake/cli/{plugins → _plugins}/nativeapp/policy.py +3 -0
  51. snowflake/cli/{plugins → _plugins}/nativeapp/project_model.py +36 -20
  52. snowflake/cli/_plugins/nativeapp/run_processor.py +184 -0
  53. snowflake/cli/_plugins/nativeapp/same_account_install_method.py +70 -0
  54. snowflake/cli/_plugins/nativeapp/teardown_processor.py +70 -0
  55. snowflake/cli/_plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +262 -0
  56. snowflake/cli/{plugins → _plugins}/nativeapp/version/commands.py +20 -49
  57. snowflake/cli/_plugins/nativeapp/version/version_processor.py +98 -0
  58. snowflake/cli/{plugins → _plugins}/notebook/commands.py +8 -6
  59. snowflake/cli/{plugins → _plugins}/notebook/manager.py +14 -14
  60. snowflake/cli/{plugins/nativeapp → _plugins/notebook}/plugin_spec.py +1 -1
  61. snowflake/cli/{plugins → _plugins}/notebook/types.py +0 -1
  62. snowflake/cli/{plugins → _plugins}/object/command_aliases.py +6 -5
  63. snowflake/cli/{plugins → _plugins}/object/commands.py +16 -10
  64. snowflake/cli/{plugins → _plugins}/object/manager.py +43 -21
  65. snowflake/cli/{plugins → _plugins}/object/plugin_spec.py +1 -1
  66. snowflake/cli/_plugins/snowpark/commands.py +450 -0
  67. snowflake/cli/_plugins/snowpark/common.py +268 -0
  68. snowflake/cli/{plugins → _plugins}/snowpark/models.py +2 -8
  69. snowflake/cli/{plugins → _plugins}/snowpark/package/anaconda_packages.py +2 -36
  70. snowflake/cli/{plugins → _plugins}/snowpark/package/commands.py +13 -74
  71. snowflake/cli/{plugins → _plugins}/snowpark/package/manager.py +4 -3
  72. snowflake/cli/{plugins → _plugins}/snowpark/package_utils.py +5 -5
  73. snowflake/cli/_plugins/snowpark/plugin_spec.py +30 -0
  74. snowflake/cli/_plugins/snowpark/snowpark_entity.py +29 -0
  75. snowflake/cli/_plugins/snowpark/snowpark_entity_model.py +173 -0
  76. snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +109 -0
  77. snowflake/cli/{plugins → _plugins}/snowpark/snowpark_shared.py +0 -36
  78. snowflake/cli/{plugins → _plugins}/snowpark/zipper.py +16 -8
  79. snowflake/cli/{plugins → _plugins}/spcs/__init__.py +5 -7
  80. snowflake/cli/{plugins → _plugins}/spcs/compute_pool/commands.py +29 -28
  81. snowflake/cli/{plugins → _plugins}/spcs/compute_pool/manager.py +3 -3
  82. snowflake/cli/{plugins → _plugins}/spcs/image_registry/commands.py +3 -3
  83. snowflake/cli/{plugins → _plugins}/spcs/image_repository/commands.py +25 -19
  84. snowflake/cli/{plugins → _plugins}/spcs/image_repository/manager.py +1 -1
  85. snowflake/cli/{plugins → _plugins}/spcs/plugin_spec.py +1 -1
  86. snowflake/cli/{plugins → _plugins}/spcs/services/commands.py +66 -32
  87. snowflake/cli/{plugins → _plugins}/spcs/services/manager.py +43 -5
  88. snowflake/cli/{plugins → _plugins}/sql/commands.py +20 -17
  89. snowflake/cli/{plugins → _plugins}/sql/manager.py +1 -1
  90. snowflake/cli/{plugins → _plugins}/sql/plugin_spec.py +1 -1
  91. snowflake/cli/{plugins → _plugins}/stage/commands.py +20 -17
  92. snowflake/cli/{plugins → _plugins}/stage/diff.py +1 -47
  93. snowflake/cli/{plugins → _plugins}/stage/manager.py +62 -24
  94. snowflake/cli/{plugins → _plugins}/stage/plugin_spec.py +1 -1
  95. snowflake/cli/_plugins/stage/utils.py +54 -0
  96. snowflake/cli/{plugins → _plugins}/streamlit/commands.py +71 -62
  97. snowflake/cli/{plugins → _plugins}/streamlit/manager.py +68 -70
  98. snowflake/cli/_plugins/streamlit/plugin_spec.py +30 -0
  99. snowflake/cli/_plugins/streamlit/streamlit_entity.py +12 -0
  100. snowflake/cli/_plugins/streamlit/streamlit_entity_model.py +66 -0
  101. snowflake/cli/_plugins/workspace/action_context.py +18 -0
  102. snowflake/cli/_plugins/workspace/commands.py +306 -0
  103. snowflake/cli/_plugins/workspace/manager.py +74 -0
  104. snowflake/cli/_plugins/workspace/plugin_spec.py +30 -0
  105. snowflake/cli/api/cli_global_context.py +152 -295
  106. snowflake/cli/api/commands/common.py +25 -0
  107. snowflake/cli/api/commands/decorators.py +19 -4
  108. snowflake/cli/api/commands/experimental_behaviour.py +2 -3
  109. snowflake/cli/api/commands/flags.py +143 -222
  110. snowflake/cli/api/commands/overrideable_parameter.py +143 -0
  111. snowflake/cli/api/commands/snow_typer.py +21 -11
  112. snowflake/cli/api/commands/utils.py +18 -0
  113. snowflake/cli/api/config.py +44 -12
  114. snowflake/cli/api/connections.py +216 -0
  115. snowflake/cli/api/console/abc.py +8 -3
  116. snowflake/cli/api/constants.py +11 -0
  117. snowflake/cli/api/entities/common.py +56 -0
  118. snowflake/cli/api/entities/utils.py +370 -0
  119. snowflake/cli/api/errno.py +1 -0
  120. snowflake/cli/api/exceptions.py +31 -5
  121. snowflake/cli/api/feature_flags.py +0 -1
  122. snowflake/cli/api/identifiers.py +45 -9
  123. snowflake/cli/api/metrics.py +92 -0
  124. snowflake/cli/api/project/definition.py +48 -6
  125. snowflake/cli/api/project/definition_conversion.py +400 -0
  126. snowflake/cli/api/project/definition_manager.py +16 -5
  127. snowflake/cli/api/project/project_verification.py +3 -3
  128. snowflake/cli/api/project/schemas/entities/common.py +91 -16
  129. snowflake/cli/api/project/schemas/entities/entities.py +37 -6
  130. snowflake/cli/api/project/schemas/project_definition.py +180 -49
  131. snowflake/cli/api/project/schemas/updatable_model.py +11 -3
  132. snowflake/cli/api/project/schemas/v1/__init__.py +0 -0
  133. snowflake/cli/api/project/schemas/{identifier_model.py → v1/identifier_model.py} +3 -1
  134. snowflake/cli/api/project/schemas/v1/native_app/__init__.py +0 -0
  135. snowflake/cli/api/project/schemas/{native_app → v1/native_app}/application.py +8 -9
  136. snowflake/cli/api/project/schemas/{native_app → v1/native_app}/native_app.py +4 -4
  137. snowflake/cli/api/project/schemas/{native_app → v1/native_app}/package.py +7 -1
  138. snowflake/cli/api/project/schemas/v1/snowpark/__init__.py +0 -0
  139. snowflake/cli/api/project/schemas/{snowpark → v1/snowpark}/callable.py +2 -2
  140. snowflake/cli/api/project/schemas/{snowpark → v1/snowpark}/snowpark.py +2 -2
  141. snowflake/cli/api/project/schemas/v1/streamlit/__init__.py +0 -0
  142. snowflake/cli/api/project/schemas/{streamlit → v1/streamlit}/streamlit.py +2 -1
  143. snowflake/cli/api/project/util.py +23 -6
  144. snowflake/cli/api/rendering/jinja.py +14 -8
  145. snowflake/cli/api/rendering/project_definition_templates.py +5 -1
  146. snowflake/cli/api/rendering/sql_templates.py +56 -11
  147. snowflake/cli/api/rest_api.py +11 -5
  148. snowflake/cli/api/secure_path.py +16 -18
  149. snowflake/cli/api/secure_utils.py +90 -1
  150. snowflake/cli/api/sql_execution.py +47 -27
  151. snowflake/cli/api/utils/definition_rendering.py +45 -13
  152. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0.dist-info}/METADATA +20 -18
  153. snowflake_cli_labs-3.0.0.dist-info/RECORD +242 -0
  154. snowflake_cli_labs-3.0.0.dist-info/entry_points.txt +2 -0
  155. snowflake/cli/api/commands/project_initialisation.py +0 -65
  156. snowflake/cli/api/commands/typer_pre_execute.py +0 -26
  157. snowflake/cli/api/project/schemas/entities/application_entity.py +0 -44
  158. snowflake/cli/api/project/schemas/entities/application_package_entity.py +0 -66
  159. snowflake/cli/app/build_and_push.sh +0 -8
  160. snowflake/cli/plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -172
  161. snowflake/cli/plugins/nativeapp/init.py +0 -345
  162. snowflake/cli/plugins/nativeapp/manager.py +0 -823
  163. snowflake/cli/plugins/nativeapp/run_processor.py +0 -389
  164. snowflake/cli/plugins/nativeapp/teardown_processor.py +0 -301
  165. snowflake/cli/plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -135
  166. snowflake/cli/plugins/nativeapp/version/version_processor.py +0 -362
  167. snowflake/cli/plugins/object_stage_deprecated/__init__.py +0 -15
  168. snowflake/cli/plugins/object_stage_deprecated/commands.py +0 -122
  169. snowflake/cli/plugins/object_stage_deprecated/plugin_spec.py +0 -32
  170. snowflake/cli/plugins/snowpark/commands.py +0 -548
  171. snowflake/cli/plugins/snowpark/common.py +0 -307
  172. snowflake/cli/plugins/snowpark/manager.py +0 -109
  173. snowflake/cli/plugins/snowpark/plugin_spec.py +0 -30
  174. snowflake/cli/plugins/snowpark/snowpark_package_paths.py +0 -65
  175. snowflake/cli/plugins/spcs/jobs/commands.py +0 -78
  176. snowflake/cli/plugins/spcs/jobs/manager.py +0 -53
  177. snowflake/cli/plugins/streamlit/__init__.py +0 -13
  178. snowflake/cli/plugins/streamlit/plugin_spec.py +0 -30
  179. snowflake/cli/plugins/workspace/__init__.py +0 -13
  180. snowflake/cli/plugins/workspace/commands.py +0 -35
  181. snowflake/cli/plugins/workspace/plugin_spec.py +0 -30
  182. snowflake/cli/templates/default_snowpark/.gitignore +0 -4
  183. snowflake/cli/templates/default_snowpark/app/common.py +0 -2
  184. snowflake/cli/templates/default_snowpark/app/functions.py +0 -15
  185. snowflake/cli/templates/default_snowpark/app/procedures.py +0 -22
  186. snowflake/cli/templates/default_snowpark/requirements.txt +0 -1
  187. snowflake/cli/templates/default_snowpark/snowflake.yml +0 -23
  188. snowflake/cli/templates/default_streamlit/.gitignore +0 -4
  189. snowflake/cli/templates/default_streamlit/common/hello.py +0 -2
  190. snowflake/cli/templates/default_streamlit/environment.yml +0 -6
  191. snowflake/cli/templates/default_streamlit/pages/my_page.py +0 -3
  192. snowflake/cli/templates/default_streamlit/snowflake.yml +0 -10
  193. snowflake/cli/templates/default_streamlit/streamlit_app.py +0 -4
  194. snowflake_cli_labs-2.8.0rc1.dist-info/RECORD +0 -240
  195. snowflake_cli_labs-2.8.0rc1.dist-info/entry_points.txt +0 -2
  196. /snowflake/cli/{app → _app}/__init__.py +0 -0
  197. /snowflake/cli/{api/project/schemas/native_app → _app/api_impl}/__init__.py +0 -0
  198. /snowflake/cli/{api/project/schemas/snowpark → _app/api_impl/plugin}/__init__.py +0 -0
  199. /snowflake/cli/{app → _app}/api_impl/plugin/plugin_config_provider_impl.py +0 -0
  200. /snowflake/cli/{app → _app}/commands_registration/__init__.py +0 -0
  201. /snowflake/cli/{app → _app}/commands_registration/threadsafe.py +0 -0
  202. /snowflake/cli/{app → _app}/constants.py +0 -0
  203. /snowflake/cli/{api/project/schemas/streamlit → _app/dev}/__init__.py +0 -0
  204. /snowflake/cli/{app → _app}/dev/commands_structure.py +0 -0
  205. /snowflake/cli/{app/api_impl → _app/dev/docs}/__init__.py +0 -0
  206. /snowflake/cli/{app → _app}/dev/docs/project_definition_generate_json_schema.py +0 -0
  207. /snowflake/cli/{app → _app}/dev/docs/template_utils.py +0 -0
  208. /snowflake/cli/{app → _app}/dev/docs/templates/definition_description.rst.jinja2 +0 -0
  209. /snowflake/cli/{app → _app}/dev/docs/templates/overview.rst.jinja2 +0 -0
  210. /snowflake/cli/{app → _app}/dev/pycharm_remote_debug.py +0 -0
  211. /snowflake/cli/{app → _app}/loggers.py +0 -0
  212. /snowflake/cli/{app/api_impl/plugin → _plugins}/__init__.py +0 -0
  213. /snowflake/cli/{app/dev → _plugins/connection}/__init__.py +0 -0
  214. /snowflake/cli/{app/dev/docs → _plugins/cortex}/__init__.py +0 -0
  215. /snowflake/cli/{plugins → _plugins}/cortex/types.py +0 -0
  216. /snowflake/cli/{plugins → _plugins/git}/__init__.py +0 -0
  217. /snowflake/cli/{plugins/connection → _plugins/helpers}/__init__.py +0 -0
  218. /snowflake/cli/{plugins/cortex → _plugins/init}/__init__.py +0 -0
  219. /snowflake/cli/{plugins/git → _plugins/nativeapp}/__init__.py +0 -0
  220. /snowflake/cli/{plugins/init → _plugins/nativeapp/codegen}/__init__.py +0 -0
  221. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/sandbox.py +0 -0
  222. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -0
  223. /snowflake/cli/{plugins → _plugins}/nativeapp/constants.py +0 -0
  224. /snowflake/cli/{templates/default_snowpark/app → _plugins/nativeapp/entities}/__init__.py +0 -0
  225. /snowflake/cli/{plugins → _plugins}/nativeapp/feature_flags.py +0 -0
  226. /snowflake/cli/{plugins → _plugins}/nativeapp/utils.py +0 -0
  227. /snowflake/cli/{plugins/nativeapp → _plugins/nativeapp/version}/__init__.py +0 -0
  228. /snowflake/cli/{plugins/nativeapp/codegen → _plugins/notebook}/__init__.py +0 -0
  229. /snowflake/cli/{plugins → _plugins}/notebook/exceptions.py +0 -0
  230. /snowflake/cli/{plugins/nativeapp/version → _plugins/object}/__init__.py +0 -0
  231. /snowflake/cli/{plugins → _plugins}/object/common.py +0 -0
  232. /snowflake/cli/{plugins/notebook → _plugins/snowpark}/__init__.py +0 -0
  233. /snowflake/cli/{plugins/object → _plugins/snowpark/package}/__init__.py +0 -0
  234. /snowflake/cli/{plugins → _plugins}/snowpark/package/utils.py +0 -0
  235. /snowflake/cli/{plugins → _plugins}/spcs/common.py +0 -0
  236. /snowflake/cli/{plugins/snowpark → _plugins/spcs/compute_pool}/__init__.py +0 -0
  237. /snowflake/cli/{plugins/snowpark/package → _plugins/spcs/image_registry}/__init__.py +0 -0
  238. /snowflake/cli/{plugins → _plugins}/spcs/image_registry/manager.py +0 -0
  239. /snowflake/cli/{plugins/spcs/compute_pool → _plugins/spcs/image_repository}/__init__.py +0 -0
  240. /snowflake/cli/{plugins/spcs/image_registry → _plugins/spcs/services}/__init__.py +0 -0
  241. /snowflake/cli/{plugins/spcs/image_repository → _plugins/sql}/__init__.py +0 -0
  242. /snowflake/cli/{plugins → _plugins}/sql/snowsql_templating.py +0 -0
  243. /snowflake/cli/{plugins/spcs/jobs → _plugins/stage}/__init__.py +0 -0
  244. /snowflake/cli/{plugins → _plugins}/stage/md5.py +0 -0
  245. /snowflake/cli/{plugins/spcs/services → _plugins/streamlit}/__init__.py +0 -0
  246. /snowflake/cli/{plugins/sql → _plugins/workspace}/__init__.py +0 -0
  247. /snowflake/cli/{plugins/stage → api/project/schemas/entities}/__init__.py +0 -0
  248. /snowflake/cli/api/project/schemas/{native_app → v1/native_app}/path_mapping.py +0 -0
  249. /snowflake/cli/api/project/schemas/{snowpark → v1/snowpark}/argument.py +0 -0
  250. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0.dist-info}/WHEEL +0 -0
  251. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,66 +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 typing import List, Literal, Optional, Union
19
-
20
- from pydantic import Field
21
- from snowflake.cli.api.project.schemas.entities.common import (
22
- EntityBase,
23
- )
24
- from snowflake.cli.api.project.schemas.native_app.package import DistributionOptions
25
- from snowflake.cli.api.project.schemas.native_app.path_mapping import PathMapping
26
- from snowflake.cli.api.project.schemas.updatable_model import (
27
- DiscriminatorField,
28
- IdentifierField,
29
- )
30
-
31
-
32
- class ApplicationPackageEntity(EntityBase):
33
- type: Literal["application package"] = DiscriminatorField() # noqa: A003
34
- name: str = Field(
35
- title="Name of the application package created when this entity is deployed"
36
- )
37
- artifacts: List[Union[PathMapping, Path]] = Field(
38
- title="List of paths or file source/destination pairs to add to the deploy root",
39
- )
40
- bundle_root: Optional[Path] = Field(
41
- title="Folder at the root of your project where artifacts necessary to perform the bundle step are stored.",
42
- default=Path("output/bundle/"),
43
- )
44
- deploy_root: Optional[Path] = Field(
45
- title="Folder at the root of your project where the build step copies the artifacts",
46
- default=Path("output/deploy/"),
47
- )
48
- generated_root: Optional[Path] = Field(
49
- title="Subdirectory of the deploy root where files generated by the Snowflake CLI will be written.",
50
- default=Path("__generated/"),
51
- )
52
- stage: Optional[str] = IdentifierField(
53
- title="Identifier of the stage that stores the application artifacts.",
54
- default="app_src.stage",
55
- )
56
- scratch_stage: Optional[str] = IdentifierField(
57
- title="Identifier of the stage that stores temporary scratch data used by the Snowflake CLI.",
58
- default="app_src.stage_snowflake_cli_scratch",
59
- )
60
- distribution: Optional[DistributionOptions] = Field(
61
- title="Distribution of the application package created by the Snowflake CLI",
62
- default="internal",
63
- )
64
- manifest: Path = Field(
65
- title="Path to manifest.yml",
66
- )
@@ -1,8 +0,0 @@
1
- set -e
2
- export SF_REGISTRY="$(snow spcs image-registry url -c integration)"
3
- DATABASE=$(echo "${SNOWFLAKE_CONNECTIONS_INTEGRATION_DATABASE}" | tr '[:upper:]' '[:lower:]')
4
-
5
- echo "Using registry: ${SF_REGISTRY}"
6
- docker build --platform linux/amd64 -t "${SF_REGISTRY}/${DATABASE}/public/snowcli_repository/test_counter" .
7
- snow spcs image-registry token --format=json -c integration | docker login "${SF_REGISTRY}/${DATABASE}/public/snowcli_repository" -u 0sessiontoken --password-stdin
8
- docker push "${SF_REGISTRY}/${DATABASE}/public/snowcli_repository/test_counter"
@@ -1,172 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from __future__ import annotations
16
-
17
- import json
18
- import os.path
19
- from pathlib import Path
20
- from typing import List, Optional
21
-
22
- from click import ClickException
23
- from snowflake.cli.api.console import cli_console as cc
24
- from snowflake.cli.api.project.schemas.native_app.path_mapping import (
25
- PathMapping,
26
- ProcessorMapping,
27
- )
28
- from snowflake.cli.plugins.nativeapp.artifacts import BundleMap, find_setup_script_file
29
- from snowflake.cli.plugins.nativeapp.codegen.artifact_processor import (
30
- ArtifactProcessor,
31
- is_python_file_artifact,
32
- )
33
- from snowflake.cli.plugins.nativeapp.codegen.sandbox import (
34
- ExecutionEnvironmentType,
35
- SandboxEnvBuilder,
36
- execute_script_in_sandbox,
37
- )
38
- from snowflake.cli.plugins.nativeapp.project_model import NativeAppProjectModel
39
- from snowflake.cli.plugins.stage.diff import to_stage_path
40
-
41
- DEFAULT_TIMEOUT = 30
42
- DRIVER_PATH = Path(__file__).parent / "setup_driver.py.source"
43
-
44
-
45
- class NativeAppSetupProcessor(ArtifactProcessor):
46
- def __init__(
47
- self,
48
- na_project: NativeAppProjectModel,
49
- ):
50
- super().__init__(na_project=na_project)
51
-
52
- def process(
53
- self,
54
- artifact_to_process: PathMapping,
55
- processor_mapping: Optional[ProcessorMapping],
56
- **kwargs,
57
- ) -> None:
58
- """
59
- Processes a Python setup script and generates the corresponding SQL commands.
60
- """
61
- bundle_map = BundleMap(
62
- project_root=self._na_project.project_root,
63
- deploy_root=self._na_project.deploy_root,
64
- )
65
- bundle_map.add(artifact_to_process)
66
-
67
- self._create_or_update_sandbox()
68
-
69
- cc.phase("Processing Python setup files")
70
-
71
- files_to_process = []
72
- for src_file, dest_file in bundle_map.all_mappings(
73
- absolute=True, expand_directories=True, predicate=is_python_file_artifact
74
- ):
75
- cc.message(
76
- f"Found Python setup file: {src_file.relative_to(self._na_project.project_root)}"
77
- )
78
- files_to_process.append(src_file)
79
-
80
- sql_files_mapping = self._execute_in_sandbox(files_to_process)
81
- self._generate_setup_sql(sql_files_mapping)
82
-
83
- def _execute_in_sandbox(self, py_files: List[Path]) -> dict:
84
- file_count = len(py_files)
85
- cc.step(f"Processing {file_count} setup file{'s' if file_count > 1 else ''}")
86
-
87
- env_vars = {
88
- "_SNOWFLAKE_CLI_PROJECT_PATH": str(self._na_project.project_root),
89
- "_SNOWFLAKE_CLI_SETUP_FILES": os.pathsep.join(map(str, py_files)),
90
- "_SNOWFLAKE_CLI_APP_NAME": str(self._na_project.package_name),
91
- "_SNOWFLAKE_CLI_SQL_DEST_DIR": str(self.generated_root),
92
- }
93
-
94
- try:
95
- result = execute_script_in_sandbox(
96
- script_source=DRIVER_PATH.read_text(),
97
- env_type=ExecutionEnvironmentType.VENV,
98
- cwd=self._na_project.bundle_root,
99
- timeout=DEFAULT_TIMEOUT,
100
- path=self.sandbox_root,
101
- env_vars=env_vars,
102
- )
103
- except Exception as e:
104
- raise ClickException(
105
- f"Exception while executing python setup script logic: {e}"
106
- )
107
-
108
- if result.returncode == 0:
109
- sql_file_mappings = json.loads(result.stdout)
110
- return sql_file_mappings
111
- else:
112
- raise ClickException(
113
- f"Failed to execute python setup script logic: {result.stderr}"
114
- )
115
-
116
- def _generate_setup_sql(self, sql_file_mappings: dict) -> None:
117
- if not sql_file_mappings:
118
- # Nothing to generate
119
- return
120
-
121
- generated_root = self.generated_root
122
- generated_root.mkdir(exist_ok=True, parents=True)
123
-
124
- cc.step("Patching setup script")
125
- setup_file_path = find_setup_script_file(
126
- deploy_root=self._na_project.deploy_root
127
- )
128
- with self.edit_file(setup_file_path) as f:
129
- new_contents = [f.contents]
130
-
131
- if sql_file_mappings["schemas"]:
132
- schemas_file = generated_root / sql_file_mappings["schemas"]
133
- new_contents.insert(
134
- 0,
135
- f"EXECUTE IMMEDIATE FROM '/{to_stage_path(schemas_file.relative_to(self._na_project.deploy_root))}';",
136
- )
137
-
138
- if sql_file_mappings["compute_pools"]:
139
- compute_pools_file = generated_root / sql_file_mappings["compute_pools"]
140
- new_contents.append(
141
- f"EXECUTE IMMEDIATE FROM '/{to_stage_path(compute_pools_file.relative_to(self._na_project.deploy_root))}';"
142
- )
143
-
144
- if sql_file_mappings["services"]:
145
- services_file = generated_root / sql_file_mappings["services"]
146
- new_contents.append(
147
- f"EXECUTE IMMEDIATE FROM '/{to_stage_path(services_file.relative_to(self._na_project.deploy_root))}';"
148
- )
149
-
150
- f.edited_contents = "\n".join(new_contents)
151
-
152
- @property
153
- def sandbox_root(self):
154
- return self._na_project.bundle_root / "setup_py_venv"
155
-
156
- @property
157
- def generated_root(self):
158
- return self._na_project.generated_root / "setup_py"
159
-
160
- def _create_or_update_sandbox(self):
161
- sandbox_root = self.sandbox_root
162
- env_builder = SandboxEnvBuilder(sandbox_root, with_pip=True)
163
- if sandbox_root.exists():
164
- cc.step("Virtual environment found")
165
- else:
166
- cc.step(
167
- f"Creating virtual environment in {sandbox_root.relative_to(self._na_project.project_root)}"
168
- )
169
- env_builder.ensure_created()
170
-
171
- # Temporarily fetch the library from a location specified via env vars
172
- env_builder.pip_install(os.environ["SNOWFLAKE_APP_PYTHON_LOC"])
@@ -1,345 +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 re
19
- from pathlib import Path
20
- from typing import Optional
21
-
22
- from click.exceptions import ClickException
23
- from snowflake.cli.api.constants import DEFAULT_SIZE_LIMIT_MB
24
- from snowflake.cli.api.exceptions import MissingConfiguration
25
- from snowflake.cli.api.project.definition_manager import DefinitionManager
26
- from snowflake.cli.api.project.util import (
27
- is_valid_identifier,
28
- is_valid_unquoted_identifier,
29
- to_identifier,
30
- )
31
- from snowflake.cli.api.rendering.jinja import jinja_render_from_file
32
- from snowflake.cli.api.secure_path import SecurePath
33
- from yaml import dump, safe_dump, safe_load
34
-
35
- log = logging.getLogger(__name__)
36
-
37
- OFFICIAL_TEMPLATES_GITHUB_URL = "https://github.com/snowflakedb/native-apps-templates"
38
- BASIC_TEMPLATE = "basic"
39
-
40
-
41
- class InitError(ClickException):
42
- """
43
- Snowflake Native App project could not be initiated due to an underlying error.
44
- """
45
-
46
- def __init__(self):
47
- super().__init__(self.__doc__)
48
-
49
-
50
- class ProjectNameInvalidError(ClickException):
51
- """
52
- Intended project name does not qualify as a valid identifier.
53
- """
54
-
55
- def __init__(self, project_name: str):
56
- super().__init__(
57
- f"Intended project name does not qualify as a valid identifier: {project_name}"
58
- )
59
-
60
-
61
- class RenderingFromJinjaError(ClickException):
62
- """
63
- Could not complete rendering file from Jinja template.
64
- """
65
-
66
- def __init__(self, name: str):
67
- super().__init__(
68
- f"Could not complete rendering file from Jinja template: {name}"
69
- )
70
-
71
-
72
- class CannotInitializeAnExistingProjectError(ClickException):
73
- """
74
- Cannot initialize a new project within an existing Snowflake Native App project.
75
- """
76
-
77
- def __init__(self):
78
- super().__init__(self.__doc__)
79
-
80
-
81
- class DirectoryAlreadyExistsError(ClickException):
82
- """
83
- Directory already contains a project with the intended name.
84
- """
85
-
86
- name: str
87
-
88
- def __init__(self, name: str):
89
- super().__init__(
90
- f"The directory {name} already exists. Please specify a different path for the project."
91
- )
92
- self.name = name
93
-
94
-
95
- class TemplateNotFoundError(ClickException):
96
- """
97
- Specified template was not found.
98
- """
99
-
100
- def __init__(self, template_name):
101
- super().__init__(f"Specified template was not found: {template_name}")
102
-
103
-
104
- class ProjectDescriptor:
105
- """
106
- Encapsulates static properties of a Snowflake Native App project.
107
- """
108
-
109
- def __init__(self, *, name, path):
110
- self.name = name
111
- self.path = path
112
-
113
-
114
- def _to_yaml_string(identifier: str):
115
- """
116
- Returns the YAML representation of an identifier, suitable for including in a YAML jinja template
117
- """
118
- if is_valid_unquoted_identifier(identifier):
119
- return identifier
120
- else:
121
- return dump(identifier).rstrip()
122
-
123
-
124
- def _render_snowflake_yml(parent_to_snowflake_yml: Path, project_identifier: str):
125
- """
126
- Create a snowflake.yml file from a jinja template at a given path.
127
-
128
- Args:
129
- parent_to_snowflake_yml (Path): The parent directory of snowflake.yml.jinja, and later snowflake.yml
130
- project_identifier (str): The name of the project to be created, as a Snowflake identifier.
131
-
132
- Returns:
133
- None
134
- """
135
-
136
- snowflake_yml_jinja = "snowflake.yml.jinja"
137
-
138
- try:
139
- jinja_render_from_file(
140
- template_path=parent_to_snowflake_yml / snowflake_yml_jinja,
141
- data={
142
- # generic_render_template operates on text, not YAML, so escape before rendering
143
- "project_name": _to_yaml_string(project_identifier)
144
- },
145
- output_file_path=parent_to_snowflake_yml / "snowflake.yml",
146
- )
147
- (parent_to_snowflake_yml / snowflake_yml_jinja).unlink()
148
- except Exception as err:
149
- log.error(err)
150
- raise RenderingFromJinjaError(snowflake_yml_jinja)
151
-
152
-
153
- def _replace_snowflake_yml_name_with_project(
154
- target_directory: Path, project_identifier: str
155
- ):
156
- """
157
- Replace the native_app schema's "name" field in a snowflake.yml file with its parent directory name, i.e. the Snowflake Native App project, as the default start.
158
- This does not change the name in any other snowflake.*.yml as snowflake.yml is the base file and all others are overrides for the user to customize.
159
-
160
- Args:
161
- target_directory (str): The directory containing snowflake.yml at its root.
162
- project_identifier (str): The name of the project to be created, as a Snowflake identifier.
163
-
164
- Returns:
165
- None
166
- """
167
-
168
- path_to_snowflake_yml = SecurePath(target_directory) / "snowflake.yml"
169
- contents = None
170
-
171
- with path_to_snowflake_yml.open(
172
- "r", read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB
173
- ) as file:
174
- contents = safe_load(file)
175
-
176
- if (
177
- (contents is not None)
178
- and ("native_app" in contents)
179
- and ("name" in contents["native_app"])
180
- and (contents["native_app"]["name"] != project_identifier)
181
- ):
182
- contents["native_app"]["name"] = project_identifier
183
- with path_to_snowflake_yml.open("w") as file:
184
- safe_dump(contents, file, sort_keys=False)
185
-
186
-
187
- def _validate_and_update_snowflake_yml(target_directory: Path, project_identifier: str):
188
- """
189
- Update the native_app name key in the snowflake.yml file and perform validation on the entire file.
190
- This step is useful when cloning from a non-Snowflake template repo which may directly have a snowflake.yml file.
191
-
192
- Args:
193
- target_directory (Path): The directory containing snowflake.yml at its root.
194
- project_identifier (str): The name of the project to be created, as a Snowflake identifier.
195
-
196
- Returns:
197
- None
198
- """
199
- # 1. Determine if a snowflake.yml file exists, at the very least
200
- definition_manager = DefinitionManager(target_directory)
201
- if not definition_manager.has_definition_file:
202
- raise MissingConfiguration(
203
- "Cannot find project definition (snowflake.yml). Please provide a path to the project or run this command in a valid project directory."
204
- )
205
-
206
- # 2. Change the project name in snowflake.yml if necessary
207
- _replace_snowflake_yml_name_with_project(
208
- target_directory=target_directory, project_identifier=project_identifier
209
- )
210
-
211
- # 3. Validate the Project Definition File(s)
212
- definition_manager.project_definition
213
-
214
-
215
- def _generate_project_name_from_path(p: Path):
216
- return re.sub(r"[. -]+", "_", p.name)
217
-
218
-
219
- def _init_from_template(
220
- project_path: Path,
221
- project_identifier: str,
222
- git_url: Optional[str],
223
- template: Optional[str],
224
- ):
225
- """
226
- Initialize a Snowflake Native App project with a git URL and optionally a specific template within the git URL.
227
-
228
- Args:
229
- project_path (Path): The directory of the user where the project will be added.
230
- project_identifier (str): The name of the project to be created, as a Snowflake identifier.
231
- git_url (str): The git URL to perform a clone from.
232
- template (str): A optional template within the git URL to use, all other directories and files outside the
233
- template will be discarded.
234
-
235
- Returns:
236
- None
237
- """
238
- use_whole_repo_as_template = git_url and not template
239
- if not use_whole_repo_as_template:
240
- git_url = git_url if git_url else OFFICIAL_TEMPLATES_GITHUB_URL
241
-
242
- try:
243
- with SecurePath.temporary_directory() as temp_path:
244
- from git import rmtree as git_rmtree
245
- from snowflake.cli.plugins.nativeapp.utils import shallow_git_clone
246
-
247
- shallow_git_clone(git_url, temp_path.path)
248
-
249
- if use_whole_repo_as_template:
250
- # the template is the entire git repository
251
- template_root = temp_path
252
- # Remove all git history before we move the repo
253
- git_rmtree((template_root / ".git").path)
254
- else:
255
- # The template is a subdirectory of the git repository
256
- template_name = template if template else BASIC_TEMPLATE
257
- template_root = temp_path / template_name
258
- if not template_root.path.is_dir():
259
- raise TemplateNotFoundError(template_name=template_name)
260
-
261
- if (template_root / "snowflake.yml.jinja").exists():
262
- # Render snowflake.yml file from its jinja template
263
- _render_snowflake_yml(
264
- parent_to_snowflake_yml=template_root.path,
265
- project_identifier=project_identifier,
266
- )
267
-
268
- # If not an official Snowflake Native App template
269
- if git_url != OFFICIAL_TEMPLATES_GITHUB_URL:
270
- _validate_and_update_snowflake_yml(
271
- target_directory=template_root.path,
272
- project_identifier=project_identifier,
273
- )
274
-
275
- project_path.parent.mkdir(parents=True, exist_ok=True)
276
-
277
- # Move the template to the specified path
278
- template_root.move(project_path)
279
-
280
- except TemplateNotFoundError:
281
- raise
282
- except Exception as err:
283
- # If there was any error, validation on Project Definition file or otherwise,
284
- # there should not be any Snowflake Native App Project left after this.
285
- if project_path.exists():
286
- SecurePath(project_path).rmdir(recursive=True)
287
-
288
- log.error(err)
289
- raise InitError()
290
-
291
-
292
- def nativeapp_init(
293
- path: str,
294
- name: Optional[str] = None,
295
- git_url: Optional[str] = None,
296
- template: Optional[str] = None,
297
- ) -> ProjectDescriptor:
298
- """
299
- Initialize a Snowflake Native App project in the user's current working directory, with or without the use of a template.
300
-
301
- Args:
302
- path (str): The location of the project to be created.
303
- name (str): Name of the project to be created.
304
- git_url (str): The git URL to perform a clone from.
305
- template (str): A template within the git URL to use, all other directories and files outside the template will be discarded.
306
-
307
- Returns:
308
- A project descriptor for the newly initialized project.
309
- """
310
- try:
311
- project_path = Path(path).expanduser().resolve()
312
- except Exception as err: # expanduser can fail
313
- raise InitError()
314
-
315
- # If a subdirectory with the same name as name exists in the current directory, fail init command
316
- if project_path.exists():
317
- raise DirectoryAlreadyExistsError(path)
318
-
319
- # Check if the specified path already exists in a Snowflake Native App project. Nesting projects is not allowed.
320
- if DefinitionManager.find_project_root(search_path=project_path.parent) is not None:
321
- raise CannotInitializeAnExistingProjectError()
322
-
323
- project_name = (
324
- name if name is not None else _generate_project_name_from_path(project_path)
325
- )
326
- if not project_name:
327
- # empty name
328
- raise ProjectNameInvalidError(project_name=project_name)
329
-
330
- if not is_valid_identifier(project_name) and (
331
- project_name.startswith('"') or project_name.endswith('"')
332
- ):
333
- # the project name looks like it was partially quoted. This is likely a mistake, reject it rather than
334
- # silently escaping it.
335
- raise ProjectNameInvalidError(project_name=project_name)
336
-
337
- project_identifier = to_identifier(project_name)
338
- _init_from_template(
339
- project_path=project_path,
340
- project_identifier=project_identifier,
341
- git_url=git_url,
342
- template=template,
343
- )
344
-
345
- return ProjectDescriptor(name=project_name, path=project_path)