snowflake-cli-labs 3.0.0rc5__py3-none-any.whl → 3.0.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 (244) hide show
  1. README.md +21 -0
  2. {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/METADATA +6 -96
  3. snowflake_cli_labs-3.0.2.dist-info/RECORD +5 -0
  4. snowflake/cli/__about__.py +0 -17
  5. snowflake/cli/__init__.py +0 -13
  6. snowflake/cli/_app/__init__.py +0 -22
  7. snowflake/cli/_app/__main__.py +0 -31
  8. snowflake/cli/_app/api_impl/__init__.py +0 -13
  9. snowflake/cli/_app/api_impl/plugin/__init__.py +0 -13
  10. snowflake/cli/_app/api_impl/plugin/plugin_config_provider_impl.py +0 -66
  11. snowflake/cli/_app/cli_app.py +0 -252
  12. snowflake/cli/_app/commands_registration/__init__.py +0 -33
  13. snowflake/cli/_app/commands_registration/builtin_plugins.py +0 -50
  14. snowflake/cli/_app/commands_registration/command_plugins_loader.py +0 -169
  15. snowflake/cli/_app/commands_registration/commands_registration_with_callbacks.py +0 -105
  16. snowflake/cli/_app/commands_registration/exception_logging.py +0 -26
  17. snowflake/cli/_app/commands_registration/threadsafe.py +0 -48
  18. snowflake/cli/_app/commands_registration/typer_registration.py +0 -153
  19. snowflake/cli/_app/constants.py +0 -19
  20. snowflake/cli/_app/dev/__init__.py +0 -13
  21. snowflake/cli/_app/dev/commands_structure.py +0 -48
  22. snowflake/cli/_app/dev/docs/__init__.py +0 -13
  23. snowflake/cli/_app/dev/docs/commands_docs_generator.py +0 -118
  24. snowflake/cli/_app/dev/docs/generator.py +0 -35
  25. snowflake/cli/_app/dev/docs/project_definition_docs_generator.py +0 -58
  26. snowflake/cli/_app/dev/docs/project_definition_generate_json_schema.py +0 -227
  27. snowflake/cli/_app/dev/docs/template_utils.py +0 -23
  28. snowflake/cli/_app/dev/docs/templates/definition_description.rst.jinja2 +0 -38
  29. snowflake/cli/_app/dev/docs/templates/overview.rst.jinja2 +0 -9
  30. snowflake/cli/_app/dev/docs/templates/usage.rst.jinja2 +0 -67
  31. snowflake/cli/_app/dev/pycharm_remote_debug.py +0 -46
  32. snowflake/cli/_app/loggers.py +0 -199
  33. snowflake/cli/_app/main_typer.py +0 -62
  34. snowflake/cli/_app/printing.py +0 -181
  35. snowflake/cli/_app/secret.py +0 -9
  36. snowflake/cli/_app/snow_connector.py +0 -309
  37. snowflake/cli/_app/telemetry.py +0 -220
  38. snowflake/cli/_app/version_check.py +0 -74
  39. snowflake/cli/_plugins/__init__.py +0 -13
  40. snowflake/cli/_plugins/connection/__init__.py +0 -13
  41. snowflake/cli/_plugins/connection/commands.py +0 -353
  42. snowflake/cli/_plugins/connection/plugin_spec.py +0 -30
  43. snowflake/cli/_plugins/connection/util.py +0 -195
  44. snowflake/cli/_plugins/cortex/__init__.py +0 -13
  45. snowflake/cli/_plugins/cortex/commands.py +0 -332
  46. snowflake/cli/_plugins/cortex/constants.py +0 -17
  47. snowflake/cli/_plugins/cortex/manager.py +0 -189
  48. snowflake/cli/_plugins/cortex/plugin_spec.py +0 -30
  49. snowflake/cli/_plugins/cortex/types.py +0 -22
  50. snowflake/cli/_plugins/git/__init__.py +0 -13
  51. snowflake/cli/_plugins/git/commands.py +0 -358
  52. snowflake/cli/_plugins/git/manager.py +0 -151
  53. snowflake/cli/_plugins/git/plugin_spec.py +0 -30
  54. snowflake/cli/_plugins/helpers/__init__.py +0 -13
  55. snowflake/cli/_plugins/helpers/commands.py +0 -90
  56. snowflake/cli/_plugins/helpers/plugin_spec.py +0 -30
  57. snowflake/cli/_plugins/init/__init__.py +0 -13
  58. snowflake/cli/_plugins/init/commands.py +0 -248
  59. snowflake/cli/_plugins/init/plugin_spec.py +0 -30
  60. snowflake/cli/_plugins/nativeapp/__init__.py +0 -13
  61. snowflake/cli/_plugins/nativeapp/artifacts.py +0 -757
  62. snowflake/cli/_plugins/nativeapp/bundle_context.py +0 -31
  63. snowflake/cli/_plugins/nativeapp/codegen/__init__.py +0 -13
  64. snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py +0 -91
  65. snowflake/cli/_plugins/nativeapp/codegen/compiler.py +0 -149
  66. snowflake/cli/_plugins/nativeapp/codegen/sandbox.py +0 -306
  67. snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -249
  68. snowflake/cli/_plugins/nativeapp/codegen/setup/setup_driver.py.source +0 -59
  69. snowflake/cli/_plugins/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -181
  70. snowflake/cli/_plugins/nativeapp/codegen/snowpark/extension_function_utils.py +0 -217
  71. snowflake/cli/_plugins/nativeapp/codegen/snowpark/models.py +0 -61
  72. snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py +0 -523
  73. snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +0 -114
  74. snowflake/cli/_plugins/nativeapp/commands.py +0 -559
  75. snowflake/cli/_plugins/nativeapp/common_flags.py +0 -44
  76. snowflake/cli/_plugins/nativeapp/constants.py +0 -27
  77. snowflake/cli/_plugins/nativeapp/entities/__init__.py +0 -0
  78. snowflake/cli/_plugins/nativeapp/entities/application.py +0 -878
  79. snowflake/cli/_plugins/nativeapp/entities/application_package.py +0 -1392
  80. snowflake/cli/_plugins/nativeapp/exceptions.py +0 -113
  81. snowflake/cli/_plugins/nativeapp/feature_flags.py +0 -24
  82. snowflake/cli/_plugins/nativeapp/manager.py +0 -415
  83. snowflake/cli/_plugins/nativeapp/plugin_spec.py +0 -30
  84. snowflake/cli/_plugins/nativeapp/policy.py +0 -53
  85. snowflake/cli/_plugins/nativeapp/project_model.py +0 -211
  86. snowflake/cli/_plugins/nativeapp/run_processor.py +0 -184
  87. snowflake/cli/_plugins/nativeapp/same_account_install_method.py +0 -70
  88. snowflake/cli/_plugins/nativeapp/teardown_processor.py +0 -70
  89. snowflake/cli/_plugins/nativeapp/utils.py +0 -98
  90. snowflake/cli/_plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -262
  91. snowflake/cli/_plugins/nativeapp/version/__init__.py +0 -13
  92. snowflake/cli/_plugins/nativeapp/version/commands.py +0 -141
  93. snowflake/cli/_plugins/nativeapp/version/version_processor.py +0 -98
  94. snowflake/cli/_plugins/notebook/__init__.py +0 -13
  95. snowflake/cli/_plugins/notebook/commands.py +0 -86
  96. snowflake/cli/_plugins/notebook/exceptions.py +0 -20
  97. snowflake/cli/_plugins/notebook/manager.py +0 -71
  98. snowflake/cli/_plugins/notebook/plugin_spec.py +0 -30
  99. snowflake/cli/_plugins/notebook/types.py +0 -15
  100. snowflake/cli/_plugins/object/__init__.py +0 -13
  101. snowflake/cli/_plugins/object/command_aliases.py +0 -95
  102. snowflake/cli/_plugins/object/commands.py +0 -180
  103. snowflake/cli/_plugins/object/common.py +0 -85
  104. snowflake/cli/_plugins/object/manager.py +0 -118
  105. snowflake/cli/_plugins/object/plugin_spec.py +0 -30
  106. snowflake/cli/_plugins/snowpark/__init__.py +0 -13
  107. snowflake/cli/_plugins/snowpark/commands.py +0 -450
  108. snowflake/cli/_plugins/snowpark/common.py +0 -268
  109. snowflake/cli/_plugins/snowpark/models.py +0 -150
  110. snowflake/cli/_plugins/snowpark/package/__init__.py +0 -13
  111. snowflake/cli/_plugins/snowpark/package/anaconda_packages.py +0 -199
  112. snowflake/cli/_plugins/snowpark/package/commands.py +0 -195
  113. snowflake/cli/_plugins/snowpark/package/manager.py +0 -44
  114. snowflake/cli/_plugins/snowpark/package/utils.py +0 -26
  115. snowflake/cli/_plugins/snowpark/package_utils.py +0 -354
  116. snowflake/cli/_plugins/snowpark/plugin_spec.py +0 -30
  117. snowflake/cli/_plugins/snowpark/snowpark_entity.py +0 -29
  118. snowflake/cli/_plugins/snowpark/snowpark_entity_model.py +0 -173
  119. snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +0 -109
  120. snowflake/cli/_plugins/snowpark/snowpark_shared.py +0 -59
  121. snowflake/cli/_plugins/snowpark/zipper.py +0 -89
  122. snowflake/cli/_plugins/spcs/__init__.py +0 -33
  123. snowflake/cli/_plugins/spcs/common.py +0 -99
  124. snowflake/cli/_plugins/spcs/compute_pool/__init__.py +0 -13
  125. snowflake/cli/_plugins/spcs/compute_pool/commands.py +0 -241
  126. snowflake/cli/_plugins/spcs/compute_pool/manager.py +0 -121
  127. snowflake/cli/_plugins/spcs/image_registry/__init__.py +0 -13
  128. snowflake/cli/_plugins/spcs/image_registry/commands.py +0 -65
  129. snowflake/cli/_plugins/spcs/image_registry/manager.py +0 -105
  130. snowflake/cli/_plugins/spcs/image_repository/__init__.py +0 -13
  131. snowflake/cli/_plugins/spcs/image_repository/commands.py +0 -202
  132. snowflake/cli/_plugins/spcs/image_repository/manager.py +0 -84
  133. snowflake/cli/_plugins/spcs/plugin_spec.py +0 -30
  134. snowflake/cli/_plugins/spcs/services/__init__.py +0 -13
  135. snowflake/cli/_plugins/spcs/services/commands.py +0 -345
  136. snowflake/cli/_plugins/spcs/services/manager.py +0 -208
  137. snowflake/cli/_plugins/sql/__init__.py +0 -13
  138. snowflake/cli/_plugins/sql/commands.py +0 -86
  139. snowflake/cli/_plugins/sql/manager.py +0 -92
  140. snowflake/cli/_plugins/sql/plugin_spec.py +0 -30
  141. snowflake/cli/_plugins/sql/snowsql_templating.py +0 -28
  142. snowflake/cli/_plugins/stage/__init__.py +0 -13
  143. snowflake/cli/_plugins/stage/commands.py +0 -264
  144. snowflake/cli/_plugins/stage/diff.py +0 -280
  145. snowflake/cli/_plugins/stage/manager.py +0 -582
  146. snowflake/cli/_plugins/stage/md5.py +0 -160
  147. snowflake/cli/_plugins/stage/plugin_spec.py +0 -30
  148. snowflake/cli/_plugins/stage/utils.py +0 -54
  149. snowflake/cli/_plugins/streamlit/__init__.py +0 -13
  150. snowflake/cli/_plugins/streamlit/commands.py +0 -195
  151. snowflake/cli/_plugins/streamlit/manager.py +0 -220
  152. snowflake/cli/_plugins/streamlit/plugin_spec.py +0 -30
  153. snowflake/cli/_plugins/streamlit/streamlit_entity.py +0 -12
  154. snowflake/cli/_plugins/streamlit/streamlit_entity_model.py +0 -66
  155. snowflake/cli/_plugins/workspace/__init__.py +0 -13
  156. snowflake/cli/_plugins/workspace/action_context.py +0 -18
  157. snowflake/cli/_plugins/workspace/commands.py +0 -306
  158. snowflake/cli/_plugins/workspace/manager.py +0 -74
  159. snowflake/cli/_plugins/workspace/plugin_spec.py +0 -30
  160. snowflake/cli/api/__init__.py +0 -48
  161. snowflake/cli/api/cli_global_context.py +0 -247
  162. snowflake/cli/api/commands/__init__.py +0 -13
  163. snowflake/cli/api/commands/alias.py +0 -23
  164. snowflake/cli/api/commands/common.py +0 -25
  165. snowflake/cli/api/commands/decorators.py +0 -369
  166. snowflake/cli/api/commands/execution_metadata.py +0 -40
  167. snowflake/cli/api/commands/experimental_behaviour.py +0 -18
  168. snowflake/cli/api/commands/flags.py +0 -561
  169. snowflake/cli/api/commands/overrideable_parameter.py +0 -143
  170. snowflake/cli/api/commands/snow_typer.py +0 -247
  171. snowflake/cli/api/commands/utils.py +0 -18
  172. snowflake/cli/api/config.py +0 -380
  173. snowflake/cli/api/connections.py +0 -216
  174. snowflake/cli/api/console/__init__.py +0 -17
  175. snowflake/cli/api/console/abc.py +0 -94
  176. snowflake/cli/api/console/console.py +0 -134
  177. snowflake/cli/api/console/enum.py +0 -17
  178. snowflake/cli/api/constants.py +0 -90
  179. snowflake/cli/api/entities/common.py +0 -56
  180. snowflake/cli/api/entities/utils.py +0 -370
  181. snowflake/cli/api/errno.py +0 -28
  182. snowflake/cli/api/exceptions.py +0 -190
  183. snowflake/cli/api/feature_flags.py +0 -54
  184. snowflake/cli/api/identifiers.py +0 -190
  185. snowflake/cli/api/metrics.py +0 -92
  186. snowflake/cli/api/output/__init__.py +0 -13
  187. snowflake/cli/api/output/formats.py +0 -20
  188. snowflake/cli/api/output/types.py +0 -118
  189. snowflake/cli/api/plugins/__init__.py +0 -13
  190. snowflake/cli/api/plugins/command/__init__.py +0 -72
  191. snowflake/cli/api/plugins/command/plugin_hook_specs.py +0 -21
  192. snowflake/cli/api/plugins/plugin_config.py +0 -32
  193. snowflake/cli/api/project/__init__.py +0 -13
  194. snowflake/cli/api/project/definition.py +0 -126
  195. snowflake/cli/api/project/definition_conversion.py +0 -400
  196. snowflake/cli/api/project/definition_manager.py +0 -145
  197. snowflake/cli/api/project/errors.py +0 -56
  198. snowflake/cli/api/project/project_verification.py +0 -23
  199. snowflake/cli/api/project/schemas/__init__.py +0 -13
  200. snowflake/cli/api/project/schemas/entities/__init__.py +0 -13
  201. snowflake/cli/api/project/schemas/entities/common.py +0 -153
  202. snowflake/cli/api/project/schemas/entities/entities.py +0 -61
  203. snowflake/cli/api/project/schemas/project_definition.py +0 -330
  204. snowflake/cli/api/project/schemas/template.py +0 -77
  205. snowflake/cli/api/project/schemas/updatable_model.py +0 -202
  206. snowflake/cli/api/project/schemas/v1/__init__.py +0 -0
  207. snowflake/cli/api/project/schemas/v1/identifier_model.py +0 -51
  208. snowflake/cli/api/project/schemas/v1/native_app/__init__.py +0 -0
  209. snowflake/cli/api/project/schemas/v1/native_app/application.py +0 -61
  210. snowflake/cli/api/project/schemas/v1/native_app/native_app.py +0 -93
  211. snowflake/cli/api/project/schemas/v1/native_app/package.py +0 -84
  212. snowflake/cli/api/project/schemas/v1/native_app/path_mapping.py +0 -65
  213. snowflake/cli/api/project/schemas/v1/snowpark/__init__.py +0 -0
  214. snowflake/cli/api/project/schemas/v1/snowpark/argument.py +0 -28
  215. snowflake/cli/api/project/schemas/v1/snowpark/callable.py +0 -69
  216. snowflake/cli/api/project/schemas/v1/snowpark/snowpark.py +0 -36
  217. snowflake/cli/api/project/schemas/v1/streamlit/__init__.py +0 -0
  218. snowflake/cli/api/project/schemas/v1/streamlit/streamlit.py +0 -47
  219. snowflake/cli/api/project/util.py +0 -278
  220. snowflake/cli/api/rendering/__init__.py +0 -13
  221. snowflake/cli/api/rendering/jinja.py +0 -118
  222. snowflake/cli/api/rendering/project_definition_templates.py +0 -43
  223. snowflake/cli/api/rendering/project_templates.py +0 -98
  224. snowflake/cli/api/rendering/sql_templates.py +0 -105
  225. snowflake/cli/api/rest_api.py +0 -178
  226. snowflake/cli/api/sanitizers.py +0 -43
  227. snowflake/cli/api/secure_path.py +0 -360
  228. snowflake/cli/api/secure_utils.py +0 -118
  229. snowflake/cli/api/sql_execution.py +0 -280
  230. snowflake/cli/api/utils/__init__.py +0 -13
  231. snowflake/cli/api/utils/cursor.py +0 -34
  232. snowflake/cli/api/utils/definition_rendering.py +0 -415
  233. snowflake/cli/api/utils/dict_utils.py +0 -73
  234. snowflake/cli/api/utils/error_handling.py +0 -23
  235. snowflake/cli/api/utils/graph.py +0 -97
  236. snowflake/cli/api/utils/models.py +0 -63
  237. snowflake/cli/api/utils/naming_utils.py +0 -13
  238. snowflake/cli/api/utils/path_utils.py +0 -36
  239. snowflake/cli/api/utils/templating_functions.py +0 -144
  240. snowflake/cli/api/utils/types.py +0 -35
  241. snowflake_cli_labs-3.0.0rc5.dist-info/RECORD +0 -242
  242. snowflake_cli_labs-3.0.0rc5.dist-info/entry_points.txt +0 -2
  243. {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/WHEEL +0 -0
  244. {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/licenses/LICENSE +0 -0
@@ -1,211 +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 functools import cached_property
18
- from pathlib import Path
19
- from typing import List, Optional
20
-
21
- from snowflake.cli._plugins.nativeapp.artifacts import resolve_without_follow
22
- from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext
23
- from snowflake.cli.api.cli_global_context import get_cli_context
24
- from snowflake.cli.api.entities.common import get_sql_executor
25
- from snowflake.cli.api.project.definition import (
26
- default_app_package,
27
- default_application,
28
- default_role,
29
- )
30
- from snowflake.cli.api.project.schemas.entities.common import PostDeployHook
31
- from snowflake.cli.api.project.schemas.v1.native_app.native_app import NativeApp
32
- from snowflake.cli.api.project.schemas.v1.native_app.path_mapping import PathMapping
33
- from snowflake.cli.api.project.util import (
34
- append_test_resource_suffix,
35
- extract_schema,
36
- to_identifier,
37
- )
38
-
39
-
40
- class NativeAppProjectModel:
41
- """
42
- Exposes properties of a native app project defined in a Snowflake Project Definition file. Whenever
43
- appropriate, APIs defined in this class provide suitable defaults or fallback logic to access properties
44
- of the project.
45
- """
46
-
47
- def __init__(
48
- self,
49
- project_definition: NativeApp,
50
- project_root: Path,
51
- ):
52
- self._project_definition = project_definition
53
- self._project_root = resolve_without_follow(project_root)
54
-
55
- @property
56
- def project_root(self) -> Path:
57
- return self._project_root
58
-
59
- @property
60
- def definition(self) -> NativeApp:
61
- return self._project_definition
62
-
63
- @cached_property
64
- def artifacts(self) -> List[PathMapping]:
65
- return self.definition.artifacts
66
-
67
- @cached_property
68
- def bundle_root(self) -> Path:
69
- return self.project_root / self.definition.bundle_root
70
-
71
- @cached_property
72
- def deploy_root(self) -> Path:
73
- return self.project_root / self.definition.deploy_root
74
-
75
- @cached_property
76
- def generated_root(self) -> Path:
77
- return self.deploy_root / self.definition.generated_root
78
-
79
- @cached_property
80
- def package_scripts(self) -> List[str]:
81
- """
82
- Relative paths to package scripts from the project root.
83
- """
84
- if self.definition.package and self.definition.package.scripts:
85
- return self.definition.package.scripts
86
- else:
87
- return []
88
-
89
- @cached_property
90
- def stage_fqn(self) -> str:
91
- return f"{self.package_name}.{self.definition.source_stage}"
92
-
93
- @cached_property
94
- def scratch_stage_fqn(self) -> str:
95
- return f"{self.package_name}.{self.definition.scratch_stage}"
96
-
97
- @cached_property
98
- def stage_schema(self) -> Optional[str]:
99
- return extract_schema(self.stage_fqn)
100
-
101
- @cached_property
102
- def package_warehouse(self) -> Optional[str]:
103
- if self.definition.package and self.definition.package.warehouse:
104
- return to_identifier(self.definition.package.warehouse)
105
- else:
106
- cli_context = get_cli_context()
107
- if cli_context.connection.warehouse:
108
- return to_identifier(cli_context.connection.warehouse)
109
- return None
110
-
111
- @cached_property
112
- def application_warehouse(self) -> Optional[str]:
113
- if self.definition.application and self.definition.application.warehouse:
114
- return to_identifier(self.definition.application.warehouse)
115
- else:
116
- cli_context = get_cli_context()
117
- if cli_context.connection.warehouse:
118
- return to_identifier(cli_context.connection.warehouse)
119
- return None
120
-
121
- @cached_property
122
- def project_identifier(self) -> str:
123
- # name is expected to be a valid Snowflake identifier, but YAML parsers will
124
- # sometimes strip out double quotes, so we try to get them back here.
125
- return to_identifier(self.definition.name)
126
-
127
- @property
128
- def package_name(self) -> str:
129
- if self.definition.package and self.definition.package.name:
130
- return to_identifier(self.definition.package.name)
131
- else:
132
- # V1.0 PDF doesn't support templating, so if the identifier isn't
133
- # explicitly specified, the default is generated here,
134
- # so we have to append the test resource suffix here
135
- name = default_app_package(self.project_identifier)
136
- return to_identifier(append_test_resource_suffix(name))
137
-
138
- @cached_property
139
- def package_role(self) -> str:
140
- if self.definition.package and self.definition.package.role:
141
- return self.definition.package.role
142
- else:
143
- return self._default_role
144
-
145
- @cached_property
146
- def package_distribution(self) -> str:
147
- if self.definition.package and self.definition.package.distribution:
148
- return self.definition.package.distribution.lower()
149
- else:
150
- return "internal"
151
-
152
- @property
153
- def app_name(self) -> str:
154
- if self.definition.application and self.definition.application.name:
155
- return to_identifier(self.definition.application.name)
156
- else:
157
- # V1.0 PDF doesn't support templating, so if the identifier isn't
158
- # explicitly specified, the default is generated here,
159
- # so we have to append the test resource suffix here
160
- name = default_application(self.project_identifier)
161
- return to_identifier(append_test_resource_suffix(name))
162
-
163
- @cached_property
164
- def app_role(self) -> str:
165
- if self.definition.application and self.definition.application.role:
166
- return self.definition.application.role
167
- else:
168
- return self._default_role
169
-
170
- @cached_property
171
- def app_post_deploy_hooks(self) -> Optional[List[PostDeployHook]]:
172
- """
173
- List of application instance post deploy hooks.
174
- """
175
- if self.definition.application and self.definition.application.post_deploy:
176
- return self.definition.application.post_deploy
177
- else:
178
- return None
179
-
180
- @cached_property
181
- def package_post_deploy_hooks(self) -> Optional[List[PostDeployHook]]:
182
- """
183
- List of application package post deploy hooks.
184
- """
185
- if self.definition.package and self.definition.package.post_deploy:
186
- return self.definition.package.post_deploy
187
- else:
188
- return None
189
-
190
- @cached_property
191
- def _default_role(self) -> str:
192
- role = default_role()
193
- if role is None:
194
- role = get_sql_executor().current_role()
195
- return role
196
-
197
- @cached_property
198
- def debug_mode(self) -> Optional[bool]:
199
- if self.definition.application:
200
- return self.definition.application.debug
201
- return None
202
-
203
- def get_bundle_context(self) -> BundleContext:
204
- return BundleContext(
205
- package_name=self.package_name,
206
- artifacts=self.artifacts,
207
- project_root=self.project_root,
208
- bundle_root=self.bundle_root,
209
- deploy_root=self.deploy_root,
210
- generated_root=self.generated_root,
211
- )
@@ -1,184 +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 Optional
19
-
20
- import typer
21
- from snowflake.cli._plugins.nativeapp.artifacts import BundleMap
22
- from snowflake.cli._plugins.nativeapp.entities.application import ApplicationEntity
23
- from snowflake.cli._plugins.nativeapp.entities.application_package import (
24
- ApplicationPackageEntity,
25
- )
26
- from snowflake.cli._plugins.nativeapp.manager import (
27
- NativeAppCommandProcessor,
28
- NativeAppManager,
29
- )
30
- from snowflake.cli._plugins.nativeapp.policy import PolicyBase
31
- from snowflake.cli._plugins.nativeapp.same_account_install_method import (
32
- SameAccountInstallMethod,
33
- )
34
- from snowflake.cli.api.console import cli_console as cc
35
- from snowflake.cli.api.entities.common import get_sql_executor
36
- from snowflake.cli.api.entities.utils import (
37
- generic_sql_error_handler,
38
- )
39
- from snowflake.cli.api.errno import (
40
- APPLICATION_NO_LONGER_AVAILABLE,
41
- APPLICATION_OWNS_EXTERNAL_OBJECTS,
42
- )
43
- from snowflake.cli.api.project.schemas.v1.native_app.native_app import NativeApp
44
- from snowflake.connector import ProgrammingError
45
- from snowflake.connector.cursor import SnowflakeCursor
46
-
47
-
48
- class NativeAppRunProcessor(NativeAppManager, NativeAppCommandProcessor):
49
- def __init__(self, project_definition: NativeApp, project_root: Path):
50
- super().__init__(project_definition, project_root)
51
-
52
- def get_all_existing_versions(self) -> SnowflakeCursor:
53
- return ApplicationPackageEntity.version_list(
54
- self.package_name, self.package_role
55
- )
56
-
57
- def get_existing_version_info(self, version: str) -> Optional[dict]:
58
- return ApplicationPackageEntity.get_existing_version_info(
59
- version=version,
60
- package_name=self.package_name,
61
- package_role=self.package_role,
62
- )
63
-
64
- def drop_application_before_upgrade(
65
- self, policy: PolicyBase, is_interactive: bool, cascade: bool = False
66
- ):
67
- """
68
- This method will attempt to drop an application object if a previous upgrade fails.
69
- """
70
- if cascade:
71
- try:
72
- if application_objects := self.get_objects_owned_by_application():
73
- application_objects_str = self._application_objects_to_str(
74
- application_objects
75
- )
76
- cc.message(
77
- f"The following objects are owned by application {self.app_name} and need to be dropped:\n{application_objects_str}"
78
- )
79
- except ProgrammingError as err:
80
- if err.errno != APPLICATION_NO_LONGER_AVAILABLE:
81
- generic_sql_error_handler(err)
82
- cc.warning(
83
- "The application owns other objects but they could not be determined."
84
- )
85
- user_prompt = "Do you want the Snowflake CLI to drop these objects, then drop the existing application object and recreate it?"
86
- else:
87
- user_prompt = "Do you want the Snowflake CLI to drop the existing application object and recreate it?"
88
-
89
- if not policy.should_proceed(user_prompt):
90
- if is_interactive:
91
- cc.message("Not upgrading the application object.")
92
- raise typer.Exit(0)
93
- else:
94
- cc.message(
95
- "Cannot upgrade the application object non-interactively without --force."
96
- )
97
- raise typer.Exit(1)
98
- try:
99
- cascade_msg = " (cascade)" if cascade else ""
100
- cc.step(f"Dropping application object {self.app_name}{cascade_msg}.")
101
- cascade_sql = " cascade" if cascade else ""
102
- sql_executor = get_sql_executor()
103
- sql_executor.execute_query(f"drop application {self.app_name}{cascade_sql}")
104
- except ProgrammingError as err:
105
- if err.errno == APPLICATION_OWNS_EXTERNAL_OBJECTS and not cascade:
106
- # We need to cascade the deletion, let's try again (only if we didn't try with cascade already)
107
- return self.drop_application_before_upgrade(
108
- policy, is_interactive, cascade=True
109
- )
110
- else:
111
- generic_sql_error_handler(err)
112
-
113
- def create_or_upgrade_app(
114
- self,
115
- policy: PolicyBase,
116
- install_method: SameAccountInstallMethod,
117
- is_interactive: bool = False,
118
- ):
119
- def drop_app():
120
- self.drop_application_before_upgrade(policy, is_interactive)
121
-
122
- return ApplicationEntity.create_or_upgrade_app(
123
- console=cc,
124
- project_root=self.project_root,
125
- package_name=self.package_name,
126
- package_role=self.package_role,
127
- app_name=self.app_name,
128
- app_role=self.app_role,
129
- app_warehouse=self.application_warehouse,
130
- stage_schema=self.stage_schema,
131
- stage_fqn=self.stage_fqn,
132
- debug_mode=self.debug_mode,
133
- policy=policy,
134
- install_method=install_method,
135
- is_interactive=is_interactive,
136
- post_deploy_hooks=self.app_post_deploy_hooks,
137
- drop_application_before_upgrade=drop_app,
138
- )
139
-
140
- def process(
141
- self,
142
- bundle_map: BundleMap,
143
- policy: PolicyBase,
144
- version: Optional[str] = None,
145
- patch: Optional[int] = None,
146
- from_release_directive: bool = False,
147
- is_interactive: bool = False,
148
- validate: bool = True,
149
- *args,
150
- **kwargs,
151
- ):
152
- def deploy_package():
153
- self.deploy(
154
- bundle_map=bundle_map,
155
- prune=True,
156
- recursive=True,
157
- validate=validate,
158
- policy=policy,
159
- )
160
-
161
- def drop_app():
162
- self.drop_application_before_upgrade(policy, is_interactive)
163
-
164
- ApplicationEntity.deploy(
165
- console=cc,
166
- project_root=self.project_root,
167
- app_name=self.app_name,
168
- app_role=self.app_role,
169
- app_warehouse=self.application_warehouse,
170
- package_name=self.package_name,
171
- package_role=self.package_role,
172
- stage_schema=self.stage_schema,
173
- stage_fqn=self.stage_fqn,
174
- debug_mode=self.debug_mode,
175
- validate=validate,
176
- from_release_directive=from_release_directive,
177
- is_interactive=is_interactive,
178
- policy=policy,
179
- version=version,
180
- patch=patch,
181
- post_deploy_hooks=self.app_post_deploy_hooks,
182
- deploy_package=deploy_package,
183
- drop_application_before_upgrade=drop_app,
184
- )
@@ -1,70 +0,0 @@
1
- from typing import Optional
2
-
3
- from snowflake.cli._plugins.nativeapp.constants import (
4
- ALLOWED_SPECIAL_COMMENTS,
5
- COMMENT_COL,
6
- )
7
- from snowflake.cli._plugins.nativeapp.exceptions import (
8
- ApplicationCreatedExternallyError,
9
- )
10
-
11
- # from snowflake.cli._plugins.nativeapp.project_model import NativeAppProjectModel
12
- from snowflake.cli._plugins.stage.manager import StageManager
13
-
14
-
15
- class SameAccountInstallMethod:
16
- _requires_created_by_cli: bool
17
- _from_release_directive: bool
18
- version: Optional[str]
19
- patch: Optional[int]
20
-
21
- def __init__(
22
- self,
23
- requires_created_by_cli: bool,
24
- version: Optional[str] = None,
25
- patch: Optional[int] = None,
26
- from_release_directive: bool = False,
27
- ):
28
- self._requires_created_by_cli = requires_created_by_cli
29
- self.version = version
30
- self.patch = patch
31
- self._from_release_directive = from_release_directive
32
-
33
- @classmethod
34
- def unversioned_dev(cls):
35
- """aka. stage dev aka loose files"""
36
- return cls(True)
37
-
38
- @classmethod
39
- def versioned_dev(cls, version: str, patch: Optional[int] = None):
40
- return cls(False, version, patch)
41
-
42
- @classmethod
43
- def release_directive(cls):
44
- return cls(False, from_release_directive=True)
45
-
46
- @property
47
- def is_dev_mode(self) -> bool:
48
- return not self._from_release_directive
49
-
50
- def using_clause(
51
- self,
52
- stage_fqn: str,
53
- ) -> str:
54
- if self._from_release_directive:
55
- return ""
56
-
57
- if self.version:
58
- patch_clause = f"patch {self.patch}" if self.patch else ""
59
- return f"using version {self.version} {patch_clause}"
60
-
61
- stage_name = StageManager.quote_stage_name(stage_fqn)
62
- return f"using {stage_name}"
63
-
64
- def ensure_app_usable(self, app_name: str, app_role: str, show_app_row: dict):
65
- """Raise an exception if we cannot proceed with install given the pre-existing application object"""
66
-
67
- if self._requires_created_by_cli:
68
- if show_app_row[COMMENT_COL] not in ALLOWED_SPECIAL_COMMENTS:
69
- # this application object was not created by this tooling
70
- raise ApplicationCreatedExternallyError(app_name)
@@ -1,70 +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 Dict, Optional
19
-
20
- from snowflake.cli._plugins.nativeapp.entities.application import ApplicationEntity
21
- from snowflake.cli._plugins.nativeapp.entities.application_package import (
22
- ApplicationPackageEntity,
23
- )
24
- from snowflake.cli._plugins.nativeapp.manager import (
25
- NativeAppCommandProcessor,
26
- NativeAppManager,
27
- )
28
- from snowflake.cli.api.console import cli_console as cc
29
-
30
-
31
- class NativeAppTeardownProcessor(NativeAppManager, NativeAppCommandProcessor):
32
- def __init__(self, project_definition: Dict, project_root: Path):
33
- super().__init__(project_definition, project_root)
34
-
35
- def drop_application(
36
- self, auto_yes: bool, interactive: bool = False, cascade: Optional[bool] = None
37
- ):
38
- return ApplicationEntity.drop(
39
- console=cc,
40
- app_name=self.app_name,
41
- app_role=self.app_role,
42
- auto_yes=auto_yes,
43
- interactive=interactive,
44
- cascade=cascade,
45
- )
46
-
47
- def drop_package(self, auto_yes: bool):
48
- return ApplicationPackageEntity.drop(
49
- console=cc,
50
- package_name=self.package_name,
51
- package_role=self.package_role,
52
- force_drop=auto_yes,
53
- )
54
-
55
- def process(
56
- self,
57
- interactive: bool,
58
- force_drop: bool = False,
59
- cascade: Optional[bool] = None,
60
- *args,
61
- **kwargs,
62
- ):
63
-
64
- # Drop the application object
65
- self.drop_application(
66
- auto_yes=force_drop, interactive=interactive, cascade=cascade
67
- )
68
-
69
- # Drop the application package
70
- self.drop_package(auto_yes=force_drop)
@@ -1,98 +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 os
18
- from pathlib import Path
19
- from sys import stdin, stdout
20
- from typing import Iterable, Optional, Union
21
-
22
- from click import ClickException
23
-
24
-
25
- def needs_confirmation(needs_confirm: bool, auto_yes: bool) -> bool:
26
- return needs_confirm and not auto_yes
27
-
28
-
29
- def is_tty_interactive():
30
- return stdin.isatty() and stdout.isatty()
31
-
32
-
33
- def get_first_paragraph_from_markdown_file(file_path: Path) -> Optional[str]:
34
- """
35
- Reads a Markdown file at the given file path and finds the first paragraph
36
-
37
- Parameters:
38
- file_path (Path): Path to Markdown file
39
-
40
- Returns:
41
- Optional[str]: the first paragraph as a string, or None
42
- if no paragraph could be found
43
-
44
- Raises:
45
- FileNotFoundError: if file_path to Markdown file does not exist
46
- """
47
- if not file_path.exists():
48
- raise FileNotFoundError(file_path)
49
-
50
- with open(file_path, "r") as markdown_file:
51
- paragraph_text = None
52
-
53
- for line in markdown_file:
54
- stripped_line = line.strip()
55
- if not stripped_line.startswith("#") and stripped_line:
56
- paragraph_text = stripped_line
57
- break
58
-
59
- return paragraph_text
60
-
61
-
62
- def shallow_git_clone(url: Union[str, os.PathLike], to_path: Union[str, os.PathLike]):
63
- """
64
- Performs a shallow clone of the repository at the provided url to the path specified
65
-
66
- Parameters:
67
- url (str | PathLike): Valid git url.
68
- to_path (str | PathLike): Path to which the repository should be cloned to.
69
-
70
- Returns:
71
- Repo: the repository that was cloned
72
- """
73
- from git import Repo
74
-
75
- # Clone the repository in the directory with options.
76
- repo = Repo.clone_from(
77
- url=url,
78
- to_path=to_path,
79
- filter=["tree:0"],
80
- depth=1,
81
- )
82
- # Close repo to avoid issues with permissions on Windows
83
- repo.close()
84
-
85
- return repo
86
-
87
-
88
- def verify_no_directories(paths_to_sync: Iterable[Path]):
89
- for path in paths_to_sync:
90
- if path.is_dir():
91
- raise ClickException(
92
- f"{path} is a directory. Add the -r flag to deploy directories." #
93
- )
94
-
95
-
96
- def verify_exists(path: Path):
97
- if not path.exists():
98
- raise ClickException(f"The following path does not exist: {path}")