snowflake-cli-labs 2.8.0rc1__py3-none-any.whl → 2.8.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. README.md +21 -0
  2. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-2.8.2.dist-info}/METADATA +7 -95
  3. snowflake_cli_labs-2.8.2.dist-info/RECORD +5 -0
  4. snowflake/cli/__about__.py +0 -17
  5. snowflake/cli/__init__.py +0 -13
  6. snowflake/cli/api/__init__.py +0 -48
  7. snowflake/cli/api/cli_global_context.py +0 -390
  8. snowflake/cli/api/commands/__init__.py +0 -13
  9. snowflake/cli/api/commands/alias.py +0 -23
  10. snowflake/cli/api/commands/decorators.py +0 -354
  11. snowflake/cli/api/commands/execution_metadata.py +0 -40
  12. snowflake/cli/api/commands/experimental_behaviour.py +0 -19
  13. snowflake/cli/api/commands/flags.py +0 -640
  14. snowflake/cli/api/commands/project_initialisation.py +0 -65
  15. snowflake/cli/api/commands/snow_typer.py +0 -237
  16. snowflake/cli/api/commands/typer_pre_execute.py +0 -26
  17. snowflake/cli/api/config.py +0 -348
  18. snowflake/cli/api/console/__init__.py +0 -17
  19. snowflake/cli/api/console/abc.py +0 -89
  20. snowflake/cli/api/console/console.py +0 -134
  21. snowflake/cli/api/console/enum.py +0 -17
  22. snowflake/cli/api/constants.py +0 -79
  23. snowflake/cli/api/errno.py +0 -27
  24. snowflake/cli/api/exceptions.py +0 -164
  25. snowflake/cli/api/feature_flags.py +0 -55
  26. snowflake/cli/api/identifiers.py +0 -154
  27. snowflake/cli/api/output/__init__.py +0 -13
  28. snowflake/cli/api/output/formats.py +0 -20
  29. snowflake/cli/api/output/types.py +0 -118
  30. snowflake/cli/api/plugins/__init__.py +0 -13
  31. snowflake/cli/api/plugins/command/__init__.py +0 -72
  32. snowflake/cli/api/plugins/command/plugin_hook_specs.py +0 -21
  33. snowflake/cli/api/plugins/plugin_config.py +0 -32
  34. snowflake/cli/api/project/__init__.py +0 -13
  35. snowflake/cli/api/project/definition.py +0 -84
  36. snowflake/cli/api/project/definition_manager.py +0 -134
  37. snowflake/cli/api/project/errors.py +0 -56
  38. snowflake/cli/api/project/project_verification.py +0 -23
  39. snowflake/cli/api/project/schemas/__init__.py +0 -13
  40. snowflake/cli/api/project/schemas/entities/application_entity.py +0 -44
  41. snowflake/cli/api/project/schemas/entities/application_package_entity.py +0 -66
  42. snowflake/cli/api/project/schemas/entities/common.py +0 -78
  43. snowflake/cli/api/project/schemas/entities/entities.py +0 -30
  44. snowflake/cli/api/project/schemas/identifier_model.py +0 -49
  45. snowflake/cli/api/project/schemas/native_app/__init__.py +0 -13
  46. snowflake/cli/api/project/schemas/native_app/application.py +0 -62
  47. snowflake/cli/api/project/schemas/native_app/native_app.py +0 -93
  48. snowflake/cli/api/project/schemas/native_app/package.py +0 -78
  49. snowflake/cli/api/project/schemas/native_app/path_mapping.py +0 -65
  50. snowflake/cli/api/project/schemas/project_definition.py +0 -199
  51. snowflake/cli/api/project/schemas/snowpark/__init__.py +0 -13
  52. snowflake/cli/api/project/schemas/snowpark/argument.py +0 -28
  53. snowflake/cli/api/project/schemas/snowpark/callable.py +0 -69
  54. snowflake/cli/api/project/schemas/snowpark/snowpark.py +0 -36
  55. snowflake/cli/api/project/schemas/streamlit/__init__.py +0 -13
  56. snowflake/cli/api/project/schemas/streamlit/streamlit.py +0 -46
  57. snowflake/cli/api/project/schemas/template.py +0 -77
  58. snowflake/cli/api/project/schemas/updatable_model.py +0 -194
  59. snowflake/cli/api/project/util.py +0 -261
  60. snowflake/cli/api/rendering/__init__.py +0 -13
  61. snowflake/cli/api/rendering/jinja.py +0 -112
  62. snowflake/cli/api/rendering/project_definition_templates.py +0 -39
  63. snowflake/cli/api/rendering/project_templates.py +0 -98
  64. snowflake/cli/api/rendering/sql_templates.py +0 -60
  65. snowflake/cli/api/rest_api.py +0 -172
  66. snowflake/cli/api/sanitizers.py +0 -43
  67. snowflake/cli/api/secure_path.py +0 -362
  68. snowflake/cli/api/secure_utils.py +0 -29
  69. snowflake/cli/api/sql_execution.py +0 -260
  70. snowflake/cli/api/utils/__init__.py +0 -13
  71. snowflake/cli/api/utils/cursor.py +0 -34
  72. snowflake/cli/api/utils/definition_rendering.py +0 -383
  73. snowflake/cli/api/utils/dict_utils.py +0 -73
  74. snowflake/cli/api/utils/error_handling.py +0 -23
  75. snowflake/cli/api/utils/graph.py +0 -97
  76. snowflake/cli/api/utils/models.py +0 -63
  77. snowflake/cli/api/utils/naming_utils.py +0 -13
  78. snowflake/cli/api/utils/path_utils.py +0 -36
  79. snowflake/cli/api/utils/templating_functions.py +0 -144
  80. snowflake/cli/api/utils/types.py +0 -35
  81. snowflake/cli/app/__init__.py +0 -22
  82. snowflake/cli/app/__main__.py +0 -31
  83. snowflake/cli/app/api_impl/__init__.py +0 -13
  84. snowflake/cli/app/api_impl/plugin/__init__.py +0 -13
  85. snowflake/cli/app/api_impl/plugin/plugin_config_provider_impl.py +0 -66
  86. snowflake/cli/app/build_and_push.sh +0 -8
  87. snowflake/cli/app/cli_app.py +0 -243
  88. snowflake/cli/app/commands_registration/__init__.py +0 -33
  89. snowflake/cli/app/commands_registration/builtin_plugins.py +0 -54
  90. snowflake/cli/app/commands_registration/command_plugins_loader.py +0 -169
  91. snowflake/cli/app/commands_registration/commands_registration_with_callbacks.py +0 -105
  92. snowflake/cli/app/commands_registration/exception_logging.py +0 -26
  93. snowflake/cli/app/commands_registration/threadsafe.py +0 -48
  94. snowflake/cli/app/commands_registration/typer_registration.py +0 -153
  95. snowflake/cli/app/constants.py +0 -19
  96. snowflake/cli/app/dev/__init__.py +0 -13
  97. snowflake/cli/app/dev/commands_structure.py +0 -48
  98. snowflake/cli/app/dev/docs/__init__.py +0 -13
  99. snowflake/cli/app/dev/docs/commands_docs_generator.py +0 -100
  100. snowflake/cli/app/dev/docs/generator.py +0 -35
  101. snowflake/cli/app/dev/docs/project_definition_docs_generator.py +0 -58
  102. snowflake/cli/app/dev/docs/project_definition_generate_json_schema.py +0 -227
  103. snowflake/cli/app/dev/docs/template_utils.py +0 -23
  104. snowflake/cli/app/dev/docs/templates/definition_description.rst.jinja2 +0 -38
  105. snowflake/cli/app/dev/docs/templates/overview.rst.jinja2 +0 -9
  106. snowflake/cli/app/dev/docs/templates/usage.rst.jinja2 +0 -57
  107. snowflake/cli/app/dev/pycharm_remote_debug.py +0 -46
  108. snowflake/cli/app/loggers.py +0 -199
  109. snowflake/cli/app/main_typer.py +0 -62
  110. snowflake/cli/app/printing.py +0 -181
  111. snowflake/cli/app/snow_connector.py +0 -243
  112. snowflake/cli/app/telemetry.py +0 -189
  113. snowflake/cli/plugins/__init__.py +0 -13
  114. snowflake/cli/plugins/connection/__init__.py +0 -13
  115. snowflake/cli/plugins/connection/commands.py +0 -330
  116. snowflake/cli/plugins/connection/plugin_spec.py +0 -30
  117. snowflake/cli/plugins/connection/util.py +0 -179
  118. snowflake/cli/plugins/cortex/__init__.py +0 -13
  119. snowflake/cli/plugins/cortex/commands.py +0 -327
  120. snowflake/cli/plugins/cortex/constants.py +0 -17
  121. snowflake/cli/plugins/cortex/manager.py +0 -189
  122. snowflake/cli/plugins/cortex/plugin_spec.py +0 -30
  123. snowflake/cli/plugins/cortex/types.py +0 -22
  124. snowflake/cli/plugins/git/__init__.py +0 -13
  125. snowflake/cli/plugins/git/commands.py +0 -305
  126. snowflake/cli/plugins/git/manager.py +0 -96
  127. snowflake/cli/plugins/git/plugin_spec.py +0 -30
  128. snowflake/cli/plugins/init/__init__.py +0 -13
  129. snowflake/cli/plugins/init/commands.py +0 -244
  130. snowflake/cli/plugins/init/plugin_spec.py +0 -30
  131. snowflake/cli/plugins/nativeapp/__init__.py +0 -13
  132. snowflake/cli/plugins/nativeapp/artifacts.py +0 -742
  133. snowflake/cli/plugins/nativeapp/codegen/__init__.py +0 -13
  134. snowflake/cli/plugins/nativeapp/codegen/artifact_processor.py +0 -91
  135. snowflake/cli/plugins/nativeapp/codegen/compiler.py +0 -130
  136. snowflake/cli/plugins/nativeapp/codegen/sandbox.py +0 -306
  137. snowflake/cli/plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -172
  138. snowflake/cli/plugins/nativeapp/codegen/setup/setup_driver.py.source +0 -56
  139. snowflake/cli/plugins/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -181
  140. snowflake/cli/plugins/nativeapp/codegen/snowpark/extension_function_utils.py +0 -217
  141. snowflake/cli/plugins/nativeapp/codegen/snowpark/models.py +0 -61
  142. snowflake/cli/plugins/nativeapp/codegen/snowpark/python_processor.py +0 -528
  143. snowflake/cli/plugins/nativeapp/commands.py +0 -439
  144. snowflake/cli/plugins/nativeapp/common_flags.py +0 -44
  145. snowflake/cli/plugins/nativeapp/constants.py +0 -27
  146. snowflake/cli/plugins/nativeapp/exceptions.py +0 -122
  147. snowflake/cli/plugins/nativeapp/feature_flags.py +0 -24
  148. snowflake/cli/plugins/nativeapp/init.py +0 -345
  149. snowflake/cli/plugins/nativeapp/manager.py +0 -823
  150. snowflake/cli/plugins/nativeapp/plugin_spec.py +0 -30
  151. snowflake/cli/plugins/nativeapp/policy.py +0 -50
  152. snowflake/cli/plugins/nativeapp/project_model.py +0 -195
  153. snowflake/cli/plugins/nativeapp/run_processor.py +0 -389
  154. snowflake/cli/plugins/nativeapp/teardown_processor.py +0 -301
  155. snowflake/cli/plugins/nativeapp/utils.py +0 -98
  156. snowflake/cli/plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -135
  157. snowflake/cli/plugins/nativeapp/version/__init__.py +0 -13
  158. snowflake/cli/plugins/nativeapp/version/commands.py +0 -170
  159. snowflake/cli/plugins/nativeapp/version/version_processor.py +0 -362
  160. snowflake/cli/plugins/notebook/__init__.py +0 -13
  161. snowflake/cli/plugins/notebook/commands.py +0 -84
  162. snowflake/cli/plugins/notebook/exceptions.py +0 -20
  163. snowflake/cli/plugins/notebook/manager.py +0 -71
  164. snowflake/cli/plugins/notebook/plugin_spec.py +0 -30
  165. snowflake/cli/plugins/notebook/types.py +0 -16
  166. snowflake/cli/plugins/object/__init__.py +0 -13
  167. snowflake/cli/plugins/object/command_aliases.py +0 -94
  168. snowflake/cli/plugins/object/commands.py +0 -174
  169. snowflake/cli/plugins/object/common.py +0 -85
  170. snowflake/cli/plugins/object/manager.py +0 -96
  171. snowflake/cli/plugins/object/plugin_spec.py +0 -30
  172. snowflake/cli/plugins/object_stage_deprecated/__init__.py +0 -15
  173. snowflake/cli/plugins/object_stage_deprecated/commands.py +0 -122
  174. snowflake/cli/plugins/object_stage_deprecated/plugin_spec.py +0 -32
  175. snowflake/cli/plugins/snowpark/__init__.py +0 -13
  176. snowflake/cli/plugins/snowpark/commands.py +0 -548
  177. snowflake/cli/plugins/snowpark/common.py +0 -307
  178. snowflake/cli/plugins/snowpark/manager.py +0 -109
  179. snowflake/cli/plugins/snowpark/models.py +0 -156
  180. snowflake/cli/plugins/snowpark/package/__init__.py +0 -13
  181. snowflake/cli/plugins/snowpark/package/anaconda_packages.py +0 -233
  182. snowflake/cli/plugins/snowpark/package/commands.py +0 -256
  183. snowflake/cli/plugins/snowpark/package/manager.py +0 -43
  184. snowflake/cli/plugins/snowpark/package/utils.py +0 -26
  185. snowflake/cli/plugins/snowpark/package_utils.py +0 -354
  186. snowflake/cli/plugins/snowpark/plugin_spec.py +0 -30
  187. snowflake/cli/plugins/snowpark/snowpark_package_paths.py +0 -65
  188. snowflake/cli/plugins/snowpark/snowpark_shared.py +0 -95
  189. snowflake/cli/plugins/snowpark/zipper.py +0 -81
  190. snowflake/cli/plugins/spcs/__init__.py +0 -35
  191. snowflake/cli/plugins/spcs/common.py +0 -99
  192. snowflake/cli/plugins/spcs/compute_pool/__init__.py +0 -13
  193. snowflake/cli/plugins/spcs/compute_pool/commands.py +0 -240
  194. snowflake/cli/plugins/spcs/compute_pool/manager.py +0 -121
  195. snowflake/cli/plugins/spcs/image_registry/__init__.py +0 -13
  196. snowflake/cli/plugins/spcs/image_registry/commands.py +0 -65
  197. snowflake/cli/plugins/spcs/image_registry/manager.py +0 -105
  198. snowflake/cli/plugins/spcs/image_repository/__init__.py +0 -13
  199. snowflake/cli/plugins/spcs/image_repository/commands.py +0 -196
  200. snowflake/cli/plugins/spcs/image_repository/manager.py +0 -84
  201. snowflake/cli/plugins/spcs/jobs/__init__.py +0 -13
  202. snowflake/cli/plugins/spcs/jobs/commands.py +0 -78
  203. snowflake/cli/plugins/spcs/jobs/manager.py +0 -53
  204. snowflake/cli/plugins/spcs/plugin_spec.py +0 -30
  205. snowflake/cli/plugins/spcs/services/__init__.py +0 -13
  206. snowflake/cli/plugins/spcs/services/commands.py +0 -311
  207. snowflake/cli/plugins/spcs/services/manager.py +0 -170
  208. snowflake/cli/plugins/sql/__init__.py +0 -13
  209. snowflake/cli/plugins/sql/commands.py +0 -83
  210. snowflake/cli/plugins/sql/manager.py +0 -92
  211. snowflake/cli/plugins/sql/plugin_spec.py +0 -30
  212. snowflake/cli/plugins/sql/snowsql_templating.py +0 -28
  213. snowflake/cli/plugins/stage/__init__.py +0 -13
  214. snowflake/cli/plugins/stage/commands.py +0 -261
  215. snowflake/cli/plugins/stage/diff.py +0 -326
  216. snowflake/cli/plugins/stage/manager.py +0 -544
  217. snowflake/cli/plugins/stage/md5.py +0 -160
  218. snowflake/cli/plugins/stage/plugin_spec.py +0 -30
  219. snowflake/cli/plugins/streamlit/__init__.py +0 -13
  220. snowflake/cli/plugins/streamlit/commands.py +0 -186
  221. snowflake/cli/plugins/streamlit/manager.py +0 -222
  222. snowflake/cli/plugins/streamlit/plugin_spec.py +0 -30
  223. snowflake/cli/plugins/workspace/__init__.py +0 -13
  224. snowflake/cli/plugins/workspace/commands.py +0 -35
  225. snowflake/cli/plugins/workspace/plugin_spec.py +0 -30
  226. snowflake/cli/templates/default_snowpark/.gitignore +0 -4
  227. snowflake/cli/templates/default_snowpark/app/__init__.py +0 -0
  228. snowflake/cli/templates/default_snowpark/app/common.py +0 -2
  229. snowflake/cli/templates/default_snowpark/app/functions.py +0 -15
  230. snowflake/cli/templates/default_snowpark/app/procedures.py +0 -22
  231. snowflake/cli/templates/default_snowpark/requirements.txt +0 -1
  232. snowflake/cli/templates/default_snowpark/snowflake.yml +0 -23
  233. snowflake/cli/templates/default_streamlit/.gitignore +0 -4
  234. snowflake/cli/templates/default_streamlit/common/hello.py +0 -2
  235. snowflake/cli/templates/default_streamlit/environment.yml +0 -6
  236. snowflake/cli/templates/default_streamlit/pages/my_page.py +0 -3
  237. snowflake/cli/templates/default_streamlit/snowflake.yml +0 -10
  238. snowflake/cli/templates/default_streamlit/streamlit_app.py +0 -4
  239. snowflake_cli_labs-2.8.0rc1.dist-info/RECORD +0 -240
  240. snowflake_cli_labs-2.8.0rc1.dist-info/entry_points.txt +0 -2
  241. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-2.8.2.dist-info}/WHEEL +0 -0
  242. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-2.8.2.dist-info}/licenses/LICENSE +0 -0
