snowflake-cli-labs 3.0.0rc5__py3-none-any.whl → 3.0.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 (244) hide show
  1. README.md +21 -0
  2. {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/METADATA +6 -96
  3. snowflake_cli_labs-3.0.2.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 -90
  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 -400
  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.0rc5.dist-info/RECORD +0 -242
  242. snowflake_cli_labs-3.0.0rc5.dist-info/entry_points.txt +0 -2
  243. {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/WHEEL +0 -0
  244. {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/licenses/LICENSE +0 -0
@@ -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
- from contextlib import contextmanager
18
- from contextvars import ContextVar
19
- from dataclasses import dataclass, field, replace
20
- from pathlib import Path
21
- from typing import TYPE_CHECKING, Iterator
22
-
23
- from snowflake.cli.api.connections import ConnectionContext, OpenConnectionCache
24
- from snowflake.cli.api.exceptions import MissingConfiguration
25
- from snowflake.cli.api.metrics import CLIMetrics
26
- from snowflake.cli.api.output.formats import OutputFormat
27
- from snowflake.cli.api.rendering.jinja import CONTEXT_KEY
28
- from snowflake.connector import SnowflakeConnection
29
-
30
- if TYPE_CHECKING:
31
- from snowflake.cli.api.project.definition_manager import DefinitionManager
32
- from snowflake.cli.api.project.schemas.project_definition import ProjectDefinition
33
-
34
- _CONNECTION_CACHE = OpenConnectionCache()
35
-
36
-
37
- @dataclass
38
- class _CliGlobalContextManager:
39
- connection_context: ConnectionContext = field(default_factory=ConnectionContext)
40
- connection_cache: OpenConnectionCache = (
41
- _CONNECTION_CACHE # by default, use global cache
42
- )
43
-
44
- output_format: OutputFormat = OutputFormat.TABLE
45
- silent: bool = False
46
- verbose: bool = False
47
- experimental: bool = False
48
- enable_tracebacks: bool = True
49
-
50
- metrics: CLIMetrics = field(default_factory=CLIMetrics)
51
-
52
- project_path_arg: str | None = None
53
- project_is_optional: bool = True
54
- project_env_overrides_args: dict[str, str] = field(default_factory=dict)
55
-
56
- # FIXME: this property only exists to help implement
57
- # nativeapp_definition_v2_to_v1. Consider changing the way
58
- # this calculation is provided to commands in order to remove
59
- # this logic (then make project_definition a non-cloned @property)
60
- override_project_definition: ProjectDefinition | None = None
61
-
62
- _definition_manager: DefinitionManager | None = None
63
-
64
- # which properties invalidate our current DefinitionManager?
65
- DEFINITION_MANAGER_DEPENDENCIES = [
66
- "project_path_arg",
67
- "project_is_optional",
68
- "project_env_overrides_args",
69
- ]
70
-
71
- def reset(self):
72
- self.__init__()
73
-
74
- def clone(self) -> _CliGlobalContextManager:
75
- return replace(
76
- self,
77
- connection_context=self.connection_context.clone(),
78
- project_env_overrides_args=self.project_env_overrides_args.copy(),
79
- )
80
-
81
- def __setattr__(self, prop, val):
82
- if prop in self.DEFINITION_MANAGER_DEPENDENCIES:
83
- self._clear_definition_manager()
84
-
85
- super().__setattr__(prop, val)
86
-
87
- @property
88
- def project_definition(self) -> ProjectDefinition | None:
89
- if self.override_project_definition:
90
- return self.override_project_definition
91
-
92
- return self._definition_manager_or_raise().project_definition
93
-
94
- @property
95
- def project_root(self) -> Path:
96
- return Path(self._definition_manager_or_raise().project_root)
97
-
98
- @property
99
- def template_context(self) -> dict:
100
- return self._definition_manager_or_raise().template_context
101
-
102
- @property
103
- def connection(self) -> SnowflakeConnection:
104
- """
105
- Returns a connection for our configured context from the configured cache.
106
- By default, this is the global _CONNECTION_CACHE. If a matching connection
107
- does not already exist, creates a new connection and caches it.
108
- """
109
- self.connection_context.validate_and_complete()
110
- return self.connection_cache[self.connection_context]
111
-
112
- def _definition_manager_or_raise(self) -> DefinitionManager:
113
- """
114
- (Re-)parses project definition based on project args (project_path_arg and
115
- project_env_overrides_args). If we cannot provide a project definition
116
- (i.e. no snowflake.yml) and require one, raises MissingConfiguration.
117
- """
118
- from snowflake.cli.api.project.definition_manager import DefinitionManager
119
-
120
- # don't need to re-parse definition if we already have one
121
- if not self._definition_manager:
122
- dm = DefinitionManager(
123
- self.project_path_arg,
124
- {CONTEXT_KEY: {"env": self.project_env_overrides_args}},
125
- )
126
- if not dm.has_definition_file and not self.project_is_optional:
127
- raise MissingConfiguration(
128
- "Cannot find project definition (snowflake.yml). Please provide a path to the project or run this command in a valid project directory."
129
- )
130
- self._definition_manager = dm
131
-
132
- return self._definition_manager
133
-
134
- def _clear_definition_manager(self):
135
- """
136
- Force re-calculation of definition_manager and its dependent attributes
137
- (template_context, project_definition, and project_root).
138
- """
139
- self._definition_manager = None
140
-
141
-
142
- class _CliGlobalContextAccess:
143
- def __init__(self, manager: _CliGlobalContextManager):
144
- self._manager = manager
145
-
146
- @property
147
- def connection(self) -> SnowflakeConnection:
148
- return self._manager.connection
149
-
150
- @property
151
- def connection_context(self) -> ConnectionContext:
152
- return self._manager.connection_context
153
-
154
- @property
155
- def enable_tracebacks(self) -> bool:
156
- return self._manager.enable_tracebacks
157
-
158
- @property
159
- def metrics(self):
160
- return self._manager.metrics
161
-
162
- @property
163
- def output_format(self) -> OutputFormat:
164
- return self._manager.output_format
165
-
166
- @property
167
- def verbose(self) -> bool:
168
- return self._manager.verbose
169
-
170
- @property
171
- def experimental(self) -> bool:
172
- return self._manager.experimental
173
-
174
- @property
175
- def project_definition(self) -> ProjectDefinition | None:
176
- return self._manager.project_definition
177
-
178
- @property
179
- def project_root(self) -> Path | None:
180
- return self._manager.project_root
181
-
182
- @property
183
- def template_context(self) -> dict:
184
- return self._manager.template_context
185
-
186
- @property
187
- def silent(self) -> bool:
188
- if self._should_force_mute_intermediate_output:
189
- return True
190
- return self._manager.silent
191
-
192
- @property
193
- def _should_force_mute_intermediate_output(self) -> bool:
194
- """Computes whether cli_console output should be muted."""
195
- return self._manager.output_format == OutputFormat.JSON
196
-
197
-
198
- _CLI_CONTEXT_MANAGER: ContextVar[_CliGlobalContextManager | None] = ContextVar(
199
- "cli_context", default=None
200
- )
201
-
202
-
203
- def get_cli_context_manager() -> _CliGlobalContextManager:
204
- mgr = _CLI_CONTEXT_MANAGER.get()
205
- if not mgr:
206
- mgr = _CliGlobalContextManager()
207
- _CLI_CONTEXT_MANAGER.set(mgr)
208
- return mgr
209
-
210
-
211
- def get_cli_context() -> _CliGlobalContextAccess:
212
- return _CliGlobalContextAccess(get_cli_context_manager())
213
-
214
-
215
- @contextmanager
216
- def fork_cli_context(
217
- connection_overrides: dict | None = None,
218
- project_env_overrides: dict[str, str] | None = None,
219
- project_is_optional: bool | None = None,
220
- project_path: str | None = None,
221
- ) -> Iterator[_CliGlobalContextAccess]:
222
- """
223
- Forks the global CLI context, making changes that are only visible
224
- (e.g. via get_cli_context()) while inside this context manager.
225
-
226
- Please note that environment variable changes are only visible through
227
- the project definition; os.getenv / os.environ / get_env_value are not
228
- affected by these new values.
229
- """
230
- old_manager = get_cli_context_manager()
231
- new_manager = old_manager.clone()
232
- token = _CLI_CONTEXT_MANAGER.set(new_manager)
233
-
234
- if connection_overrides:
235
- new_manager.connection_context.update(**connection_overrides)
236
-
237
- if project_env_overrides:
238
- new_manager.project_env_overrides_args.update(project_env_overrides)
239
-
240
- if project_is_optional is not None:
241
- new_manager.project_is_optional = project_is_optional
242
-
243
- if project_path:
244
- new_manager.project_path_arg = project_path
245
-
246
- yield _CliGlobalContextAccess(new_manager)
247
- _CLI_CONTEXT_MANAGER.reset(token)
@@ -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,23 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from copy import deepcopy
16
-
17
-
18
- def build_alias(main_app, name: str, help_str: str):
19
- alias = deepcopy(main_app)
20
- alias.info.name = name
21
- alias.info.help = help_str
22
- alias.info.hidden = True
23
- return alias
@@ -1,25 +0,0 @@
1
- from dataclasses import dataclass
2
- from enum import Enum
3
-
4
-
5
- class OnErrorType(Enum):
6
- """
7
- Command option values for what to do when an error occurs.
8
- """
9
-
10
- BREAK = "break"
11
- CONTINUE = "continue"
12
-
13
-
14
- @dataclass
15
- class Variable:
16
- """
17
- Key-value pair dataclass, returned after parsing "key=value" command options.
18
- """
19
-
20
- key: str
21
- value: str
22
-
23
- def __init__(self, key: str, value: str):
24
- self.key = key
25
- self.value = value
@@ -1,369 +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 inspect
18
- from functools import wraps
19
- from inspect import Signature
20
- from typing import Callable, Dict, List, Optional, get_type_hints
21
-
22
- from snowflake.cli.api.cli_global_context import get_cli_context
23
- from snowflake.cli.api.commands.flags import (
24
- AccountOption,
25
- AuthenticatorOption,
26
- ConnectionOption,
27
- DatabaseOption,
28
- DebugOption,
29
- DiagAllowlistPathOption,
30
- DiagLogPathOption,
31
- EnableDiagOption,
32
- HostOption,
33
- MasterTokenOption,
34
- MfaPasscodeOption,
35
- OutputFormatOption,
36
- PasswordOption,
37
- PortOption,
38
- PrivateKeyPathOption,
39
- RoleOption,
40
- SchemaOption,
41
- SessionTokenOption,
42
- SilentOption,
43
- TemporaryConnectionOption,
44
- TokenFilePathOption,
45
- UserOption,
46
- VerboseOption,
47
- WarehouseOption,
48
- experimental_option,
49
- project_definition_option,
50
- project_env_overrides_option,
51
- )
52
- from snowflake.cli.api.exceptions import CommandReturnTypeError
53
- from snowflake.cli.api.output.formats import OutputFormat
54
- from snowflake.cli.api.output.types import CommandResult
55
-
56
-
57
- def global_options(func: Callable):
58
- """
59
- Decorator providing default flags for overriding global parameters. Values are
60
- updated in global SnowCLI state.
61
-
62
- To use this decorator your command needs to accept **options as last argument.
63
- """
64
- return _global_options_decorator_factory(func, GLOBAL_OPTIONS)
65
-
66
-
67
- def global_options_with_connection(func: Callable):
68
- """
69
- Decorator providing default flags including connection flags for overriding
70
- global parameters. Values are updated in global SnowCLI state.
71
-
72
- To use this decorator your command needs to accept **options as last argument.
73
- """
74
- return _global_options_decorator_factory(
75
- func, [*GLOBAL_CONNECTION_OPTIONS, *GLOBAL_OPTIONS]
76
- )
77
-
78
-
79
- def with_project_definition(is_optional: bool = False):
80
- def _decorator(func: Callable):
81
-
82
- return _options_decorator_factory(
83
- func,
84
- additional_options=[
85
- inspect.Parameter(
86
- "project_definition",
87
- inspect.Parameter.KEYWORD_ONLY,
88
- annotation=Optional[str],
89
- default=project_definition_option(is_optional),
90
- ),
91
- inspect.Parameter(
92
- "env_overrides",
93
- inspect.Parameter.KEYWORD_ONLY,
94
- annotation=List[str],
95
- default=project_env_overrides_option(),
96
- ),
97
- ],
98
- )
99
-
100
- return _decorator
101
-
102
-
103
- def with_experimental_behaviour(
104
- experimental_behaviour_description: Optional[str] = None,
105
- ):
106
- """
107
- Decorator providing --experimental flag, which allows to use experimental behaviour in commands implementation.
108
-
109
- To use this decorator your command needs to accept **options as last argument.
110
- """
111
- additional_options = [
112
- inspect.Parameter(
113
- "experimental",
114
- inspect.Parameter.KEYWORD_ONLY,
115
- annotation=Optional[bool],
116
- default=experimental_option(experimental_behaviour_description),
117
- ),
118
- ]
119
-
120
- def decorator(func: Callable):
121
- return _options_decorator_factory(
122
- func=func,
123
- additional_options=additional_options,
124
- )
125
-
126
- return decorator
127
-
128
-
129
- def _execute_before_command_using_global_options(**options):
130
- from snowflake.cli._app.loggers import create_loggers
131
-
132
- cli_context = get_cli_context()
133
- create_loggers(cli_context.verbose, cli_context.enable_tracebacks)
134
-
135
-
136
- def _global_options_decorator_factory(
137
- func: Callable, additional_options: List[inspect.Parameter]
138
- ):
139
- return _options_decorator_factory(
140
- func=func,
141
- additional_options=additional_options,
142
- execute_before_command_using_new_options=_execute_before_command_using_global_options,
143
- )
144
-
145
-
146
- def _options_decorator_factory(
147
- func: Callable,
148
- additional_options: List[inspect.Parameter],
149
- execute_before_command_using_new_options: Optional[Callable] = None,
150
- ):
151
- """
152
- execute_before_command_using_new_options executes before command telemetry has been emitted,
153
- but after command line options have been populated.
154
- """
155
-
156
- @wraps(func)
157
- def wrapper(**options):
158
- if execute_before_command_using_new_options:
159
- execute_before_command_using_new_options(**options)
160
- return func(**options)
161
-
162
- wrapper.__signature__ = _extend_signature_with_additional_options(func, additional_options) # type: ignore
163
- return wrapper
164
-
165
-
166
- def _extend_signature_with_additional_options(
167
- func: Callable, additional_options: List[inspect.Parameter]
168
- ) -> Signature:
169
- """Extends function signature with additional options"""
170
- sig = inspect.signature(func)
171
-
172
- # Remove **options from signature
173
- existing_parameters = tuple(
174
- [p for p in sig.parameters.values() if not _is_options_parameter(p)]
175
- )
176
-
177
- type_hints = get_type_hints(func)
178
- existing_parameters_with_evaluated_types = [
179
- _evaluate_param_type(p, type_hints) for p in existing_parameters
180
- ]
181
- parameters = [
182
- *existing_parameters_with_evaluated_types,
183
- *additional_options,
184
- ]
185
- return sig.replace(parameters=parameters)
186
-
187
-
188
- def _is_options_parameter(param: inspect.Parameter) -> bool:
189
- return param.kind == inspect.Parameter.VAR_KEYWORD and param.name == "options"
190
-
191
-
192
- def _evaluate_param_type(
193
- param: inspect.Parameter, type_hints: Dict[str, type]
194
- ) -> inspect.Parameter:
195
- type_annotation = (
196
- type_hints.get(param.annotation)
197
- if isinstance(param.annotation, str)
198
- else param.annotation
199
- )
200
- return inspect.Parameter(
201
- name=param.name,
202
- kind=param.kind,
203
- annotation=type_annotation,
204
- default=param.default,
205
- )
206
-
207
-
208
- GLOBAL_CONNECTION_OPTIONS = [
209
- inspect.Parameter(
210
- "connection",
211
- inspect.Parameter.KEYWORD_ONLY,
212
- annotation=Optional[str],
213
- default=ConnectionOption,
214
- ),
215
- inspect.Parameter(
216
- "host",
217
- inspect.Parameter.KEYWORD_ONLY,
218
- annotation=Optional[str],
219
- default=HostOption,
220
- ),
221
- inspect.Parameter(
222
- "port",
223
- inspect.Parameter.KEYWORD_ONLY,
224
- annotation=Optional[int],
225
- default=PortOption,
226
- ),
227
- inspect.Parameter(
228
- "account",
229
- inspect.Parameter.KEYWORD_ONLY,
230
- annotation=Optional[str],
231
- default=AccountOption,
232
- ),
233
- inspect.Parameter(
234
- "user",
235
- inspect.Parameter.KEYWORD_ONLY,
236
- annotation=Optional[str],
237
- default=UserOption,
238
- ),
239
- inspect.Parameter(
240
- "password",
241
- inspect.Parameter.KEYWORD_ONLY,
242
- annotation=Optional[str],
243
- default=PasswordOption,
244
- ),
245
- inspect.Parameter(
246
- "authenticator",
247
- inspect.Parameter.KEYWORD_ONLY,
248
- annotation=Optional[str],
249
- default=AuthenticatorOption,
250
- ),
251
- inspect.Parameter(
252
- "private_key_file",
253
- inspect.Parameter.KEYWORD_ONLY,
254
- annotation=Optional[str],
255
- default=PrivateKeyPathOption,
256
- ),
257
- inspect.Parameter(
258
- "session_token",
259
- inspect.Parameter.KEYWORD_ONLY,
260
- annotation=Optional[str],
261
- default=SessionTokenOption,
262
- ),
263
- inspect.Parameter(
264
- "master_token",
265
- inspect.Parameter.KEYWORD_ONLY,
266
- annotation=Optional[str],
267
- default=MasterTokenOption,
268
- ),
269
- inspect.Parameter(
270
- "token_file_path",
271
- inspect.Parameter.KEYWORD_ONLY,
272
- annotation=Optional[str],
273
- default=TokenFilePathOption,
274
- ),
275
- inspect.Parameter(
276
- "database",
277
- inspect.Parameter.KEYWORD_ONLY,
278
- annotation=Optional[str],
279
- default=DatabaseOption,
280
- ),
281
- inspect.Parameter(
282
- "schema",
283
- inspect.Parameter.KEYWORD_ONLY,
284
- annotation=Optional[str],
285
- default=SchemaOption,
286
- ),
287
- inspect.Parameter(
288
- "role",
289
- inspect.Parameter.KEYWORD_ONLY,
290
- annotation=Optional[str],
291
- default=RoleOption,
292
- ),
293
- inspect.Parameter(
294
- "warehouse",
295
- inspect.Parameter.KEYWORD_ONLY,
296
- annotation=Optional[str],
297
- default=WarehouseOption,
298
- ),
299
- inspect.Parameter(
300
- "temporary_connection",
301
- inspect.Parameter.KEYWORD_ONLY,
302
- annotation=Optional[bool],
303
- default=TemporaryConnectionOption,
304
- ),
305
- inspect.Parameter(
306
- "mfa_passcode",
307
- inspect.Parameter.KEYWORD_ONLY,
308
- annotation=Optional[str],
309
- default=MfaPasscodeOption,
310
- ),
311
- inspect.Parameter(
312
- "enable_diag",
313
- inspect.Parameter.KEYWORD_ONLY,
314
- annotation=Optional[bool],
315
- default=EnableDiagOption,
316
- ),
317
- inspect.Parameter(
318
- "diag_log_path",
319
- inspect.Parameter.KEYWORD_ONLY,
320
- annotation=Optional[str],
321
- default=DiagLogPathOption,
322
- ),
323
- inspect.Parameter(
324
- "diag_allowlist_path",
325
- inspect.Parameter.KEYWORD_ONLY,
326
- annotation=Optional[str],
327
- default=DiagAllowlistPathOption,
328
- ),
329
- ]
330
-
331
- GLOBAL_OPTIONS = [
332
- inspect.Parameter(
333
- "format",
334
- inspect.Parameter.KEYWORD_ONLY,
335
- annotation=OutputFormat,
336
- default=OutputFormatOption,
337
- ),
338
- inspect.Parameter(
339
- "verbose",
340
- inspect.Parameter.KEYWORD_ONLY,
341
- annotation=Optional[bool],
342
- default=VerboseOption,
343
- ),
344
- inspect.Parameter(
345
- "debug",
346
- inspect.Parameter.KEYWORD_ONLY,
347
- annotation=Optional[bool],
348
- default=DebugOption,
349
- ),
350
- inspect.Parameter(
351
- "silent",
352
- inspect.Parameter.KEYWORD_ONLY,
353
- annotation=Optional[bool],
354
- default=SilentOption,
355
- ),
356
- ]
357
-
358
-
359
- def with_output(func):
360
- from snowflake.cli._app.printing import print_result
361
-
362
- @wraps(func)
363
- def wrapper(*args, **kwargs):
364
- output_data = func(*args, **kwargs)
365
- if not isinstance(output_data, CommandResult):
366
- raise CommandReturnTypeError(type(output_data))
367
- print_result(output_data)
368
-
369
- return wrapper