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,153 +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 List
19
-
20
- import click
21
- from snowflake.cli.api.plugins.command import CommandSpec, CommandType
22
- from snowflake.cli.app.commands_registration import LoadedCommandPlugin
23
- from snowflake.cli.app.commands_registration.exception_logging import exception_logging
24
- from typer.core import TyperGroup
25
-
26
- log = logging.getLogger(__name__)
27
- log_exception = exception_logging(log)
28
-
29
-
30
- class TyperCommandsRegistration:
31
- def __init__(self, plugins: List[LoadedCommandPlugin]):
32
- self._plugins = plugins
33
- self._main_typer_command_group = (
34
- self._get_main_typer_command_group_from_click_context()
35
- )
36
-
37
- def register_commands(self):
38
- for plugin in self._plugins:
39
- try:
40
- self._add_plugin_to_typer(plugin.command_spec)
41
- except Exception as ex:
42
- log_exception(
43
- f"Cannot register plugin [{plugin.plugin_name}]: {ex.__str__()}", ex
44
- )
45
-
46
- @staticmethod
47
- def _get_main_typer_command_group_from_click_context() -> TyperGroup:
48
- main_typer_command_group = click.get_current_context().command
49
- if isinstance(main_typer_command_group, TyperGroup):
50
- return main_typer_command_group
51
- else:
52
- raise RuntimeError(
53
- "Invalid main top-level command type. It should be a TyperGroup but it is not."
54
- )
55
-
56
- def _add_plugin_to_typer(
57
- self,
58
- command_spec: CommandSpec,
59
- ) -> None:
60
- command_spec = self._adjust_command_spec_if_required(command_spec)
61
- parent_group = self._find_typer_group_at_path(
62
- current_level_group=self._main_typer_command_group,
63
- remaining_parent_path_segments=command_spec.parent_command_path.path_segments,
64
- command_spec=command_spec,
65
- )
66
- self._validate_command_spec(command_spec, parent_group)
67
- parent_group.add_command(command_spec.command)
68
-
69
- def _adjust_command_spec_if_required(
70
- self,
71
- command_spec: CommandSpec,
72
- ) -> CommandSpec:
73
- command_spec = self._add_empty_callback_to_command_spec_if_required(
74
- command_spec
75
- )
76
- return command_spec
77
-
78
- @staticmethod
79
- def _add_empty_callback_to_command_spec_if_required(
80
- command_spec: CommandSpec,
81
- ) -> CommandSpec:
82
- new_command_spec = command_spec
83
- is_specified_as_command_group = (
84
- command_spec.command_type == CommandType.COMMAND_GROUP
85
- )
86
- is_typer_group = isinstance(command_spec.command, TyperGroup)
87
- if is_specified_as_command_group and not is_typer_group:
88
- typer_instance = command_spec.typer_instance
89
- typer_instance.callback()(lambda: None)
90
- new_command_spec = CommandSpec(
91
- parent_command_path=command_spec.parent_command_path,
92
- command_type=command_spec.command_type,
93
- typer_instance=typer_instance,
94
- )
95
- return new_command_spec
96
-
97
- @staticmethod
98
- def _validate_command_spec(
99
- command_spec: CommandSpec,
100
- parent_group: TyperGroup,
101
- ) -> None:
102
- command = command_spec.command
103
- command_type = command_spec.command_type
104
- is_typer_group = isinstance(command, TyperGroup)
105
- if command.name in parent_group.commands:
106
- raise RuntimeError(
107
- f"Cannot add command [{command_spec.full_command_path}] because it already exists."
108
- )
109
- if command_type == CommandType.SINGLE_COMMAND and is_typer_group:
110
- raise RuntimeError(
111
- f"Cannot add command [{command_spec.full_command_path}] "
112
- + f"because its command type is {CommandType.SINGLE_COMMAND} "
113
- + f"while its implementation contains elements "
114
- + f"making it a TyperGroup ({CommandType.COMMAND_GROUP}) "
115
- + f"(a callback or multiple nested commands)."
116
- )
117
- if command_type == CommandType.COMMAND_GROUP and not is_typer_group:
118
- raise RuntimeError(
119
- f"Cannot add command [{command_spec.full_command_path}] "
120
- + f"because its command type is {CommandType.COMMAND_GROUP} "
121
- + f"while its implementation is not a TyperGroup."
122
- )
123
-
124
- def _find_typer_group_at_path(
125
- self,
126
- current_level_group: TyperGroup,
127
- remaining_parent_path_segments: List[str],
128
- command_spec: CommandSpec,
129
- ) -> TyperGroup:
130
- if remaining_parent_path_segments:
131
- expected_name = remaining_parent_path_segments[0]
132
- matching_subgroups = [
133
- subgroup
134
- for subgroup in current_level_group.commands.values()
135
- if isinstance(subgroup, TyperGroup) and subgroup.name == expected_name
136
- ]
137
- if matching_subgroups:
138
- return self._find_typer_group_at_path(
139
- current_level_group=matching_subgroups[0],
140
- remaining_parent_path_segments=remaining_parent_path_segments[1:],
141
- command_spec=command_spec,
142
- )
143
- else:
144
- raise RuntimeError(
145
- f"Invalid command path [{command_spec.full_command_path}]. "
146
- f"Command group [{expected_name}] does not exist."
147
- )
148
- else:
149
- return current_level_group
150
-
151
-
152
- def register_commands_from_plugins(plugins: List[LoadedCommandPlugin]) -> None:
153
- return TyperCommandsRegistration(plugins).register_commands()
@@ -1,19 +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 Literal
18
-
19
- PARAM_APPLICATION_NAME: Literal["snowcli"] = "snowcli"
@@ -1,13 +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.
@@ -1,48 +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 dataclass, field
18
- from typing import Dict
19
-
20
- from click import Command
21
-
22
-
23
- @dataclass
24
- class _Node:
25
- name: str
26
- children: Dict[str, _Node] = field(default_factory=dict)
27
- level: int = 0
28
-
29
- def print_node(self):
30
- print(" " * self.level, self.name)
31
- for ch in self.children.values():
32
- ch.print_node()
33
-
34
-
35
- def generate_commands_structure(command: Command, root: _Node | None = None):
36
- """
37
- Iterates recursively through commands info. Creates tree-like structure
38
- of commands.
39
- """
40
- if not root:
41
- root = _Node(name="snow")
42
-
43
- if hasattr(command, "commands"):
44
- for command_name, command_info in command.commands.items():
45
- if command_name not in root.children:
46
- root.children[command_name] = _Node(command_name, level=root.level + 1)
47
- generate_commands_structure(command_info, root.children[command_name])
48
- return root
@@ -1,13 +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.
@@ -1,100 +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 List, Optional
19
-
20
- from click import Command
21
- from snowflake.cli.api.secure_path import SecurePath
22
- from snowflake.cli.app.dev.docs.template_utils import get_template_environment
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
- with file_path.open("w+") as fh:
90
- fh.write(
91
- template.render(
92
- {
93
- "help": command.help,
94
- "name": command_name,
95
- "options": options,
96
- "arguments": arguments,
97
- "path": path,
98
- }
99
- )
100
- )
@@ -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.api.secure_path import SecurePath
21
- from snowflake.cli.app.dev.docs.commands_docs_generator import generate_command_docs
22
- from snowflake.cli.app.dev.docs.project_definition_docs_generator import (
23
- generate_project_definition_docs,
24
- )
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.api.project.schemas.project_definition import DefinitionV11
22
- from snowflake.cli.api.secure_path import SecurePath
23
- from snowflake.cli.app.dev.docs.project_definition_generate_json_schema import (
24
- ProjectDefinitionGenerateJsonSchema,
25
- )
26
- from snowflake.cli.app.dev.docs.template_utils import get_template_environment
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