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,169 +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 Dict, List, Optional
19
-
20
- import pluggy
21
- from snowflake.cli._app.commands_registration import (
22
- LoadedBuiltInCommandPlugin,
23
- LoadedCommandPlugin,
24
- LoadedExternalCommandPlugin,
25
- )
26
- from snowflake.cli._app.commands_registration.builtin_plugins import (
27
- get_builtin_plugin_name_to_plugin_spec,
28
- )
29
- from snowflake.cli._app.commands_registration.exception_logging import exception_logging
30
- from snowflake.cli.api.plugins.command import (
31
- SNOWCLI_COMMAND_PLUGIN_NAMESPACE,
32
- CommandPath,
33
- CommandSpec,
34
- plugin_hook_specs,
35
- )
36
-
37
- log = logging.getLogger(__name__)
38
- log_exception = exception_logging(log)
39
-
40
-
41
- class CommandPluginsLoader:
42
- def __init__(self):
43
- plugin_manager = pluggy.PluginManager(SNOWCLI_COMMAND_PLUGIN_NAMESPACE)
44
- plugin_manager.add_hookspecs(plugin_hook_specs)
45
- self._plugin_manager = plugin_manager
46
- self._loaded_plugins: Dict[str, LoadedCommandPlugin] = {}
47
- self._loaded_command_paths: Dict[CommandPath, LoadedCommandPlugin] = {}
48
-
49
- def register_builtin_plugins(self) -> None:
50
- for plugin_name, plugin in get_builtin_plugin_name_to_plugin_spec().items():
51
- try:
52
- self._plugin_manager.register(plugin=plugin, name=plugin_name)
53
- except Exception as ex:
54
- log_exception(
55
- f"Cannot register plugin [{plugin_name}]: {ex.__str__()}", ex
56
- )
57
-
58
- def register_external_plugins(self, plugin_names: List[str]) -> None:
59
- for plugin_name in plugin_names:
60
- try:
61
- self._plugin_manager.load_setuptools_entrypoints(
62
- SNOWCLI_COMMAND_PLUGIN_NAMESPACE, plugin_name
63
- )
64
- except Exception as ex:
65
- log_exception(
66
- f"Cannot register plugin [{plugin_name}]: {ex.__str__()}", ex
67
- )
68
-
69
- def load_all_registered_plugins(self) -> List[LoadedCommandPlugin]:
70
- for plugin_name, plugin in self._plugin_manager.list_name_plugin():
71
- self._load_plugin(plugin_name, plugin)
72
- return list(self._loaded_plugins.values())
73
-
74
- def _load_plugin(self, plugin_name: str, plugin) -> Optional[LoadedCommandPlugin]:
75
- already_loaded_plugin = self._loaded_plugins.get(plugin_name)
76
- if already_loaded_plugin:
77
- return already_loaded_plugin
78
- return self._load_new_plugin(plugin_name, plugin)
79
-
80
- def _load_new_plugin(
81
- self, plugin_name: str, plugin
82
- ) -> Optional[LoadedCommandPlugin]:
83
- loaded_plugin = self._load_plugin_spec(plugin_name, plugin)
84
- if not loaded_plugin:
85
- return None
86
- other_plugin_with_the_same_command_path = self._loaded_command_paths.get(
87
- loaded_plugin.command_spec.full_command_path
88
- )
89
- if other_plugin_with_the_same_command_path:
90
- log.error(
91
- "Cannot load plugin [%s] "
92
- "because it defines the same command [%s] "
93
- "as already loaded plugin [%s].",
94
- plugin_name,
95
- loaded_plugin.command_spec.full_command_path,
96
- other_plugin_with_the_same_command_path.plugin_name,
97
- )
98
- return None
99
- self._loaded_plugins[plugin_name] = loaded_plugin
100
- self._loaded_command_paths[
101
- loaded_plugin.command_spec.full_command_path
102
- ] = loaded_plugin
103
-
104
- if self._is_external_plugin(loaded_plugin):
105
- log.info("Loaded external plugin: %s", plugin_name)
106
-
107
- return loaded_plugin
108
-
109
- def _load_plugin_spec(
110
- self, plugin_name: str, plugin
111
- ) -> Optional[LoadedCommandPlugin]:
112
- if plugin_name in get_builtin_plugin_name_to_plugin_spec().keys():
113
- return self._load_builtin_plugin_spec(plugin_name, plugin)
114
- else:
115
- return self._load_external_plugin_spec(plugin_name, plugin)
116
-
117
- def _load_builtin_plugin_spec(
118
- self, plugin_name: str, plugin
119
- ) -> Optional[LoadedCommandPlugin]:
120
- command_spec = self._load_command_spec(plugin_name, plugin)
121
- if command_spec:
122
- return LoadedBuiltInCommandPlugin(
123
- plugin_name=plugin_name,
124
- command_spec=command_spec,
125
- )
126
- else:
127
- return None
128
-
129
- def _load_external_plugin_spec(
130
- self, plugin_name: str, plugin
131
- ) -> Optional[LoadedCommandPlugin]:
132
- command_spec = self._load_command_spec(plugin_name, plugin)
133
- if command_spec:
134
- return LoadedExternalCommandPlugin(
135
- plugin_name=plugin_name,
136
- command_spec=command_spec,
137
- )
138
- else:
139
- return None
140
-
141
- @staticmethod
142
- def _load_command_spec(plugin_name: str, plugin) -> Optional[CommandSpec]:
143
- try:
144
- return plugin.command_spec()
145
- except Exception as ex:
146
- log_exception(
147
- f"Cannot load command specification from plugin [{plugin_name}]: {ex.__str__()}",
148
- ex,
149
- )
150
- return None
151
-
152
- @staticmethod
153
- def _is_external_plugin(plugin) -> bool:
154
- return isinstance(plugin, LoadedExternalCommandPlugin)
155
-
156
-
157
- def load_only_builtin_command_plugins() -> List[LoadedCommandPlugin]:
158
- loader = CommandPluginsLoader()
159
- loader.register_builtin_plugins()
160
- return loader.load_all_registered_plugins()
161
-
162
-
163
- def load_builtin_and_external_command_plugins(
164
- external_plugin_names: List[str],
165
- ) -> List[LoadedCommandPlugin]:
166
- loader = CommandPluginsLoader()
167
- loader.register_builtin_plugins()
168
- loader.register_external_plugins(external_plugin_names)
169
- return loader.load_all_registered_plugins()
@@ -1,105 +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
18
- from typing import Callable, List
19
-
20
- from snowflake.cli._app.commands_registration.command_plugins_loader import (
21
- load_builtin_and_external_command_plugins,
22
- load_only_builtin_command_plugins,
23
- )
24
- from snowflake.cli._app.commands_registration.threadsafe import ThreadsafeCounter
25
- from snowflake.cli._app.commands_registration.typer_registration import (
26
- register_commands_from_plugins,
27
- )
28
- from snowflake.cli.api.plugins.plugin_config import PluginConfigProvider
29
-
30
-
31
- @dataclass
32
- class CommandRegistrationConfig:
33
- enable_external_command_plugins: bool
34
-
35
-
36
- class CommandsRegistrationWithCallbacks:
37
- def __init__(self, plugin_config_provider: PluginConfigProvider):
38
- self._plugin_config_provider = plugin_config_provider
39
- self._counter_of_callbacks_required_before_registration: ThreadsafeCounter = (
40
- ThreadsafeCounter(0)
41
- )
42
- self._counter_of_callbacks_invoked_before_registration: ThreadsafeCounter = (
43
- ThreadsafeCounter(0)
44
- )
45
- self._callbacks_after_registration: List[Callable[[], None]] = []
46
- self._commands_registration_config: CommandRegistrationConfig = (
47
- CommandRegistrationConfig(enable_external_command_plugins=True)
48
- )
49
- self._commands_already_registered: bool = False
50
-
51
- def register_commands_if_ready_and_not_registered_yet(self):
52
- all_required_callbacks_executed = (
53
- self._counter_of_callbacks_required_before_registration.value
54
- == self._counter_of_callbacks_invoked_before_registration.value
55
- )
56
- if all_required_callbacks_executed and not self._commands_already_registered:
57
- self._register_commands_from_plugins()
58
-
59
- def _register_commands_from_plugins(self) -> None:
60
- if self._commands_registration_config.enable_external_command_plugins:
61
- self._register_builtin_and_enabled_external_plugin_commands()
62
- else:
63
- self._register_only_builtin_plugin_commands()
64
-
65
- self._commands_already_registered = True
66
- for callback in self._callbacks_after_registration:
67
- callback()
68
-
69
- @staticmethod
70
- def _register_only_builtin_plugin_commands() -> None:
71
- loaded_command_plugins = load_only_builtin_command_plugins()
72
- register_commands_from_plugins(loaded_command_plugins)
73
-
74
- def _register_builtin_and_enabled_external_plugin_commands(self):
75
- enabled_external_plugins = (
76
- self._plugin_config_provider.get_enabled_plugin_names()
77
- )
78
- loaded_command_plugins = load_builtin_and_external_command_plugins(
79
- enabled_external_plugins
80
- )
81
- register_commands_from_plugins(loaded_command_plugins)
82
-
83
- def disable_external_command_plugins(self):
84
- self._commands_registration_config.enable_external_command_plugins = False
85
-
86
- def before(self, callback):
87
- def enriched_callback(value):
88
- self._counter_of_callbacks_invoked_before_registration.increment()
89
- callback(value)
90
- self.register_commands_if_ready_and_not_registered_yet()
91
-
92
- self._counter_of_callbacks_required_before_registration.increment()
93
- return enriched_callback
94
-
95
- def after(self, callback):
96
- def delayed_callback(value):
97
- self._callbacks_after_registration.append(lambda: callback(value))
98
-
99
- return delayed_callback
100
-
101
- def reset_running_instance_registration_state(self):
102
- self._commands_already_registered = False
103
- self._counter_of_callbacks_invoked_before_registration.set(0)
104
- self._callbacks_after_registration.clear()
105
- self._commands_registration_config.enable_external_command_plugins = True
@@ -1,26 +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 logging import Logger
16
- from typing import Callable
17
-
18
- from snowflake.cli.api.cli_global_context import get_cli_context
19
-
20
-
21
- def exception_logging(logger: Logger) -> Callable[[str, Exception], None]:
22
- def log_error(msg: str, exception: Exception) -> None:
23
- exc_info = exception if get_cli_context().enable_tracebacks else None
24
- logger.error(msg=msg, exc_info=exc_info)
25
-
26
- return log_error
@@ -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
- import threading
18
- from typing import Callable, Generic, TypeVar
19
-
20
- T = TypeVar("T")
21
-
22
-
23
- class ThreadsafeValue(Generic[T]):
24
- def __init__(self, value: T):
25
- self._value = value
26
- self._lock = threading.Lock()
27
-
28
- def set(self, new_value: T) -> T: # noqa: A003
29
- return self.transform(lambda _: new_value)
30
-
31
- def transform(self, f: Callable[[T], T]) -> T:
32
- with self._lock:
33
- new_value = f(self._value)
34
- self._value = new_value
35
- return new_value
36
-
37
- @property
38
- def value(self) -> T:
39
- with self._lock:
40
- return self._value
41
-
42
-
43
- class ThreadsafeCounter(ThreadsafeValue[int]):
44
- def increment(self, d=1) -> int:
45
- return self.transform(lambda v: v + d)
46
-
47
- def decrement(self, d=1) -> int:
48
- return self.increment(-d)
@@ -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._app.commands_registration import LoadedCommandPlugin
22
- from snowflake.cli._app.commands_registration.exception_logging import exception_logging
23
- from snowflake.cli.api.plugins.command import CommandSpec, CommandType
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.