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,143 +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 abc import ABC, abstractmethod
18
- from inspect import signature
19
- from typing import Any, List, Optional, Tuple
20
-
21
- import typer
22
- from click import ClickException
23
- from snowflake.cli.api.exceptions import IncompatibleParametersError
24
-
25
-
26
- class _OverrideableParameter(ABC):
27
- """
28
- Class that allows you to generate instances of typer.models.OptionInfo with some default properties while allowing
29
- specific values to be overridden.
30
-
31
- Custom parameters:
32
- - mutually_exclusive (Tuple[str]|List[str]): A list of parameter names that this Option is not compatible with. If this Option has
33
- a truthy value and any of the other parameters in the mutually_exclusive list has a truthy value, a
34
- ClickException will be thrown. Note that mutually_exclusive can contain an option's own name but does not require
35
- it.
36
- """
37
-
38
- def __init__(
39
- self,
40
- default: Any = ...,
41
- *param_decls: str,
42
- mutually_exclusive: Optional[List[str] | Tuple[str]] = None,
43
- **kwargs,
44
- ):
45
- self.default = default
46
- self.param_decls = param_decls
47
- self.mutually_exclusive = mutually_exclusive
48
- self.kwargs = kwargs
49
-
50
- def __call__(self, **kwargs) -> typer.models.ParameterInfo:
51
- """
52
- Returns a typer.models.OptionInfo instance initialized with the specified default values along with any overrides
53
- from kwargs. Note that if you are overriding param_decls, you must pass an iterable of strings, you cannot use
54
- positional arguments like you can with typer.Option. Does not modify the original instance.
55
- """
56
- default = kwargs.get("default", self.default)
57
- param_decls = kwargs.get("param_decls", self.param_decls)
58
- mutually_exclusive = kwargs.get("mutually_exclusive", self.mutually_exclusive)
59
- if not isinstance(param_decls, list) and not isinstance(param_decls, tuple):
60
- raise TypeError("param_decls must be a list or tuple")
61
- passed_kwargs = self.kwargs.copy()
62
- passed_kwargs.update(kwargs)
63
- if passed_kwargs.get("callback", None) or mutually_exclusive:
64
- passed_kwargs["callback"] = self._callback_factory(
65
- passed_kwargs.get("callback", None), mutually_exclusive
66
- )
67
- for non_kwarg in ["default", "param_decls", "mutually_exclusive"]:
68
- passed_kwargs.pop(non_kwarg, None)
69
-
70
- return self.get_parameter(default, *param_decls, **passed_kwargs)
71
-
72
- @abstractmethod
73
- def get_parameter(
74
- self, default: Any = None, *param_decls: str, **kwargs
75
- ) -> typer.models.ParameterInfo:
76
- pass
77
-
78
- class InvalidCallbackSignature(ClickException):
79
- def __init__(self, callback):
80
- super().__init__(
81
- f"Signature {signature(callback)} is not valid for an OverrideableOption callback function. Must have "
82
- f"at most one parameter with each of the following types: (typer.Context, typer.CallbackParam, "
83
- f"Any Other Type)"
84
- )
85
-
86
- def _callback_factory(
87
- self, callback, mutually_exclusive: Optional[List[str] | Tuple[str]]
88
- ):
89
- callback = callback if callback else lambda x: x
90
-
91
- # inspect existing_callback to make sure signature is valid
92
- existing_params = signature(callback).parameters
93
- # at most one parameter with each type in [typer.Context, typer.CallbackParam, any other type]
94
- limits = [
95
- lambda x: x == typer.Context,
96
- lambda x: x == typer.CallbackParam,
97
- lambda x: x != typer.Context and x != typer.CallbackParam,
98
- ]
99
- for limit in limits:
100
- if len([v for v in existing_params.values() if limit(v.annotation)]) > 1:
101
- raise self.InvalidCallbackSignature(callback)
102
-
103
- def generated_callback(ctx: typer.Context, param: typer.CallbackParam, value):
104
- if mutually_exclusive:
105
- for name in mutually_exclusive:
106
- if value and ctx.params.get(
107
- name, False
108
- ): # if the current parameter is set to True and a previous parameter is also Truthy
109
- curr_opt = param.opts[0]
110
- other_opt = [x for x in ctx.command.params if x.name == name][
111
- 0
112
- ].opts[0]
113
- raise IncompatibleParametersError([curr_opt, other_opt])
114
-
115
- # pass args to existing callback based on its signature (this is how Typer infers callback args)
116
- passed_params = {}
117
- for existing_param in existing_params:
118
- annotation = existing_params[existing_param].annotation
119
- if annotation == typer.Context:
120
- passed_params[existing_param] = ctx
121
- elif annotation == typer.CallbackParam:
122
- passed_params[existing_param] = param
123
- else:
124
- passed_params[existing_param] = value
125
- return callback(**passed_params)
126
-
127
- return generated_callback
128
-
129
-
130
- class OverrideableArgument(_OverrideableParameter):
131
- def get_parameter(
132
- self, default: Any = ..., *param_decls: str, **kwargs
133
- ) -> typer.models.ArgumentInfo:
134
- return typer.Argument(default, *param_decls, **kwargs)
135
-
136
-
137
- # OverrideableOption doesn't work with flags with type List[Any] and default None, because typer executes the callback
138
- # function which converts the default value iterating over it, but None is not iterable.
139
- class OverrideableOption(_OverrideableParameter):
140
- def get_parameter(
141
- self, default: Any = ..., *param_decls: str, **kwargs
142
- ) -> typer.models.OptionInfo:
143
- return typer.Option(default, *param_decls, **kwargs)
@@ -1,247 +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 dataclasses
18
- import logging
19
- from functools import wraps
20
- from typing import Any, Callable, Dict, List, Optional, Tuple
21
-
22
- import typer
23
- from click import ClickException
24
- from snowflake.cli.api.commands.decorators import (
25
- global_options,
26
- global_options_with_connection,
27
- )
28
- from snowflake.cli.api.commands.execution_metadata import (
29
- ExecutionMetadata,
30
- ExecutionStatus,
31
- )
32
- from snowflake.cli.api.commands.flags import DEFAULT_CONTEXT_SETTINGS
33
- from snowflake.cli.api.exceptions import CommandReturnTypeError
34
- from snowflake.cli.api.output.types import CommandResult
35
- from snowflake.cli.api.sanitizers import sanitize_for_terminal
36
- from snowflake.cli.api.sql_execution import SqlExecutionMixin
37
- from snowflake.connector import DatabaseError
38
-
39
- log = logging.getLogger(__name__)
40
-
41
-
42
- class SnowTyper(typer.Typer):
43
- def __init__(self, /, **kwargs):
44
- self._sanitize_kwargs(kwargs)
45
- super().__init__(
46
- **kwargs,
47
- context_settings=DEFAULT_CONTEXT_SETTINGS,
48
- pretty_exceptions_show_locals=False,
49
- no_args_is_help=True,
50
- add_completion=True,
51
- rich_markup_mode="markdown",
52
- )
53
-
54
- @staticmethod
55
- def _sanitize_kwargs(kwargs: Dict):
56
- # Sanitize all string options that are visible in terminal output
57
- known_keywords = [
58
- "help",
59
- "short_help",
60
- "options_metavar",
61
- "rich_help_panel",
62
- "epilog",
63
- ]
64
- for kw in known_keywords:
65
- if kw in kwargs:
66
- kwargs[kw] = sanitize_for_terminal(kwargs[kw])
67
- return kwargs
68
-
69
- @wraps(typer.Typer.command)
70
- def command(
71
- self,
72
- name: Optional[str] = None,
73
- requires_global_options: bool = True,
74
- requires_connection: bool = False,
75
- is_enabled: Callable[[], bool] | None = None,
76
- require_warehouse: bool = False,
77
- **kwargs,
78
- ):
79
- """
80
- Custom implementation of Typer.command that adds ability to execute additional
81
- logic before and after execution as well as process the result and act on possible
82
- errors.
83
- """
84
- name = sanitize_for_terminal(name)
85
- self._sanitize_kwargs(kwargs)
86
- if is_enabled is not None and not is_enabled():
87
- return lambda func: func
88
-
89
- def custom_command(command_callable):
90
- """Custom command wrapper similar to Typer.command."""
91
- # Sanitize doc string which is used to create help in terminal
92
- command_callable.__doc__ = sanitize_for_terminal(command_callable.__doc__)
93
-
94
- if requires_connection:
95
- command_callable = global_options_with_connection(command_callable)
96
- elif requires_global_options:
97
- command_callable = global_options(command_callable)
98
-
99
- @wraps(command_callable)
100
- def command_callable_decorator(*args, **kw):
101
- """Wrapper around command callable. This is what happens at "runtime"."""
102
- execution = ExecutionMetadata()
103
- self.pre_execute(execution, require_warehouse=require_warehouse)
104
- try:
105
- result = command_callable(*args, **kw)
106
- self.process_result(result)
107
- execution.complete(ExecutionStatus.SUCCESS)
108
- except BaseException as err:
109
- execution.complete(ExecutionStatus.FAILURE)
110
- exception = self.exception_handler(err, execution)
111
- raise exception
112
- finally:
113
- self.post_execute(execution)
114
-
115
- return super(SnowTyper, self).command(name=name, **kwargs)(
116
- command_callable_decorator
117
- )
118
-
119
- return custom_command
120
-
121
- @staticmethod
122
- def pre_execute(execution: ExecutionMetadata, require_warehouse: bool = False):
123
- """
124
- Callback executed before running any command callable (after context execution).
125
- Pay attention to make this method safe to use if performed operations are not necessary
126
- for executing the command in proper way.
127
- """
128
- from snowflake.cli._app.telemetry import log_command_usage
129
-
130
- log.debug("Executing command pre execution callback")
131
- log_command_usage(execution)
132
- if require_warehouse and not SqlExecutionMixin().session_has_warehouse():
133
- raise ClickException(
134
- "The command requires warehouse. No warehouse found in current connection."
135
- )
136
-
137
- @staticmethod
138
- def process_result(result):
139
- """Command result processor"""
140
- from snowflake.cli._app.printing import print_result
141
-
142
- # Because we still have commands like "logs" that do not return anything.
143
- # We should improve it in future.
144
- if not result:
145
- return
146
- if not isinstance(result, CommandResult):
147
- raise CommandReturnTypeError(type(result))
148
- print_result(result)
149
-
150
- @staticmethod
151
- def exception_handler(exception: Exception, execution: ExecutionMetadata):
152
- """
153
- Callback executed on command execution error.
154
- """
155
- from snowflake.cli._app.telemetry import log_command_execution_error
156
-
157
- log.debug("Executing command exception callback")
158
- log_command_execution_error(exception, execution)
159
- if isinstance(exception, DatabaseError):
160
- return ClickException(exception.msg)
161
- return exception
162
-
163
- @staticmethod
164
- def post_execute(execution: ExecutionMetadata):
165
- """
166
- Callback executed after running any command callable. Pay attention to make this method safe to
167
- use if performed operations are not necessary for executing the command in proper way.
168
- """
169
- from snowflake.cli._app.telemetry import flush_telemetry, log_command_result
170
-
171
- log.debug("Executing command post execution callback")
172
- log_command_result(execution)
173
- flush_telemetry()
174
-
175
-
176
- @dataclasses.dataclass
177
- class SnowTyperCommandData:
178
- """
179
- Class for storing data of commands to be registered in SnowTyper instances created by SnowTyperFactory.
180
- """
181
-
182
- func: Callable
183
- args: Tuple[Any, ...]
184
- kwargs: Dict[str, Any]
185
-
186
-
187
- class SnowTyperFactory:
188
- """
189
- SnowTyper factory. Usage is similar to SnowTyper, except that create_instance()
190
- creates actual SnowTyper instance.
191
- """
192
-
193
- def __init__(
194
- self,
195
- /,
196
- name: Optional[str] = None,
197
- help: Optional[str] = None, # noqa: A002
198
- short_help: Optional[str] = None,
199
- is_hidden: Optional[Callable[[], bool]] = None,
200
- deprecated: bool = False,
201
- ):
202
- self.name = name
203
- self.help = help
204
- self.short_help = short_help
205
- self.is_hidden = is_hidden
206
- self.deprecated = deprecated
207
- self.commands_to_register: List[SnowTyperCommandData] = []
208
- self.subapps_to_register: List[SnowTyperFactory] = []
209
- self.callbacks_to_register: List[Callable] = []
210
-
211
- def create_instance(self) -> SnowTyper:
212
- app = SnowTyper(
213
- name=self.name,
214
- help=self.help,
215
- short_help=self.short_help,
216
- hidden=self.is_hidden() if self.is_hidden else False,
217
- deprecated=self.deprecated,
218
- )
219
- # register commands
220
- for command in self.commands_to_register:
221
- app.command(*command.args, **command.kwargs)(command.func)
222
- # register callbacks
223
- for callback in self.callbacks_to_register:
224
- app.callback()(callback)
225
- # add subgroups
226
- for subapp in self.subapps_to_register:
227
- app.add_typer(subapp.create_instance())
228
- return app
229
-
230
- def command(self, *args, **kwargs):
231
- def decorator(command):
232
- self.commands_to_register.append(
233
- SnowTyperCommandData(command, args=args, kwargs=kwargs)
234
- )
235
- return command
236
-
237
- return decorator
238
-
239
- def add_typer(self, snow_typer: SnowTyperFactory) -> None:
240
- self.subapps_to_register.append(snow_typer)
241
-
242
- def callback(self):
243
- def decorator(callback):
244
- self.callbacks_to_register.append(callback)
245
- return callback
246
-
247
- return decorator
@@ -1,18 +0,0 @@
1
- from typing import List, Optional
2
-
3
- from click import ClickException
4
- from snowflake.cli.api.commands.common import Variable
5
-
6
-
7
- def parse_key_value_variables(variables: Optional[List[str]]) -> List[Variable]:
8
- """Util for parsing key=value input. Useful for commands accepting multiple input options."""
9
- result: List[Variable] = []
10
- if not variables:
11
- return result
12
- for p in variables:
13
- if "=" not in p:
14
- raise ClickException(f"Invalid variable: '{p}'")
15
-
16
- key, value = p.split("=", 1)
17
- result.append(Variable(key.strip(), value.strip()))
18
- return result