snowflake-cli-labs 3.0.0rc4__py3-none-any.whl → 3.0.1__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.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/METADATA +6 -96
  3. snowflake_cli_labs-3.0.1.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 -61
  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 -395
  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.0rc4.dist-info/RECORD +0 -242
  242. snowflake_cli_labs-3.0.0rc4.dist-info/entry_points.txt +0 -2
  243. {snowflake_cli_labs-3.0.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/WHEEL +0 -0
  244. {snowflake_cli_labs-3.0.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/licenses/LICENSE +0 -0
@@ -1,118 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from __future__ import annotations
16
-
17
- import logging
18
- from typing import Any, List, Optional
19
-
20
- from click import Command
21
- from snowflake.cli._app.dev.docs.template_utils import get_template_environment
22
- from snowflake.cli.api.secure_path import SecurePath
23
- from typer.core import TyperArgument
24
-
25
- log = logging.getLogger(__name__)
26
-
27
- CMD_USAGE_TMPL = "usage.rst.jinja2"
28
- OVERVIEW_TMPL = "overview.rst.jinja2"
29
-
30
-
31
- def generate_command_docs(
32
- root: SecurePath, command: Command, cmd_parts: Optional[List] = None
33
- ):
34
- """
35
- Iterates recursively through commands info. Creates a file structure resembling
36
- commands structure. For each terminal command creates a "usage" rst file.
37
- """
38
- if getattr(command, "hidden", False):
39
- return
40
-
41
- root.mkdir(exist_ok=True)
42
- if cmd_parts is None:
43
- _render_command_usage(command, root, cmd_parts, template_name=OVERVIEW_TMPL)
44
-
45
- cmd_parts = cmd_parts or []
46
- if hasattr(command, "commands"):
47
- for command_name, command_info in command.commands.items():
48
- path = root / command.name if command.name != "default" else root
49
- generate_command_docs(path, command_info, [*cmd_parts, command_name])
50
- else:
51
- _render_command_usage(command, root, cmd_parts)
52
-
53
-
54
- def get_main_option(options: List[str]) -> str:
55
- long_options = [option for option in options if option.startswith("--")]
56
- if long_options:
57
- return long_options[0]
58
-
59
- short_options = [option for option in options if option.startswith("-")]
60
- if short_options:
61
- return short_options[0]
62
-
63
- return ""
64
-
65
-
66
- def _render_command_usage(
67
- command: Command,
68
- root: SecurePath,
69
- path: Optional[List] = None,
70
- template_name: str = CMD_USAGE_TMPL,
71
- ):
72
- # This is end command
73
- command_name = command.name
74
- env = get_template_environment()
75
- env.filters[get_main_option.__name__] = get_main_option
76
- template = env.get_template(template_name)
77
- arguments = []
78
- options = []
79
- for param in command.params:
80
- if isinstance(param, TyperArgument):
81
- arguments.append(param)
82
- else:
83
- options.append(param)
84
-
85
- # RST files are presumed to be standalone pages in the docs with a matching item in the left nav.
86
- # Included files, which these are, need to use the .txt extension.
87
- file_path = root / f"usage-{command_name}.txt"
88
- log.info("Creating %s", file_path)
89
- command_help_params = _split_docstring(command.help)
90
- template_params = {
91
- "name": command_name,
92
- "options": options,
93
- "arguments": arguments,
94
- "path": path,
95
- }
96
- with file_path.open("w+") as fh:
97
- fh.write(template.render(command_help_params | template_params))
98
-
99
-
100
- def _split_docstring(command_help: Optional[str]) -> dict[str, Any]:
101
- if command_help is None:
102
- return {}
103
-
104
- split_command_help = command_help.split("## ")
105
-
106
- if len(split_command_help) == 1:
107
- return {"help": split_command_help[0]}
108
-
109
- additional_sections = []
110
- for section in split_command_help[1:]:
111
- lines = section.split("\n")
112
- additional_sections.append(
113
- {"title": lines[0], "content": "\n".join(lines[1:]).strip()}
114
- )
115
- return {
116
- "help": split_command_help[0],
117
- "additional_sections": additional_sections,
118
- }
@@ -1,35 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from __future__ import annotations
16
-
17
- import logging
18
-
19
- from click import Command
20
- from snowflake.cli._app.dev.docs.commands_docs_generator import generate_command_docs
21
- from snowflake.cli._app.dev.docs.project_definition_docs_generator import (
22
- generate_project_definition_docs,
23
- )
24
- from snowflake.cli.api.secure_path import SecurePath
25
-
26
- log = logging.getLogger(__name__)
27
-
28
-
29
- def generate_docs(root: SecurePath, command: Command):
30
- """
31
- Generates documentation for each command, its options and for the project definition.
32
- """
33
- root.mkdir(exist_ok=True)
34
- generate_command_docs(root / "commands", command)
35
- generate_project_definition_docs(root / "project_definition")
@@ -1,58 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from __future__ import annotations
16
-
17
- import logging
18
- from typing import Any, Dict
19
-
20
- from pydantic.json_schema import model_json_schema
21
- from snowflake.cli._app.dev.docs.project_definition_generate_json_schema import (
22
- ProjectDefinitionGenerateJsonSchema,
23
- )
24
- from snowflake.cli._app.dev.docs.template_utils import get_template_environment
25
- from snowflake.cli.api.project.schemas.project_definition import DefinitionV11
26
- from snowflake.cli.api.secure_path import SecurePath
27
-
28
- log = logging.getLogger(__name__)
29
-
30
- DEFINITION_DESCRIPTION = "definition_description.rst.jinja2"
31
-
32
-
33
- def generate_project_definition_docs(root: SecurePath):
34
- """
35
- Recursively traverses the generated project definition schema,
36
- creating a file for each section that mirrors the YAML structure.
37
- Each file contains the definition for every field within that section.
38
- """
39
-
40
- root.mkdir(exist_ok=True)
41
- list_of_sections = model_json_schema(
42
- DefinitionV11, schema_generator=ProjectDefinitionGenerateJsonSchema
43
- )["result"]
44
- for section in list_of_sections:
45
- _render_definition_description(root, section)
46
- return
47
-
48
-
49
- def _render_definition_description(root: SecurePath, section: Dict[str, Any]) -> None:
50
- env = get_template_environment()
51
-
52
- # RST files are presumed to be standalone pages in the docs with a matching item in the left nav.
53
- # Included files, which these are, need to use the .txt extension.
54
- file_path = root / f"definition_{section['name']}.txt"
55
- log.info("Creating %s", file_path)
56
- template = env.get_template(DEFINITION_DESCRIPTION)
57
- with file_path.open("w+") as fh:
58
- fh.write(template.render(section))
@@ -1,227 +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 dataclasses import asdict, dataclass
18
- from typing import Any, Dict, List, Tuple
19
-
20
- from pydantic.json_schema import GenerateJsonSchema
21
-
22
-
23
- @dataclass
24
- class ProjectDefinitionProperty:
25
- """
26
- Class for storing data of properties to be used in project definition generators.
27
- """
28
-
29
- path: str
30
- title: str
31
- indents: int
32
- item_index: int
33
- required: bool
34
- name: str
35
- description: str
36
- add_types: bool
37
- types: str
38
-
39
-
40
- class ProjectDefinitionGenerateJsonSchema(GenerateJsonSchema):
41
- def __init__(self, by_alias: bool = False, ref_template: str = ""):
42
- super().__init__(by_alias, "{model}")
43
- self._remapped_definitions: Dict[str, Any] = {}
44
-
45
- def generate(self, schema, mode="validation"):
46
- """
47
- Transforms the generated json from the model to a list of project definition sections with its properties.
48
- For example:
49
- {
50
- "result": [
51
- {
52
- "title": "Native app definitions for the project",
53
- "name": "native_app",
54
- "properties": [
55
- {
56
- "path": "Version of the project definition schema, which is currently 1",
57
- "title": "Title of field A",
58
- "indents": 0,
59
- "item_index": 0,
60
- "required": True,
61
- "name": "definition_version",
62
- "add_types": True,
63
- "types": "string | integer",
64
- },
65
- {
66
- "path": "native_app.name",
67
- "title": "Project identifier",
68
- "indents": 1,
69
- "item_index": 0,
70
- "required": True,
71
- "name": "name",
72
- "add_types": True,
73
- "types": "string",
74
- }
75
- ]
76
- }
77
- ]
78
- }
79
- """
80
- json_schema = super().generate(schema, mode=mode)
81
- self._remapped_definitions = json_schema["$defs"]
82
- return {"result": self._get_definition_sections(json_schema)}
83
-
84
- def _get_definition_sections(
85
- self, current_definition: Dict[str, Any]
86
- ) -> List[Dict[str, Any]]:
87
- required_properties: List[Dict[str, Any]] = []
88
- sections: List[Dict[str, Any]] = []
89
-
90
- for property_name, property_model in current_definition["properties"].items():
91
- is_required = (
92
- "required" in current_definition
93
- and property_name in current_definition["required"]
94
- )
95
- children_properties = self._get_children_properties(
96
- property_model, property_name
97
- )
98
-
99
- new_property = ProjectDefinitionProperty(
100
- path=property_name,
101
- title=property_model.get("title", ""),
102
- description=property_model.get("description", ""),
103
- indents=0,
104
- item_index=0,
105
- required=is_required,
106
- name=property_name,
107
- add_types=len(children_properties) == 0,
108
- types=" | ".join(self._get_property_types(property_model)),
109
- )
110
- properties = [asdict(new_property)] + children_properties
111
-
112
- if is_required:
113
- required_properties.extend(properties)
114
- else:
115
- sections.append(
116
- {
117
- "properties": properties,
118
- "title": property_model["title"],
119
- "name": property_name,
120
- }
121
- )
122
-
123
- for section in sections:
124
- section["properties"] = required_properties + section["properties"]
125
-
126
- return sections
127
-
128
- def _get_section_properties(
129
- self,
130
- current_definition: Dict[str, Any],
131
- current_path: str = "",
132
- depth: int = 0,
133
- is_array_item: bool = False,
134
- ) -> List[Dict[str, Any]]:
135
- required_properties: List[Dict[str, Any]] = []
136
- optional_properties: List[Dict[str, Any]] = []
137
- item_index = 0
138
-
139
- for property_name, property_model in current_definition["properties"].items():
140
- item_index += 1 if is_array_item else 0
141
- is_required = (
142
- "required" in current_definition
143
- and property_name in current_definition["required"]
144
- )
145
- new_current_path = (
146
- property_name
147
- if current_path == ""
148
- else current_path + "." + property_name
149
- )
150
- children_properties = self._get_children_properties(
151
- property_model, new_current_path, depth
152
- )
153
- new_property = ProjectDefinitionProperty(
154
- path=new_current_path,
155
- title=property_model.get("title", ""),
156
- description=property_model.get("description", ""),
157
- indents=depth,
158
- item_index=item_index,
159
- required=is_required,
160
- name=property_name,
161
- add_types=len(children_properties) == 0,
162
- types=" | ".join(self._get_property_types(property_model)),
163
- )
164
- properties = [asdict(new_property)] + children_properties
165
- if is_required:
166
- required_properties.extend(properties)
167
- else:
168
- optional_properties.extend(properties)
169
- return required_properties + optional_properties
170
-
171
- def _get_children_properties(
172
- self,
173
- property_model: Dict[str, Any],
174
- current_path: str,
175
- depth: int = 0,
176
- ) -> List[Dict[str, Any]]:
177
- child_properties: List[Dict[str, Any]] = []
178
- references: List[Tuple[str, bool]] = self._get_property_references(
179
- property_model
180
- )
181
- for reference, is_array_item in references:
182
- child_properties.extend(
183
- self._get_section_properties(
184
- self._remapped_definitions[reference],
185
- current_path,
186
- depth + 1,
187
- is_array_item,
188
- )
189
- )
190
-
191
- return child_properties
192
-
193
- def _get_property_references(
194
- self,
195
- model_with_type: Dict[str, Any],
196
- is_array_item: bool = False,
197
- ) -> list[tuple[str, bool]]:
198
- result: List[Tuple[str, bool]] = []
199
-
200
- if "$ref" in model_with_type:
201
- return [(model_with_type["$ref"], is_array_item)]
202
-
203
- if "type" in model_with_type and model_with_type["type"] == "array":
204
- result.extend(self._get_property_references(model_with_type["items"], True))
205
-
206
- if "anyOf" in model_with_type:
207
- for property_type in model_with_type["anyOf"]:
208
- result.extend(
209
- self._get_property_references(property_type, is_array_item)
210
- )
211
- return result
212
-
213
- def _get_property_types(self, model_with_type: Dict[str, Any]) -> list[str]:
214
- types_result: List[str] = []
215
- if "type" in model_with_type:
216
- if model_with_type["type"] == "array":
217
- items_types = self._get_property_types(model_with_type["items"])
218
- if len(items_types) > 0:
219
- types_result.append(f"array[{' | '.join(items_types)}]")
220
-
221
- elif model_with_type["type"] != "null":
222
- types_result.append(model_with_type["type"])
223
- elif "anyOf" in model_with_type:
224
- for property_type in model_with_type["anyOf"]:
225
- types = self._get_property_types(property_type)
226
- types_result.extend(types)
227
- return types_result
@@ -1,23 +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 pathlib import Path
16
-
17
- from jinja2 import Environment, FileSystemLoader
18
-
19
- _TEMPLATE_PATH = Path(__file__).parent / "templates"
20
-
21
-
22
- def get_template_environment() -> Environment:
23
- return Environment(loader=FileSystemLoader(_TEMPLATE_PATH))
@@ -1,38 +0,0 @@
1
- {{ title }}
2
-
3
- Project definition structure
4
- ===============================================================================
5
-
6
- .. code-block::
7
-
8
- {% for property in properties %}
9
- {{ " "*(property["indents"] + 1) + ("- " if property["item_index"] == 1 else "") + (" " if property["item_index"] > 1 else "") + property["name"] }}: {% if property["add_types"] %}<{{ property["types"] }}>{% endif %}
10
- {%- endfor %}
11
-
12
-
13
- Project definition properties
14
- ===============================================================================
15
- {%- if properties %}
16
- The following table describes the project definition properties.
17
-
18
- .. list-table:: Project definition properties
19
- :widths: 30 70
20
- :header-rows: 1
21
-
22
- * - Property
23
- - Definition
24
- {% for property in properties %}
25
- * - **{{property["path"]}}**
26
-
27
- *{{"Required" if property["required"] else "Optional"}}*{{ (", *"+property["types"]+"*") if property["types"]}}
28
-
29
- - {{property["title"]}}
30
- {% if property["description"] %}
31
- {{ property["description"] }}
32
- {% else %}{% endif -%}
33
- {%+ endfor %}
34
- {% else %}
35
-
36
- None
37
-
38
- {% endif -%}
@@ -1,9 +0,0 @@
1
- {{ help }}
2
-
3
-
4
- Global options
5
- ===============================================================================
6
- {% for param in options if not param.hidden %}
7
- :samp:`{% for p in param.opts %}{{ p }}{{ ", " if not loop.last }}{% endfor %}{% if not param.is_flag %} {{ '{' }}{{ param.name }}{{ '}' }}{% endif %}`
8
- {% if param.help %}{{ " " + param.help | replace("`", "``") }}{% if param.help[-1] != '.' %}.{% endif %}{% else %} TBD{% endif %}
9
- {% endfor %}
@@ -1,67 +0,0 @@
1
- {{ help | replace("`", "``") | replace("\n", " ") }}
2
-
3
- Syntax
4
- ===============================================================================
5
-
6
- .. code-block:: console
7
-
8
- snow {% for part in path %}{{ part }}{{ " " if not loop.last }}{% endfor %}
9
- {%- for param in arguments if not param.hidden %}
10
- <{{ param.name }}>
11
- {%- endfor %}
12
- {%- for param in options if not param.hidden %}
13
- {{ (param.opts | get_main_option) }}{% if not param.is_flag %} <{{ param.name }}>{% endif %}
14
- {%- if param.type.name == "boolean" and param.secondary_opts|length > 0 %} {{ "/ " }}{{ param.secondary_opts[0] }}{% endif %}
15
- {%- endfor %}
16
-
17
- Arguments
18
- ===============================================================================
19
-
20
- {%- if arguments %}
21
- {% for param in arguments %}
22
- :samp:`{{ '{' }}
23
- {%- if param.required -%}
24
- {{ param.make_metavar().lower() }}
25
- {%- else -%}
26
- {{ param.make_metavar().replace("[", "").replace("]", "").lower() }}
27
- {%- endif -%}
28
- {{ '}' }}`
29
- {% if param.help %}{{ " " + param.help | replace("`", "``") | replace("\n", " ") }}{% if param.help[-1] != '.' %}.{% endif %}{% if param.default %} Default: {{ param.default }}.{% endif %}{% else %} TBD{% endif %}
30
- {% endfor %}
31
- {% else %}
32
-
33
- None
34
-
35
- {% endif -%}
36
-
37
- Options
38
- ===============================================================================
39
-
40
- {%- if options %}
41
- {% for param in options if not param.hidden %}
42
- :samp:`{% if param.type.name == "boolean" %}
43
- {%- for p in param.opts %}{{ p }}{{ ", " if not loop.last }}{% endfor %}{% if param.secondary_opts|length > 0 %} {{ "/ " }}{{ param.secondary_opts[0] }}{% endif %}
44
- {%- else %}
45
- {%- for p in param.opts %}{{ p }}{{ ", " if not loop.last }}{% endfor %}
46
- {%- endif %}
47
- {%- if not param.is_flag %}
48
- {%- if param.type.name != "choice" %}{{ ' {' }}{% else %} {% endif %}{{ param.make_metavar() }}{% if param.type.name != "choice" %}{{ '}' }}
49
- {%- endif %}
50
- {%- endif %}`
51
- {% if param.help %}{{ " " + param.help | replace("`", "``") | replace("\n", " ") }}{% if param.help[-1] != '.' %}.{% endif %}{% if param.default is not none %} Default: {{ param.default }}.{% endif %}{% else %} TBD{% endif %}
52
- {% endfor -%}
53
- {% else %}
54
-
55
- None
56
-
57
- {% endif -%}
58
-
59
- {%- if additional_sections %}
60
- ..
61
- {%- for section in additional_sections %}
62
- {{ section.title }}
63
- ===============================================================================
64
-
65
- {{ section.content | indent(2) }}
66
- {% endfor %}
67
- {% endif %}
@@ -1,46 +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 typing import Optional
18
-
19
- from click import ClickException
20
-
21
-
22
- def setup_pycharm_remote_debugger_if_provided(
23
- pycharm_debug_library_path: Optional[str],
24
- pycharm_debug_server_host: Optional[str],
25
- pycharm_debug_server_port: Optional[int],
26
- ):
27
- if pycharm_debug_library_path:
28
- if (
29
- pycharm_debug_server_host is not None
30
- and pycharm_debug_server_port is not None
31
- ):
32
- import sys
33
-
34
- sys.path.append(pycharm_debug_library_path)
35
- import pydevd_pycharm
36
-
37
- pydevd_pycharm.settrace(
38
- pycharm_debug_server_host,
39
- port=pycharm_debug_server_port,
40
- stdoutToServer=True,
41
- stderrToServer=True,
42
- )
43
- else:
44
- raise ClickException(
45
- "Debug server host and port have to be provided to use PyCharm remote debugger"
46
- )