snowflake-cli 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 (240) hide show
  1. snowflake/cli/__about__.py +17 -0
  2. snowflake/cli/__init__.py +13 -0
  3. snowflake/cli/api/__init__.py +48 -0
  4. snowflake/cli/api/cli_global_context.py +390 -0
  5. snowflake/cli/api/commands/__init__.py +13 -0
  6. snowflake/cli/api/commands/alias.py +23 -0
  7. snowflake/cli/api/commands/decorators.py +354 -0
  8. snowflake/cli/api/commands/execution_metadata.py +40 -0
  9. snowflake/cli/api/commands/experimental_behaviour.py +19 -0
  10. snowflake/cli/api/commands/flags.py +662 -0
  11. snowflake/cli/api/commands/project_initialisation.py +65 -0
  12. snowflake/cli/api/commands/snow_typer.py +237 -0
  13. snowflake/cli/api/commands/typer_pre_execute.py +26 -0
  14. snowflake/cli/api/config.py +348 -0
  15. snowflake/cli/api/console/__init__.py +17 -0
  16. snowflake/cli/api/console/abc.py +89 -0
  17. snowflake/cli/api/console/console.py +134 -0
  18. snowflake/cli/api/console/enum.py +17 -0
  19. snowflake/cli/api/constants.py +79 -0
  20. snowflake/cli/api/errno.py +27 -0
  21. snowflake/cli/api/exceptions.py +164 -0
  22. snowflake/cli/api/feature_flags.py +55 -0
  23. snowflake/cli/api/identifiers.py +167 -0
  24. snowflake/cli/api/output/__init__.py +13 -0
  25. snowflake/cli/api/output/formats.py +20 -0
  26. snowflake/cli/api/output/types.py +118 -0
  27. snowflake/cli/api/plugins/__init__.py +13 -0
  28. snowflake/cli/api/plugins/command/__init__.py +72 -0
  29. snowflake/cli/api/plugins/command/plugin_hook_specs.py +21 -0
  30. snowflake/cli/api/plugins/plugin_config.py +32 -0
  31. snowflake/cli/api/project/__init__.py +13 -0
  32. snowflake/cli/api/project/definition.py +84 -0
  33. snowflake/cli/api/project/definition_manager.py +134 -0
  34. snowflake/cli/api/project/errors.py +56 -0
  35. snowflake/cli/api/project/project_verification.py +23 -0
  36. snowflake/cli/api/project/schemas/__init__.py +13 -0
  37. snowflake/cli/api/project/schemas/entities/application_entity.py +44 -0
  38. snowflake/cli/api/project/schemas/entities/application_package_entity.py +66 -0
  39. snowflake/cli/api/project/schemas/entities/common.py +78 -0
  40. snowflake/cli/api/project/schemas/entities/entities.py +30 -0
  41. snowflake/cli/api/project/schemas/identifier_model.py +49 -0
  42. snowflake/cli/api/project/schemas/native_app/__init__.py +13 -0
  43. snowflake/cli/api/project/schemas/native_app/application.py +62 -0
  44. snowflake/cli/api/project/schemas/native_app/native_app.py +93 -0
  45. snowflake/cli/api/project/schemas/native_app/package.py +78 -0
  46. snowflake/cli/api/project/schemas/native_app/path_mapping.py +65 -0
  47. snowflake/cli/api/project/schemas/project_definition.py +199 -0
  48. snowflake/cli/api/project/schemas/snowpark/__init__.py +13 -0
  49. snowflake/cli/api/project/schemas/snowpark/argument.py +28 -0
  50. snowflake/cli/api/project/schemas/snowpark/callable.py +69 -0
  51. snowflake/cli/api/project/schemas/snowpark/snowpark.py +36 -0
  52. snowflake/cli/api/project/schemas/streamlit/__init__.py +13 -0
  53. snowflake/cli/api/project/schemas/streamlit/streamlit.py +46 -0
  54. snowflake/cli/api/project/schemas/template.py +77 -0
  55. snowflake/cli/api/project/schemas/updatable_model.py +194 -0
  56. snowflake/cli/api/project/util.py +261 -0
  57. snowflake/cli/api/rendering/__init__.py +13 -0
  58. snowflake/cli/api/rendering/jinja.py +112 -0
  59. snowflake/cli/api/rendering/project_definition_templates.py +39 -0
  60. snowflake/cli/api/rendering/project_templates.py +98 -0
  61. snowflake/cli/api/rendering/sql_templates.py +60 -0
  62. snowflake/cli/api/rest_api.py +172 -0
  63. snowflake/cli/api/sanitizers.py +43 -0
  64. snowflake/cli/api/secure_path.py +362 -0
  65. snowflake/cli/api/secure_utils.py +29 -0
  66. snowflake/cli/api/sql_execution.py +260 -0
  67. snowflake/cli/api/utils/__init__.py +13 -0
  68. snowflake/cli/api/utils/cursor.py +34 -0
  69. snowflake/cli/api/utils/definition_rendering.py +383 -0
  70. snowflake/cli/api/utils/dict_utils.py +73 -0
  71. snowflake/cli/api/utils/error_handling.py +23 -0
  72. snowflake/cli/api/utils/graph.py +97 -0
  73. snowflake/cli/api/utils/models.py +63 -0
  74. snowflake/cli/api/utils/naming_utils.py +13 -0
  75. snowflake/cli/api/utils/path_utils.py +36 -0
  76. snowflake/cli/api/utils/templating_functions.py +144 -0
  77. snowflake/cli/api/utils/types.py +35 -0
  78. snowflake/cli/app/__init__.py +22 -0
  79. snowflake/cli/app/__main__.py +31 -0
  80. snowflake/cli/app/api_impl/__init__.py +13 -0
  81. snowflake/cli/app/api_impl/plugin/__init__.py +13 -0
  82. snowflake/cli/app/api_impl/plugin/plugin_config_provider_impl.py +66 -0
  83. snowflake/cli/app/build_and_push.sh +8 -0
  84. snowflake/cli/app/cli_app.py +243 -0
  85. snowflake/cli/app/commands_registration/__init__.py +33 -0
  86. snowflake/cli/app/commands_registration/builtin_plugins.py +54 -0
  87. snowflake/cli/app/commands_registration/command_plugins_loader.py +169 -0
  88. snowflake/cli/app/commands_registration/commands_registration_with_callbacks.py +105 -0
  89. snowflake/cli/app/commands_registration/exception_logging.py +26 -0
  90. snowflake/cli/app/commands_registration/threadsafe.py +48 -0
  91. snowflake/cli/app/commands_registration/typer_registration.py +153 -0
  92. snowflake/cli/app/constants.py +19 -0
  93. snowflake/cli/app/dev/__init__.py +13 -0
  94. snowflake/cli/app/dev/commands_structure.py +48 -0
  95. snowflake/cli/app/dev/docs/__init__.py +13 -0
  96. snowflake/cli/app/dev/docs/commands_docs_generator.py +100 -0
  97. snowflake/cli/app/dev/docs/generator.py +35 -0
  98. snowflake/cli/app/dev/docs/project_definition_docs_generator.py +58 -0
  99. snowflake/cli/app/dev/docs/project_definition_generate_json_schema.py +227 -0
  100. snowflake/cli/app/dev/docs/template_utils.py +23 -0
  101. snowflake/cli/app/dev/docs/templates/definition_description.rst.jinja2 +38 -0
  102. snowflake/cli/app/dev/docs/templates/overview.rst.jinja2 +9 -0
  103. snowflake/cli/app/dev/docs/templates/usage.rst.jinja2 +57 -0
  104. snowflake/cli/app/dev/pycharm_remote_debug.py +46 -0
  105. snowflake/cli/app/loggers.py +199 -0
  106. snowflake/cli/app/main_typer.py +62 -0
  107. snowflake/cli/app/printing.py +181 -0
  108. snowflake/cli/app/snow_connector.py +243 -0
  109. snowflake/cli/app/telemetry.py +189 -0
  110. snowflake/cli/plugins/__init__.py +13 -0
  111. snowflake/cli/plugins/connection/__init__.py +13 -0
  112. snowflake/cli/plugins/connection/commands.py +330 -0
  113. snowflake/cli/plugins/connection/plugin_spec.py +30 -0
  114. snowflake/cli/plugins/connection/util.py +179 -0
  115. snowflake/cli/plugins/cortex/__init__.py +13 -0
  116. snowflake/cli/plugins/cortex/commands.py +327 -0
  117. snowflake/cli/plugins/cortex/constants.py +17 -0
  118. snowflake/cli/plugins/cortex/manager.py +189 -0
  119. snowflake/cli/plugins/cortex/plugin_spec.py +30 -0
  120. snowflake/cli/plugins/cortex/types.py +22 -0
  121. snowflake/cli/plugins/git/__init__.py +13 -0
  122. snowflake/cli/plugins/git/commands.py +354 -0
  123. snowflake/cli/plugins/git/manager.py +105 -0
  124. snowflake/cli/plugins/git/plugin_spec.py +30 -0
  125. snowflake/cli/plugins/init/__init__.py +13 -0
  126. snowflake/cli/plugins/init/commands.py +248 -0
  127. snowflake/cli/plugins/init/plugin_spec.py +30 -0
  128. snowflake/cli/plugins/nativeapp/__init__.py +13 -0
  129. snowflake/cli/plugins/nativeapp/artifacts.py +742 -0
  130. snowflake/cli/plugins/nativeapp/codegen/__init__.py +13 -0
  131. snowflake/cli/plugins/nativeapp/codegen/artifact_processor.py +91 -0
  132. snowflake/cli/plugins/nativeapp/codegen/compiler.py +130 -0
  133. snowflake/cli/plugins/nativeapp/codegen/sandbox.py +306 -0
  134. snowflake/cli/plugins/nativeapp/codegen/setup/native_app_setup_processor.py +172 -0
  135. snowflake/cli/plugins/nativeapp/codegen/setup/setup_driver.py.source +56 -0
  136. snowflake/cli/plugins/nativeapp/codegen/snowpark/callback_source.py.jinja +181 -0
  137. snowflake/cli/plugins/nativeapp/codegen/snowpark/extension_function_utils.py +217 -0
  138. snowflake/cli/plugins/nativeapp/codegen/snowpark/models.py +61 -0
  139. snowflake/cli/plugins/nativeapp/codegen/snowpark/python_processor.py +528 -0
  140. snowflake/cli/plugins/nativeapp/commands.py +439 -0
  141. snowflake/cli/plugins/nativeapp/common_flags.py +44 -0
  142. snowflake/cli/plugins/nativeapp/constants.py +27 -0
  143. snowflake/cli/plugins/nativeapp/exceptions.py +122 -0
  144. snowflake/cli/plugins/nativeapp/feature_flags.py +24 -0
  145. snowflake/cli/plugins/nativeapp/init.py +345 -0
  146. snowflake/cli/plugins/nativeapp/manager.py +823 -0
  147. snowflake/cli/plugins/nativeapp/plugin_spec.py +30 -0
  148. snowflake/cli/plugins/nativeapp/policy.py +50 -0
  149. snowflake/cli/plugins/nativeapp/project_model.py +195 -0
  150. snowflake/cli/plugins/nativeapp/run_processor.py +389 -0
  151. snowflake/cli/plugins/nativeapp/teardown_processor.py +301 -0
  152. snowflake/cli/plugins/nativeapp/utils.py +98 -0
  153. snowflake/cli/plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +135 -0
  154. snowflake/cli/plugins/nativeapp/version/__init__.py +13 -0
  155. snowflake/cli/plugins/nativeapp/version/commands.py +170 -0
  156. snowflake/cli/plugins/nativeapp/version/version_processor.py +362 -0
  157. snowflake/cli/plugins/notebook/__init__.py +13 -0
  158. snowflake/cli/plugins/notebook/commands.py +85 -0
  159. snowflake/cli/plugins/notebook/exceptions.py +20 -0
  160. snowflake/cli/plugins/notebook/manager.py +71 -0
  161. snowflake/cli/plugins/notebook/plugin_spec.py +30 -0
  162. snowflake/cli/plugins/notebook/types.py +15 -0
  163. snowflake/cli/plugins/object/__init__.py +13 -0
  164. snowflake/cli/plugins/object/command_aliases.py +95 -0
  165. snowflake/cli/plugins/object/commands.py +181 -0
  166. snowflake/cli/plugins/object/common.py +85 -0
  167. snowflake/cli/plugins/object/manager.py +97 -0
  168. snowflake/cli/plugins/object/plugin_spec.py +30 -0
  169. snowflake/cli/plugins/object_stage_deprecated/__init__.py +15 -0
  170. snowflake/cli/plugins/object_stage_deprecated/commands.py +122 -0
  171. snowflake/cli/plugins/object_stage_deprecated/plugin_spec.py +32 -0
  172. snowflake/cli/plugins/snowpark/__init__.py +13 -0
  173. snowflake/cli/plugins/snowpark/commands.py +546 -0
  174. snowflake/cli/plugins/snowpark/common.py +307 -0
  175. snowflake/cli/plugins/snowpark/manager.py +109 -0
  176. snowflake/cli/plugins/snowpark/models.py +157 -0
  177. snowflake/cli/plugins/snowpark/package/__init__.py +13 -0
  178. snowflake/cli/plugins/snowpark/package/anaconda_packages.py +233 -0
  179. snowflake/cli/plugins/snowpark/package/commands.py +256 -0
  180. snowflake/cli/plugins/snowpark/package/manager.py +44 -0
  181. snowflake/cli/plugins/snowpark/package/utils.py +26 -0
  182. snowflake/cli/plugins/snowpark/package_utils.py +354 -0
  183. snowflake/cli/plugins/snowpark/plugin_spec.py +30 -0
  184. snowflake/cli/plugins/snowpark/snowpark_package_paths.py +65 -0
  185. snowflake/cli/plugins/snowpark/snowpark_shared.py +95 -0
  186. snowflake/cli/plugins/snowpark/zipper.py +81 -0
  187. snowflake/cli/plugins/spcs/__init__.py +35 -0
  188. snowflake/cli/plugins/spcs/common.py +99 -0
  189. snowflake/cli/plugins/spcs/compute_pool/__init__.py +13 -0
  190. snowflake/cli/plugins/spcs/compute_pool/commands.py +241 -0
  191. snowflake/cli/plugins/spcs/compute_pool/manager.py +121 -0
  192. snowflake/cli/plugins/spcs/image_registry/__init__.py +13 -0
  193. snowflake/cli/plugins/spcs/image_registry/commands.py +65 -0
  194. snowflake/cli/plugins/spcs/image_registry/manager.py +105 -0
  195. snowflake/cli/plugins/spcs/image_repository/__init__.py +13 -0
  196. snowflake/cli/plugins/spcs/image_repository/commands.py +202 -0
  197. snowflake/cli/plugins/spcs/image_repository/manager.py +84 -0
  198. snowflake/cli/plugins/spcs/jobs/__init__.py +13 -0
  199. snowflake/cli/plugins/spcs/jobs/commands.py +78 -0
  200. snowflake/cli/plugins/spcs/jobs/manager.py +53 -0
  201. snowflake/cli/plugins/spcs/plugin_spec.py +30 -0
  202. snowflake/cli/plugins/spcs/services/__init__.py +13 -0
  203. snowflake/cli/plugins/spcs/services/commands.py +312 -0
  204. snowflake/cli/plugins/spcs/services/manager.py +170 -0
  205. snowflake/cli/plugins/sql/__init__.py +13 -0
  206. snowflake/cli/plugins/sql/commands.py +83 -0
  207. snowflake/cli/plugins/sql/manager.py +92 -0
  208. snowflake/cli/plugins/sql/plugin_spec.py +30 -0
  209. snowflake/cli/plugins/sql/snowsql_templating.py +28 -0
  210. snowflake/cli/plugins/stage/__init__.py +13 -0
  211. snowflake/cli/plugins/stage/commands.py +263 -0
  212. snowflake/cli/plugins/stage/diff.py +326 -0
  213. snowflake/cli/plugins/stage/manager.py +577 -0
  214. snowflake/cli/plugins/stage/md5.py +160 -0
  215. snowflake/cli/plugins/stage/plugin_spec.py +30 -0
  216. snowflake/cli/plugins/streamlit/__init__.py +13 -0
  217. snowflake/cli/plugins/streamlit/commands.py +179 -0
  218. snowflake/cli/plugins/streamlit/manager.py +222 -0
  219. snowflake/cli/plugins/streamlit/plugin_spec.py +30 -0
  220. snowflake/cli/plugins/workspace/__init__.py +13 -0
  221. snowflake/cli/plugins/workspace/commands.py +35 -0
  222. snowflake/cli/plugins/workspace/plugin_spec.py +30 -0
  223. snowflake/cli/templates/default_snowpark/.gitignore +4 -0
  224. snowflake/cli/templates/default_snowpark/app/__init__.py +0 -0
  225. snowflake/cli/templates/default_snowpark/app/common.py +2 -0
  226. snowflake/cli/templates/default_snowpark/app/functions.py +15 -0
  227. snowflake/cli/templates/default_snowpark/app/procedures.py +22 -0
  228. snowflake/cli/templates/default_snowpark/requirements.txt +1 -0
  229. snowflake/cli/templates/default_snowpark/snowflake.yml +23 -0
  230. snowflake/cli/templates/default_streamlit/.gitignore +4 -0
  231. snowflake/cli/templates/default_streamlit/common/hello.py +2 -0
  232. snowflake/cli/templates/default_streamlit/environment.yml +6 -0
  233. snowflake/cli/templates/default_streamlit/pages/my_page.py +3 -0
  234. snowflake/cli/templates/default_streamlit/snowflake.yml +10 -0
  235. snowflake/cli/templates/default_streamlit/streamlit_app.py +4 -0
  236. snowflake_cli-2.8.2.dist-info/METADATA +325 -0
  237. snowflake_cli-2.8.2.dist-info/RECORD +240 -0
  238. snowflake_cli-2.8.2.dist-info/WHEEL +4 -0
  239. snowflake_cli-2.8.2.dist-info/entry_points.txt +2 -0
  240. snowflake_cli-2.8.2.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,56 @@
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 textwrap import dedent
16
+
17
+ from click import ClickException
18
+ from pydantic import ValidationError
19
+
20
+
21
+ class SchemaValidationError(ClickException):
22
+ generic_message = "For field {location} you provided '{input}'. This caused: {msg}"
23
+ message_templates = {
24
+ "string_type": "{msg} for field '{location}', you provided '{input}'.",
25
+ "extra_forbidden": "{msg}. You provided field '{location}' with value '{input}' that is not supported in given version.",
26
+ "missing": "Your project definition is missing the following field: '{location}'",
27
+ }
28
+
29
+ def __init__(self, error: ValidationError):
30
+ errors = error.errors()
31
+ message = f"During evaluation of {error.title} in project definition following errors were encountered:\n"
32
+
33
+ def calculate_location(e):
34
+ if e["loc"] is None:
35
+ return None
36
+
37
+ # show numbers as list indexes and strings as dictionary keys. Example: key1[0].key2
38
+ result = "".join(
39
+ f"[{item}]" if isinstance(item, int) else f".{item}"
40
+ for item in e["loc"]
41
+ )
42
+
43
+ # remove leading dot from the string if any:
44
+ return result[1:] if result.startswith(".") else result
45
+
46
+ message += "\n".join(
47
+ [
48
+ self.message_templates.get(e["type"], self.generic_message).format(
49
+ **e,
50
+ location=calculate_location(e),
51
+ )
52
+ for e in errors
53
+ ]
54
+ )
55
+
56
+ super().__init__(dedent(message))
@@ -0,0 +1,23 @@
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.cli_global_context import cli_context
16
+ from snowflake.cli.api.exceptions import NoProjectDefinitionError
17
+
18
+
19
+ def assert_project_type(project_type: str):
20
+ if not getattr(cli_context.project_definition, project_type, None):
21
+ raise NoProjectDefinitionError(
22
+ project_type=project_type, project_file=cli_context.project_root
23
+ )
@@ -0,0 +1,13 @@
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.
@@ -0,0 +1,44 @@
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 typing import Literal, Optional
18
+
19
+ from pydantic import Field
20
+ from snowflake.cli.api.project.schemas.entities.application_package_entity import (
21
+ ApplicationPackageEntity,
22
+ )
23
+ from snowflake.cli.api.project.schemas.entities.common import (
24
+ EntityBase,
25
+ TargetField,
26
+ )
27
+ from snowflake.cli.api.project.schemas.updatable_model import (
28
+ DiscriminatorField,
29
+ )
30
+
31
+
32
+ class ApplicationEntity(EntityBase):
33
+ type: Literal["application"] = DiscriminatorField() # noqa A003
34
+ name: str = Field(
35
+ title="Name of the application created when this entity is deployed"
36
+ )
37
+ from_: TargetField[ApplicationPackageEntity] = Field(
38
+ alias="from",
39
+ title="An application package this entity should be created from",
40
+ )
41
+ debug: Optional[bool] = Field(
42
+ title="Whether to enable debug mode when using a named stage to create an application object",
43
+ default=None,
44
+ )
@@ -0,0 +1,66 @@
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
+ )
@@ -0,0 +1,78 @@
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 abc import ABC
18
+ from typing import Generic, List, Optional, TypeVar
19
+
20
+ from pydantic import Field
21
+ from snowflake.cli.api.project.schemas.native_app.application import (
22
+ PostDeployHook,
23
+ )
24
+ from snowflake.cli.api.project.schemas.updatable_model import (
25
+ IdentifierField,
26
+ UpdatableModel,
27
+ )
28
+
29
+
30
+ class MetaField(UpdatableModel):
31
+ warehouse: Optional[str] = IdentifierField(
32
+ title="Warehouse used to run the scripts", default=None
33
+ )
34
+ role: Optional[str] = IdentifierField(
35
+ title="Role to use when creating the entity object",
36
+ default=None,
37
+ )
38
+ post_deploy: Optional[List[PostDeployHook]] = Field(
39
+ title="Actions that will be executed after the application object is created/upgraded",
40
+ default=None,
41
+ )
42
+
43
+
44
+ class DefaultsField(UpdatableModel):
45
+ schema_: Optional[str] = Field(
46
+ title="Schema.",
47
+ alias="schema",
48
+ default=None,
49
+ )
50
+ stage: Optional[str] = Field(
51
+ title="Stage.",
52
+ default=None,
53
+ )
54
+
55
+
56
+ class EntityBase(ABC, UpdatableModel):
57
+ @classmethod
58
+ def get_type(cls) -> str:
59
+ return cls.model_fields["type"].annotation.__args__[0]
60
+
61
+ meta: Optional[MetaField] = Field(title="Meta fields", default=None)
62
+
63
+
64
+ TargetType = TypeVar("TargetType")
65
+
66
+
67
+ class TargetField(UpdatableModel, Generic[TargetType]):
68
+ target: str = Field(
69
+ title="Reference to a target entity",
70
+ )
71
+
72
+ def get_type(self) -> type:
73
+ """
74
+ Returns the generic type of this class, indicating the entity type.
75
+ Pydantic extracts Generic annotations, and populates
76
+ them in __pydantic_generic_metadata__
77
+ """
78
+ return self.__pydantic_generic_metadata__["args"][0]
@@ -0,0 +1,30 @@
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 typing import Union, get_args
18
+
19
+ from snowflake.cli.api.project.schemas.entities.application_entity import (
20
+ ApplicationEntity,
21
+ )
22
+ from snowflake.cli.api.project.schemas.entities.application_package_entity import (
23
+ ApplicationPackageEntity,
24
+ )
25
+
26
+ Entity = Union[ApplicationEntity, ApplicationPackageEntity]
27
+
28
+ ALL_ENTITIES = [*get_args(Entity)]
29
+
30
+ v2_entity_types_map = {e.get_type(): e for e in ALL_ENTITIES}
@@ -0,0 +1,49 @@
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 typing import Optional, cast
18
+
19
+ from pydantic import Field
20
+ from snowflake.cli.api.project.schemas.updatable_model import IdentifierField
21
+
22
+
23
+ class ObjectIdentifierBaseModel:
24
+ """
25
+ Type representing a base class defining object that can be identified by fully qualified name (db.schema.name).
26
+ This is not a Pydantic model and the purpose of this class is to provide typing support to Pydantic models
27
+ generated using a factory class ObjectIdentifierModel.
28
+ """
29
+
30
+ name: str
31
+ database: Optional[str]
32
+ schema_name: Optional[str]
33
+
34
+
35
+ def ObjectIdentifierModel(object_name: str) -> ObjectIdentifierBaseModel: # noqa: N802
36
+ """Generates ObjectIdentifierBaseModel but with object specific descriptions."""
37
+
38
+ class _ObjectIdentifierModel(ObjectIdentifierBaseModel):
39
+ name: str = Field(title=f"{object_name.capitalize()} name")
40
+ database: Optional[str] = IdentifierField(
41
+ title=f"Name of the database for the {object_name}", default=None
42
+ )
43
+ schema_name: Optional[str] = IdentifierField(
44
+ title=f"Name of the schema for the {object_name}",
45
+ default=None,
46
+ alias="schema",
47
+ )
48
+
49
+ return cast(ObjectIdentifierBaseModel, _ObjectIdentifierModel)
@@ -0,0 +1,13 @@
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.
@@ -0,0 +1,62 @@
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 typing import List, Optional
18
+
19
+ from pydantic import Field
20
+ from snowflake.cli.api.project.schemas.updatable_model import (
21
+ IdentifierField,
22
+ UpdatableModel,
23
+ )
24
+
25
+
26
+ class SqlScriptHookType(UpdatableModel):
27
+ sql_script: str = Field(title="SQL file path relative to the project root")
28
+
29
+
30
+ # Currently sql_script is the only supported hook type. Change to a Union once other hook types are added
31
+ PostDeployHook = SqlScriptHookType
32
+
33
+
34
+ class Application(UpdatableModel):
35
+ role: Optional[str] = Field(
36
+ title="Role to use when creating the application object and consumer-side objects",
37
+ default=None,
38
+ )
39
+ name: Optional[str] = Field(
40
+ title="Name of the application object created when you run the snow app run command",
41
+ default=None,
42
+ )
43
+ warehouse: Optional[str] = IdentifierField(
44
+ title="Name of the application object created when you run the snow app run command",
45
+ default=None,
46
+ )
47
+ debug: Optional[bool] = Field(
48
+ title="When set, forces debug_mode on/off for the deployed application object",
49
+ default=None,
50
+ )
51
+ post_deploy: Optional[List[PostDeployHook]] = Field(
52
+ title="Actions that will be executed after the application object is created/upgraded",
53
+ default=None,
54
+ )
55
+
56
+
57
+ class ApplicationV11(Application):
58
+ # Templated defaults only supported in v1.1+
59
+ name: Optional[str] = Field(
60
+ title="Name of the application object created when you run the snow app run command",
61
+ default="<% fn.concat_ids(ctx.native_app.name, '_', fn.sanitize_id(fn.get_username('unknown_user')) | lower) %>",
62
+ )
@@ -0,0 +1,93 @@
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 re
18
+ from typing import List, Optional, Union
19
+
20
+ from pydantic import Field, field_validator
21
+ from snowflake.cli.api.project.schemas.native_app.application import (
22
+ Application,
23
+ ApplicationV11,
24
+ )
25
+ from snowflake.cli.api.project.schemas.native_app.package import Package, PackageV11
26
+ from snowflake.cli.api.project.schemas.native_app.path_mapping import PathMapping
27
+ from snowflake.cli.api.project.schemas.updatable_model import UpdatableModel
28
+ from snowflake.cli.api.project.util import (
29
+ SCHEMA_AND_NAME,
30
+ )
31
+
32
+
33
+ class NativeApp(UpdatableModel):
34
+ name: str = Field(
35
+ title="Project identifier",
36
+ )
37
+ artifacts: List[Union[PathMapping, str]] = Field(
38
+ title="List of file source and destination pairs to add to the deploy root",
39
+ )
40
+ bundle_root: Optional[str] = Field(
41
+ title="Folder at the root of your project where artifacts necessary to perform the bundle step are stored.",
42
+ default="output/bundle/",
43
+ )
44
+ deploy_root: Optional[str] = Field(
45
+ title="Folder at the root of your project where the bundle step copies the artifacts.",
46
+ default="output/deploy/",
47
+ )
48
+ generated_root: Optional[str] = Field(
49
+ title="Subdirectory of the deploy root where files generated by the Snowflake CLI will be written.",
50
+ default="__generated/",
51
+ )
52
+ source_stage: Optional[str] = Field(
53
+ title="Identifier of the stage that stores the application artifacts.",
54
+ default="app_src.stage",
55
+ )
56
+ scratch_stage: Optional[str] = Field(
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
+ package: Optional[Package] = Field(title="PackageSchema", default=None)
61
+ application: Optional[Application] = Field(title="Application info", default=None)
62
+
63
+ @field_validator("source_stage")
64
+ @classmethod
65
+ def validate_source_stage(cls, input_value: str):
66
+ if not re.match(SCHEMA_AND_NAME, input_value):
67
+ raise ValueError("Incorrect value for source_stage value of native_app")
68
+ return input_value
69
+
70
+ @field_validator("artifacts")
71
+ @classmethod
72
+ def transform_artifacts(
73
+ cls, orig_artifacts: List[Union[PathMapping, str]]
74
+ ) -> List[PathMapping]:
75
+ transformed_artifacts = []
76
+ if orig_artifacts is None:
77
+ return transformed_artifacts
78
+
79
+ for artifact in orig_artifacts:
80
+ if isinstance(artifact, PathMapping):
81
+ transformed_artifacts.append(artifact)
82
+ else:
83
+ transformed_artifacts.append(PathMapping(src=artifact))
84
+
85
+ return transformed_artifacts
86
+
87
+
88
+ class NativeAppV11(NativeApp):
89
+ # templated defaults are only supported with version 1.1+
90
+ package: Optional[PackageV11] = Field(title="PackageSchema", default=PackageV11())
91
+ application: Optional[ApplicationV11] = Field(
92
+ title="Application info", default=ApplicationV11()
93
+ )
@@ -0,0 +1,78 @@
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 typing import List, Literal, Optional
18
+
19
+ from pydantic import Field, field_validator, model_validator
20
+ from snowflake.cli.api.project.schemas.native_app.application import PostDeployHook
21
+ from snowflake.cli.api.project.schemas.updatable_model import (
22
+ IdentifierField,
23
+ UpdatableModel,
24
+ )
25
+
26
+ DistributionOptions = Literal["internal", "external", "INTERNAL", "EXTERNAL"]
27
+
28
+
29
+ class Package(UpdatableModel):
30
+ scripts: Optional[List[str]] = Field(
31
+ title="List of SQL file paths relative to the project root", default=None
32
+ )
33
+ role: Optional[str] = IdentifierField(
34
+ title="Role to use when creating the application package and provider-side objects",
35
+ default=None,
36
+ )
37
+ name: Optional[str] = IdentifierField(
38
+ title="Name of the application package created when you run the snow app run command",
39
+ default=None,
40
+ )
41
+ warehouse: Optional[str] = IdentifierField(
42
+ title="Warehouse used to run the scripts", default=None
43
+ )
44
+ distribution: Optional[DistributionOptions] = Field(
45
+ title="Distribution of the application package created by the Snowflake CLI",
46
+ default="internal",
47
+ )
48
+ post_deploy: Optional[List[PostDeployHook]] = Field(
49
+ title="Actions that will be executed after the application package object is created/updated",
50
+ default=None,
51
+ )
52
+
53
+ @field_validator("scripts")
54
+ @classmethod
55
+ def validate_scripts(cls, input_list):
56
+ if len(input_list) != len(set(input_list)):
57
+ raise ValueError(
58
+ "package.scripts field should contain unique values. Check the list for duplicates and try again"
59
+ )
60
+ return input_list
61
+
62
+ @model_validator(mode="after")
63
+ @classmethod
64
+ def validate_no_scripts_and_post_deploy(cls, value: Package):
65
+ if value.scripts and value.post_deploy:
66
+ raise ValueError(
67
+ "package.scripts and package.post_deploy fields cannot be used together. "
68
+ "We recommend using package.post_deploy for all post package deploy scripts"
69
+ )
70
+ return value
71
+
72
+
73
+ class PackageV11(Package):
74
+ # Templated defaults only supported in v1.1+
75
+ name: Optional[str] = IdentifierField(
76
+ title="Name of the application package created when you run the snow app run command",
77
+ default="<% fn.concat_ids(ctx.native_app.name, '_pkg_', fn.sanitize_id(fn.get_username('unknown_user')) | lower) %>",
78
+ )
@@ -0,0 +1,65 @@
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 typing import Any, Dict, List, Optional, Union
18
+
19
+ from pydantic import Field, field_validator
20
+ from snowflake.cli.api.project.schemas.updatable_model import UpdatableModel
21
+
22
+
23
+ class ProcessorMapping(UpdatableModel):
24
+ name: str = Field(
25
+ title="Name of a processor to invoke on a collection of artifacts."
26
+ )
27
+ properties: Optional[Dict[str, Any]] = Field(
28
+ title="A set of key-value pairs used to configure the output of the processor. Consult a specific processor's documentation for more details on the supported properties.",
29
+ default=None,
30
+ )
31
+
32
+
33
+ class PathMapping(UpdatableModel):
34
+ src: str = Field(
35
+ title="Source path or glob pattern (relative to project root)", default=None
36
+ )
37
+
38
+ dest: Optional[str] = Field(
39
+ title="Destination path on stage",
40
+ description="Paths are relative to stage root; paths ending with a slash indicate that the destination is a directory which source files should be copied into.",
41
+ default=None,
42
+ )
43
+
44
+ processors: Optional[List[Union[str, ProcessorMapping]]] = Field(
45
+ title="List of processors to apply to matching source files during bundling.",
46
+ default=[],
47
+ )
48
+
49
+ @field_validator("processors")
50
+ @classmethod
51
+ def transform_processors(
52
+ cls, input_values: Optional[List[Union[str, Dict, ProcessorMapping]]]
53
+ ) -> List[ProcessorMapping]:
54
+ if input_values is None:
55
+ return []
56
+
57
+ transformed_processors: List[ProcessorMapping] = []
58
+ for input_processor in input_values:
59
+ if isinstance(input_processor, str):
60
+ transformed_processors.append(ProcessorMapping(name=input_processor))
61
+ elif isinstance(input_processor, Dict):
62
+ transformed_processors.append(ProcessorMapping(**input_processor))
63
+ else:
64
+ transformed_processors.append(input_processor)
65
+ return transformed_processors