@@ -1,742 +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 itertools
18
- import os
19
- from pathlib import Path
20
- from textwrap import dedent
21
- from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union
22
-
23
- from click.exceptions import ClickException
24
- from snowflake.cli.api.constants import DEFAULT_SIZE_LIMIT_MB
25
- from snowflake.cli.api.project.schemas.native_app.path_mapping import PathMapping
26
- from snowflake.cli.api.secure_path import SecurePath
27
- from yaml import safe_load
28
-
29
-
30
- class DeployRootError(ClickException):
31
- """
32
- The deploy root was incorrectly specified.
33
- """
34
-
35
- def __init__(self, msg: str):
36
- super().__init__(msg)
37
-
38
-
39
- class ArtifactError(ClickException):
40
- """
41
- Could not parse source or destination artifact.
42
- """
43
-
44
- def __init__(self, msg: str):
45
- super().__init__(msg)
46
-
47
-
48
- class SourceNotFoundError(ClickException):
49
- """
50
- No match was found for the specified source in the project directory
51
- """
52
-
53
- def __init__(self, src: Union[str, Path]):
54
- super().__init__(f"{dedent(str(self.__doc__))}: {src}".strip())
55
-
56
-
57
- class TooManyFilesError(ClickException):
58
- """
59
- Multiple file or directories were mapped to one output destination.
60
- """
61
-
62
- dest_path: Path
63
-
64
- def __init__(self, dest_path: Path):
65
- super().__init__(
66
- f"{dedent(str(self.__doc__))}\ndestination = {dest_path}".strip()
67
- )
68
- self.dest_path = dest_path
69
-
70
-
71
- class NotInDeployRootError(ClickException):
72
- """
73
- The specified destination path is outside of the deploy root, or
74
- would entirely replace it. This can happen when a relative path
75
- with ".." is provided, or when "." is used as the destination
76
- (use "./" instead to copy into the deploy root).
77
- """
78
-
79
- dest_path: Union[str, Path]
80
- deploy_root: Path
81
- src_path: Optional[Union[str, Path]]
82
-
83
- def __init__(
84
- self,
85
- *,
86
- dest_path: Union[Path, str],
87
- deploy_root: Path,
88
- src_path: Optional[Union[str, Path]] = None,
89
- ):
90
- message = dedent(str(self.__doc__))
91
- message += f"\ndestination = {dest_path}"
92
- message += f"\ndeploy root = {deploy_root}"
93
- if src_path is not None:
94
- message += f"""\nsource = {src_path}"""
95
- super().__init__(message.strip())
96
- self.dest_path = dest_path
97
- self.deploy_root = deploy_root
98
- self.src_path = src_path
99
-
100
-
101
- ArtifactPredicate = Callable[[Path, Path], bool]
102
-
103
-
104
- class _ArtifactPathMap:
105
- """
106
- A specialized version of an ordered multimap used to keep track of artifact
107
- source-destination mappings. The mapping is bidirectional, so it can be queried
108
- by source or destination paths. All paths manipulated by this class must be in
109
- relative, canonical form (relative to the project or deploy roots, as appropriate).
110
- """
111
-
112
- def __init__(self, project_root: Path):
113
- self._project_root = project_root
114
-
115
- # All (src,dest) pairs in inserting order, for iterating
116
- self.__src_dest_pairs: List[Tuple[Path, Path]] = []
117
- # built-in dict instances are ordered as of Python 3.7
118
- self.__src_to_dest: Dict[Path, List[Path]] = {}
119
- self.__dest_to_src: Dict[Path, Optional[Path]] = {}
120
-
121
- # This dictionary accumulates keys for each directory or file to be created in
122
- # the deploy root for any artifact mapping rule being processed. This includes
123
- # children of directories that are copied to the deploy root. Having this
124
- # information available is critical to detect possible clashes between rules.
125
- self._dest_is_dir: Dict[Path, bool] = {}
126
-
127
- def put(self, src: Path, dest: Path, dest_is_dir: bool) -> None:
128
- """
129
- Adds a new source-destination mapping pair to this map, if necessary. Note that
130
- this is internal logic that assumes that src-dest pairs have already been preprocessed
131
- by the enclosing BundleMap (for example, only file -> file and
132
- directory -> directory mappings are possible here due to the preprocessing step).
133
-
134
- Arguments:
135
- src {Path} -- the source path, in canonical form.
136
- dest {Path} -- the destination path, in canonical form.
137
- dest_is_dir {bool} -- whether the destination path is a directory.
138
- """
139
- # Both paths should be in canonical form
140
- assert not src.is_absolute()
141
- assert not dest.is_absolute()
142
-
143
- absolute_src = self._project_root / src
144
-
145
- current_source = self.__dest_to_src.get(dest)
146
- src_is_dir = absolute_src.is_dir()
147
- if dest_is_dir:
148
- assert src_is_dir # file -> directory is not possible here given how rules are processed
149
-
150
- # directory -> directory
151
- # Check that dest is currently unmapped
152
- current_is_dir = self._dest_is_dir.get(dest, False)
153
- if current_is_dir:
154
- # mapping to an existing directory is not allowed
155
- raise TooManyFilesError(dest)
156
- else:
157
- # file -> file
158
- # Check that there is no previous mapping for the same file.
159
- if current_source is not None and current_source != src:
160
- # There is already a different source mapping to this destination
161
- raise TooManyFilesError(dest)
162
-
163
- if src_is_dir:
164
- # mark all subdirectories of this source as directories so that we can
165
- # detect accidental clobbering
166
- for (root, _, files) in os.walk(absolute_src, followlinks=True):
167
- canonical_subdir = Path(root).relative_to(absolute_src)
168
- canonical_dest_subdir = dest / canonical_subdir
169
- self._update_dest_is_dir(canonical_dest_subdir, is_dir=True)
170
- for f in files:
171
- self._update_dest_is_dir(canonical_dest_subdir / f, is_dir=False)
172
-
173
- # make sure we check for dest_is_dir consistency regardless of whether the
174
- # insertion happened. This update can fail, so we need to do it first to
175
- # avoid applying partial updates to the underlying data storage.
176
- self._update_dest_is_dir(dest, dest_is_dir)
177
-
178
- dests = self.__src_to_dest.setdefault(src, [])
179
- if dest not in dests:
180
- dests.append(dest)
181
- self.__dest_to_src[dest] = src
182
- self.__src_dest_pairs.append((src, dest))
183
-
184
- def get_source(self, dest: Path) -> Optional[Path]:
185
- """
186
- Returns the source path associated with the provided destination path, if any.
187
- """
188
- return self.__dest_to_src.get(dest)
189
-
190
- def get_destinations(self, src: Path) -> Iterable[Path]:
191
- """
192
- Returns all destination paths associated with the provided source path, in insertion order.
193
- """
194
- return self.__src_to_dest.get(src, [])
195
-
196
- def all_sources(self) -> Iterable[Path]:
197
- """
198
- Returns all source paths associated with this map, in insertion order.
199
- """
200
- return self.__src_to_dest.keys()
201
-
202
- def __iter__(self) -> Iterator[Tuple[Path, Path]]:
203
- """
204
- Returns all (source, destination) pairs known to this map, in insertion order.
205
- """
206
- return iter(self.__src_dest_pairs)
207
-
208
- def _update_dest_is_dir(self, dest: Path, is_dir: bool) -> None:
209
- """
210
- Recursively marks seen destination paths as either files or folders, raising an error if any inconsistencies
211
- from previous invocations of this method are encountered.
212
-
213
- Arguments:
214
- dest {Path} -- the destination path, in canonical form.
215
- is_dir {bool} -- whether the destination path is a directory.
216
- """
217
- assert not dest.is_absolute() # dest must be in canonical relative form
218
-
219
- current_is_dir = self._dest_is_dir.get(dest, None)
220
- if current_is_dir is not None and current_is_dir != is_dir:
221
- raise ArtifactError(
222
- "Conflicting type for destination path: {canonical_dest}"
223
- )
224
-
225
- parent = dest.parent
226
- if parent != dest:
227
- self._update_dest_is_dir(parent, True)
228
-
229
- self._dest_is_dir[dest] = is_dir
230
-
231
-
232
- class BundleMap:
233
- """
234
- Computes the mapping between project directory artifacts (aka source artifacts) to their deploy root location
235
- (aka destination artifact). This information is primarily used when bundling a native applications project.
236
- """
237
-
238
- def __init__(self, *, project_root: Path, deploy_root: Path):
239
- self._project_root: Path = resolve_without_follow(project_root)
240
- self._deploy_root: Path = resolve_without_follow(deploy_root)
241
- self._artifact_map = _ArtifactPathMap(project_root=self._project_root)
242
-
243
- def deploy_root(self) -> Path:
244
- return self._deploy_root
245
-
246
- def project_root(self) -> Path:
247
- return self._project_root
248
-
249
- def _add(self, src: Path, dest: Path, map_as_child: bool) -> None:
250
- """
251
- Adds the specified artifact mapping rule to this map.
252
-
253
- Arguments:
254
- src {Path} -- the source path
255
- dest {Path} -- the destination path
256
- map_as_child {bool} -- when True, the source will be added as a child of the specified destination.
257
- """
258
- absolute_src = self._absolute_src(src)
259
- absolute_dest = self._absolute_dest(dest, src_path=src)
260
- dest_is_dir = absolute_src.is_dir() or map_as_child
261
-
262
- # Check for the special case of './' as a target ('.' is not allowed)
263
- if absolute_dest == self._deploy_root and not map_as_child:
264
- raise NotInDeployRootError(
265
- dest_path=dest, deploy_root=self._deploy_root, src_path=src
266
- )
267
-
268
- if self._deploy_root in absolute_src.parents:
269
- # ignore this item since it's in the deploy root. This can happen if the bundle map is created
270
- # after the bundle step and a project is using rules that are not sufficiently constrained.
271
- # Since the bundle step starts with deleting the deploy root, we wouldn't normally encounter this situation.
272
- return
273
-
274
- canonical_src = self._canonical_src(src)
275
- canonical_dest = self._canonical_dest(dest)
276
-
277
- if map_as_child:
278
- # Make sure the destination is a child of the original, since this was requested
279
- canonical_dest = canonical_dest / canonical_src.name
280
- dest_is_dir = absolute_src.is_dir()
281
-
282
- self._artifact_map.put(
283
- src=canonical_src, dest=canonical_dest, dest_is_dir=dest_is_dir
284
- )
285
-
286
- def _add_mapping(self, src: str, dest: Optional[str] = None):
287
- """
288
- Adds the specified artifact rule to this instance. The source should be relative to the project directory. It
289
- is interpreted as a file, directory or glob pattern. If the destination path is not specified, each source match
290
- is mapped to an identical path in the deploy root.
291
- """
292
- match_found = False
293
-
294
- src_path = Path(src)
295
- if src_path.is_absolute():
296
- raise ArtifactError("Source path must be a relative path")
297
-
298
- for resolved_src in self._project_root.glob(src):
299
- match_found = True
300
-
301
- if dest:
302
- dest_stem = dest.rstrip("/")
303
- if not dest_stem:
304
- # handle '/' as the destination as a special case. This is because specifying only '/' as a
305
- # a destination looks like '.' once all forwards slashes are stripped. If we don't handle it
306
- # specially here, `dest: /` would incorrectly be allowed.
307
- raise NotInDeployRootError(
308
- dest_path=dest,
309
- deploy_root=self._deploy_root,
310
- src_path=resolved_src,
311
- )
312
- dest_path = Path(dest.rstrip("/"))
313
- if dest_path.is_absolute():
314
- raise ArtifactError("Destination path must be a relative path")
315
- self._add(resolved_src, dest_path, specifies_directory(dest))
316
- else:
317
- self._add(
318
- resolved_src,
319
- resolved_src.relative_to(self._project_root),
320
- False,
321
- )
322
-
323
- if not match_found:
324
- raise SourceNotFoundError(src)
325
-
326
- def add(self, mapping: PathMapping) -> None:
327
- """
328
- Adds an artifact mapping rule to this instance.
329
- """
330
- self._add_mapping(mapping.src, mapping.dest)
331
-
332
- def _expand_artifact_mapping(
333
- self,
334
- src: Path,
335
- dest: Path,
336
- absolute: bool = False,
337
- expand_directories: bool = False,
338
- predicate: ArtifactPredicate = lambda src, dest: True,
339
- ) -> Iterator[Tuple[Path, Path]]:
340
- """
341
- Expands the specified source-destination mapping according to the provided options.
342
- The original mapping is yielded, followed by any expanded mappings derived from
343
- it.
344
-
345
- Arguments:
346
- src {Path} -- the source path
347
- dest {Path} -- the destination path
348
- absolute {bool} -- when True, all mappings will be yielded as absolute paths
349
- expand_directories {bool} -- when True, child mappings are yielded if the source path is a directory.
350
- predicate {ArtifactPredicate} -- when specified, only mappings satisfying this predicate will be yielded.
351
- """
352
- canonical_src = self._canonical_src(src)
353
- canonical_dest = self._canonical_dest(dest)
354
-
355
- absolute_src = self._absolute_src(canonical_src)
356
- absolute_dest = self._absolute_dest(canonical_dest)
357
- src_for_output = self._to_output_src(absolute_src, absolute)
358
- dest_for_output = self._to_output_dest(absolute_dest, absolute)
359
-
360
- if predicate(src_for_output, dest_for_output):
361
- yield src_for_output, dest_for_output
362
-
363
- if absolute_src.is_dir() and expand_directories:
364
- # both src and dest are directories, and expanding directories was requested. Traverse src, and map each
365
- # file to the dest directory
366
- for (root, subdirs, files) in os.walk(absolute_src, followlinks=True):
367
- relative_root = Path(root).relative_to(absolute_src)
368
- for name in itertools.chain(subdirs, files):
369
- src_file_for_output = src_for_output / relative_root / name
370
- dest_file_for_output = dest_for_output / relative_root / name
371
- if predicate(src_file_for_output, dest_file_for_output):
372
- yield src_file_for_output, dest_file_for_output
373
-
374
- def all_mappings(
375
- self,
376
- absolute: bool = False,
377
- expand_directories: bool = False,
378
- predicate: ArtifactPredicate = lambda src, dest: True,
379
- ) -> Iterator[Tuple[Path, Path]]:
380
- """
381
- Yields a (src, dest) pair for each deployed artifact in the project. Each pair corresponds to a single file
382
- in the project. Source directories are resolved as needed to resolve their contents.
383
-
384
- Arguments:
385
- self: this instance
386
- absolute (bool): Specifies whether the yielded paths should be joined with the project or deploy roots,
387
- as appropriate.
388
- expand_directories (bool): Specifies whether directory to directory mappings should be expanded to
389
- resolve their contained files.
390
- predicate (PathPredicate): If provided, the predicate is invoked with both the source path and the
391
- destination path as arguments. Only pairs selected by the predicate are returned.
392
-
393
- Returns:
394
- An iterator over all matching deployed artifacts.
395
- """
396
- for src, dest in self._artifact_map:
397
- for deployed_src, deployed_dest in self._expand_artifact_mapping(
398
- src,
399
- dest,
400
- absolute=absolute,
401
- expand_directories=expand_directories,
402
- predicate=predicate,
403
- ):
404
- yield deployed_src, deployed_dest
405
-
406
- def to_deploy_paths(self, src: Path) -> List[Path]:
407
- """
408
- Converts a source path to its corresponding deploy root path. If the input path is relative to the project root,
409
- paths relative to the deploy root are returned. If the input path is absolute, absolute paths are returned.
410
-
411
- Note that the provided source path must be part of a mapping. If the source path is not part of any mapping,
412
- an empty list is returned. For example, if `app/*` is specified as the source of a mapping,
413
- `to_deploy_paths(Path("app"))` will not yield any result.
414
-
415
- Arguments:
416
- src {Path} -- the source path within the project root, in canonical or absolute form.
417
-
418
- Returns:
419
- The deploy root paths for the given source path, or an empty list if no such path exists.
420
- """
421
- is_absolute = src.is_absolute()
422
-
423
- try:
424
- absolute_src = self._absolute_src(src)
425
- if not absolute_src.exists():
426
- return []
427
- canonical_src = self._canonical_src(absolute_src)
428
- except ArtifactError:
429
- # No mapping is possible for this src path
430
- return []
431
-
432
- output_destinations: List[Path] = []
433
-
434
- # 1. Check for exact rule matches for this path
435
- canonical_dests = self._artifact_map.get_destinations(canonical_src)
436
- if canonical_dests:
437
- for d in canonical_dests:
438
- output_destinations.append(self._to_output_dest(d, is_absolute))
439
-
440
- # 2. Check for any matches to parent directories for this path that would
441
- # cause this path to be part of the recursive copy
442
- canonical_parent = canonical_src.parent
443
- canonical_parent_dests = self.to_deploy_paths(canonical_parent)
444
- if canonical_parent_dests:
445
- canonical_child = canonical_src.relative_to(canonical_parent)
446
- for d in canonical_parent_dests:
447
- output_destinations.append(
448
- self._to_output_dest(d / canonical_child, is_absolute)
449
- )
450
-
451
- return output_destinations
452
-
453
- def all_sources(self, absolute: bool = False) -> Iterator[Path]:
454
- """
455
- Yields each registered artifact source in the project.
456
-
457
- Arguments:
458
- self: this instance
459
- absolute (bool): Specifies whether the yielded paths should be joined with the absolute project root.
460
- Returns:
461
- An iterator over all artifact mapping source paths.
462
- """
463
- for src in self._artifact_map.all_sources():
464
- yield self._to_output_src(src, absolute)
465
-
466
- def to_project_path(self, dest: Path) -> Optional[Path]:
467
- """
468
- Converts a deploy root path to its corresponding project source path. If the input path is relative to the
469
- deploy root, a path relative to the project root is returned. If the input path is absolute, an absolute path is
470
- returned.
471
-
472
- Arguments:
473
- dest {Path} -- the destination path within the deploy root, in canonical or absolute form.
474
-
475
- Returns:
476
- The project root path for the given deploy root path, or None if no such path exists.
477
- """
478
- is_absolute = dest.is_absolute()
479
- try:
480
- canonical_dest = self._canonical_dest(dest)
481
- except NotInDeployRootError:
482
- # No mapping possible for the dest path
483
- return None
484
-
485
- # 1. Look for an exact rule matching this path. If we find any, then
486
- # stop searching. This is because each destination path can only originate
487
- # from a single source (however, one source can be copied to multiple destinations).
488
- canonical_src = self._artifact_map.get_source(canonical_dest)
489
- if canonical_src is not None:
490
- return self._to_output_src(canonical_src, is_absolute)
491
-
492
- # 2. No exact match was found, look for a match for parent directories of this
493
- # path, recursively. Stop when a match is found
494
- canonical_parent = canonical_dest.parent
495
- if canonical_parent == canonical_dest:
496
- return None
497
- canonical_parent_src = self.to_project_path(canonical_parent)
498
- if canonical_parent_src is not None:
499
- canonical_child = canonical_dest.relative_to(canonical_parent)
500
- canonical_child_candidate = canonical_parent_src / canonical_child
501
- if self._absolute_src(canonical_child_candidate).exists():
502
- return self._to_output_src(canonical_child_candidate, is_absolute)
503
-
504
- # No mapping for this destination path
505
- return None
506
-
507
- def _absolute_src(self, src: Path) -> Path:
508
- if src.is_absolute():
509
- resolved_src = resolve_without_follow(src)
510
- else:
511
- resolved_src = resolve_without_follow(self._project_root / src)
512
- if self._project_root not in resolved_src.parents:
513
- raise ArtifactError(
514
- f"Source is not in the project root: {src}, root={self._project_root}"
515
- )
516
- return resolved_src
517
-
518
- def _absolute_dest(self, dest: Path, src_path: Optional[Path] = None) -> Path:
519
- if dest.is_absolute():
520
- resolved_dest = resolve_without_follow(dest)
521
- else:
522
- resolved_dest = resolve_without_follow(self._deploy_root / dest)
523
- if (
524
- self._deploy_root != resolved_dest
525
- and self._deploy_root not in resolved_dest.parents
526
- ):
527
- raise NotInDeployRootError(
528
- dest_path=dest, deploy_root=self._deploy_root, src_path=src_path
529
- )
530
-
531
- return resolved_dest
532
-
533
- def _canonical_src(self, src: Path) -> Path:
534
- """
535
- Returns the canonical version of a source path, relative to the project root.
536
- """
537
- absolute_src = self._absolute_src(src)
538
- return absolute_src.relative_to(self._project_root)
539
-
540
- def _canonical_dest(self, dest: Path) -> Path:
541
- """
542
- Returns the canonical version of a destination path, relative to the deploy root.
543
- """
544
- absolute_dest = self._absolute_dest(dest)
545
- return absolute_dest.relative_to(self._deploy_root)
546
-
547
- def _to_output_dest(self, dest: Path, absolute: bool) -> Path:
548
- return self._absolute_dest(dest) if absolute else self._canonical_dest(dest)
549
-
550
- def _to_output_src(self, src: Path, absolute: bool) -> Path:
551
- return self._absolute_src(src) if absolute else self._canonical_src(src)
552
-
553
-
554
- def specifies_directory(s: str) -> bool:
555
- """
556
- Does the path (as seen from the project definition) refer to
557
- a directory? For destination paths, we enforce the usage of a
558
- trailing forward slash (/). Note that we use the forward slash
559
- even on Windows so that snowflake.yml can be shared between OSes.
560
-
561
- This means that to put a file in the root of the stage, we need
562
- to specify "./" as its destination, or omit it (but only if the
563
- file already lives in the project root).
564
- """
565
- return s.endswith("/")
566
-
567
-
568
- def delete(path: Path) -> None:
569
- """
570
- Obliterates whatever is at the given path, or is a no-op if the
571
- given path does not represent a file or directory that exists.
572
- """
573
- spath = SecurePath(path)
574
- if spath.path.is_file():
575
- spath.unlink() # remove the file
576
- elif spath.path.is_dir():
577
- spath.rmdir(recursive=True) # remove dir and all contains
578
-
579
-
580
- def symlink_or_copy(src: Path, dst: Path, deploy_root: Path) -> None:
581
- """
582
- Symlinks files from src to dst. If the src contains parent directories, then copies the empty directory shell to the deploy root.
583
- The directory hierarchy above dst is created if any of those directories do not exist.
584
- """
585
- ssrc = SecurePath(src)
586
- sdst = SecurePath(dst)
587
- sdst.parent.mkdir(parents=True, exist_ok=True)
588
-
589
- # Verify that the mapping isn't accidentally trying to create a file in the project source through symlinks.
590
- # We need to ensure we're resolving symlinks for this check to be effective.
591
- # We are unlikely to hit this if calling the function through bundle map, keeping it here for other future use cases outside bundle.
592
- resolved_dst = dst.resolve()
593
- resolved_deploy_root = deploy_root.resolve()
594
- dst_is_deploy_root = resolved_deploy_root == resolved_dst
595
- if (not dst_is_deploy_root) and (resolved_deploy_root not in resolved_dst.parents):
596
- raise NotInDeployRootError(dest_path=dst, deploy_root=deploy_root, src_path=src)
597
-
598
- absolute_src = resolve_without_follow(src)
599
- if absolute_src.is_file():
600
- delete(dst)
601
- try:
602
- os.symlink(absolute_src, dst)
603
- except OSError:
604
- ssrc.copy(dst)
605
- else:
606
- # 1. Create a new directory in the deploy root
607
- dst.mkdir(exist_ok=True)
608
- # 2. For all children of src, create their counterparts in dst now that it exists
609
- for root, _, files in sorted(os.walk(absolute_src, followlinks=True)):
610
- relative_root = Path(root).relative_to(absolute_src)
611
- absolute_root_in_deploy = Path(dst, relative_root)
612
- absolute_root_in_deploy.mkdir(parents=True, exist_ok=True)
613
- for file in sorted(files):
614
- absolute_file_in_project = Path(absolute_src, relative_root, file)
615
- absolute_file_in_deploy = Path(absolute_root_in_deploy, file)
616
- symlink_or_copy(
617
- src=absolute_file_in_project,
618
- dst=absolute_file_in_deploy,
619
- deploy_root=deploy_root,
620
- )
621
-
622
-
623
- def resolve_without_follow(path: Path) -> Path:
624
- """
625
- Resolves a Path to an absolute version of itself, without following
626
- symlinks like Path.resolve() does.
627
- """
628
- return Path(os.path.abspath(path))
629
-
630
-
631
- def build_bundle(
632
- project_root: Path,
633
- deploy_root: Path,
634
- artifacts: List[PathMapping],
635
- ) -> BundleMap:
636
- """
637
- Prepares a local folder (deploy_root) with configured app artifacts.
638
- This folder can then be uploaded to a stage.
639
- Returns a map of the copied source files, pointing to where they were copied.
640
- """
641
- resolved_root = deploy_root.resolve()
642
- if resolved_root.exists() and not resolved_root.is_dir():
643
- raise DeployRootError(
644
- f"Deploy root {resolved_root} exists, but is not a directory!"
645
- )
646
-
647
- if project_root.resolve() not in resolved_root.parents:
648
- raise DeployRootError(
649
- f"Deploy root {resolved_root} is not a descendent of the project directory!"
650
- )
651
-
652
- # users may have removed files or entire artifact mappings from their project
653
- # definition since the last time we bundled; we need to clear the deploy root first
654
- if resolved_root.exists():
655
- delete(resolved_root)
656
-
657
- bundle_map = BundleMap(project_root=project_root, deploy_root=deploy_root)
658
- for artifact in artifacts:
659
- bundle_map.add(artifact)
660
-
661
- for (absolute_src, absolute_dest) in bundle_map.all_mappings(
662
- absolute=True, expand_directories=False
663
- ):
664
- symlink_or_copy(absolute_src, absolute_dest, deploy_root=deploy_root)
665
-
666
- return bundle_map
667
-
668
-
669
- def find_manifest_file(deploy_root: Path) -> Path:
670
- """
671
- Find manifest.yml file, if available, in the deploy_root of the Snowflake Native App project.
672
- """
673
- resolved_root = deploy_root.resolve()
674
- for root, _, files in os.walk(resolved_root):
675
- for file in files:
676
- if file.lower() == "manifest.yml":
677
- return Path(os.path.join(root, file))
678
-
679
- raise ClickException(
680
- "Required manifest.yml file not found in the deploy root of the Snowflake Native App project."
681
- )
682
-
683
-
684
- def find_and_read_manifest_file(deploy_root: Path) -> Dict[str, Any]:
685
- """
686
- Finds the manifest file in the deploy root of the project, and reads the contents and returns them
687
- as a dictionary.
688
- """
689
- manifest_file = find_manifest_file(deploy_root=deploy_root)
690
- with SecurePath(manifest_file).open(
691
- "r", read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB
692
- ) as file:
693
- manifest_content = safe_load(file.read())
694
- return manifest_content
695
-
696
-
697
- def find_setup_script_file(deploy_root: Path) -> Path:
698
- """
699
- Find the setup script file, if available, in the deploy_root of the Snowflake Native App project.
700
- """
701
- artifacts = "artifacts"
702
- setup_script = "setup_script"
703
-
704
- manifest_content = find_and_read_manifest_file(deploy_root=deploy_root)
705
-
706
- if (artifacts in manifest_content) and (
707
- setup_script in manifest_content[artifacts]
708
- ):
709
- setup_script_rel_path = manifest_content[artifacts][setup_script]
710
- file_name = Path(deploy_root / setup_script_rel_path)
711
- if file_name.is_file():
712
- return file_name
713
- else:
714
- raise ClickException(f"Could not find setup script file at {file_name}.")
715
- else:
716
- raise ClickException(
717
- "Manifest.yml file must contain an artifacts section to specify the location of the setup script."
718
- )
719
-
720
-
721
- def find_version_info_in_manifest_file(
722
- deploy_root: Path,
723
- ) -> Tuple[Optional[str], Optional[str]]:
724
- """
725
- Find version and patch, if available, in the manifest.yml file.
726
- """
727
- version_field = "version"
728
- name_field = "name"
729
- patch_field = "patch"
730
-
731
- manifest_content = find_and_read_manifest_file(deploy_root=deploy_root)
732
-
733
- version_name: Optional[str] = None
734
- patch_name: Optional[str] = None
735
-
736
- if version_field in manifest_content:
737
- version_info = manifest_content[version_field]
738
- version_name = version_info[name_field]
739
- if patch_field in version_info:
740
- patch_name = version_info[patch_field]
741
-
742
- return version_name, patch_name