snowflake-cli-labs 2.8.0rc1__py3-none-any.whl → 3.0.0rc1__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 (224) hide show
  1. snowflake/cli/__about__.py +1 -1
  2. snowflake/cli/{app → _app}/__main__.py +1 -1
  3. snowflake/cli/{app → _app}/cli_app.py +12 -12
  4. snowflake/cli/{app → _app}/commands_registration/builtin_plugins.py +13 -19
  5. snowflake/cli/{app → _app}/commands_registration/command_plugins_loader.py +9 -9
  6. snowflake/cli/{app → _app}/commands_registration/commands_registration_with_callbacks.py +4 -4
  7. snowflake/cli/{app → _app}/commands_registration/exception_logging.py +2 -2
  8. snowflake/cli/{app → _app}/commands_registration/typer_registration.py +2 -2
  9. snowflake/cli/{app → _app}/dev/docs/commands_docs_generator.py +30 -12
  10. snowflake/cli/{app → _app}/dev/docs/generator.py +3 -3
  11. snowflake/cli/{app → _app}/dev/docs/project_definition_docs_generator.py +4 -4
  12. snowflake/cli/{app → _app}/dev/docs/templates/usage.rst.jinja2 +14 -4
  13. snowflake/cli/{app → _app}/main_typer.py +2 -2
  14. snowflake/cli/{app → _app}/printing.py +2 -2
  15. snowflake/cli/{app → _app}/snow_connector.py +24 -17
  16. snowflake/cli/{app → _app}/telemetry.py +4 -5
  17. snowflake/cli/{plugins → _plugins}/connection/commands.py +25 -7
  18. snowflake/cli/_plugins/connection/plugin_spec.py +30 -0
  19. snowflake/cli/{plugins → _plugins}/connection/util.py +16 -0
  20. snowflake/cli/{plugins → _plugins}/cortex/commands.py +54 -49
  21. snowflake/cli/{plugins → _plugins}/cortex/constants.py +1 -1
  22. snowflake/cli/{plugins → _plugins}/cortex/manager.py +5 -5
  23. snowflake/cli/{plugins → _plugins}/cortex/plugin_spec.py +1 -1
  24. snowflake/cli/{plugins → _plugins}/git/commands.py +32 -20
  25. snowflake/cli/{plugins → _plugins}/git/manager.py +20 -11
  26. snowflake/cli/{plugins → _plugins}/git/plugin_spec.py +1 -1
  27. snowflake/cli/{plugins → _plugins}/init/commands.py +10 -6
  28. snowflake/cli/{plugins → _plugins}/init/plugin_spec.py +1 -1
  29. snowflake/cli/{plugins → _plugins}/nativeapp/artifacts.py +14 -0
  30. snowflake/cli/_plugins/nativeapp/bundle_context.py +31 -0
  31. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/artifact_processor.py +3 -3
  32. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/compiler.py +32 -18
  33. snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +249 -0
  34. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/setup/setup_driver.py.source +5 -2
  35. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/extension_function_utils.py +4 -4
  36. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/python_processor.py +23 -29
  37. snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +93 -0
  38. snowflake/cli/{plugins → _plugins}/nativeapp/commands.py +171 -42
  39. snowflake/cli/{plugins → _plugins}/nativeapp/common_flags.py +1 -1
  40. snowflake/cli/{plugins → _plugins}/nativeapp/exceptions.py +3 -3
  41. snowflake/cli/{plugins → _plugins}/nativeapp/init.py +1 -1
  42. snowflake/cli/_plugins/nativeapp/manager.py +572 -0
  43. snowflake/cli/{plugins/connection → _plugins/nativeapp}/plugin_spec.py +1 -1
  44. snowflake/cli/{plugins → _plugins}/nativeapp/project_model.py +35 -19
  45. snowflake/cli/{plugins → _plugins}/nativeapp/run_processor.py +25 -23
  46. snowflake/cli/{plugins → _plugins}/nativeapp/teardown_processor.py +24 -110
  47. snowflake/cli/{plugins → _plugins}/nativeapp/v2_conversions/v2_to_v1_decorator.py +47 -28
  48. snowflake/cli/{plugins → _plugins}/nativeapp/version/commands.py +15 -12
  49. snowflake/cli/{plugins → _plugins}/nativeapp/version/version_processor.py +22 -20
  50. snowflake/cli/{plugins → _plugins}/notebook/commands.py +8 -6
  51. snowflake/cli/{plugins → _plugins}/notebook/manager.py +14 -14
  52. snowflake/cli/{plugins → _plugins}/notebook/plugin_spec.py +1 -1
  53. snowflake/cli/{plugins → _plugins}/notebook/types.py +0 -1
  54. snowflake/cli/{plugins → _plugins}/object/command_aliases.py +6 -5
  55. snowflake/cli/{plugins → _plugins}/object/commands.py +16 -10
  56. snowflake/cli/{plugins → _plugins}/object/manager.py +7 -6
  57. snowflake/cli/{plugins → _plugins}/object/plugin_spec.py +1 -1
  58. snowflake/cli/_plugins/snowpark/commands.py +450 -0
  59. snowflake/cli/_plugins/snowpark/common.py +268 -0
  60. snowflake/cli/{plugins → _plugins}/snowpark/models.py +0 -7
  61. snowflake/cli/{plugins → _plugins}/snowpark/package/anaconda_packages.py +2 -36
  62. snowflake/cli/{plugins → _plugins}/snowpark/package/commands.py +13 -74
  63. snowflake/cli/{plugins → _plugins}/snowpark/package/manager.py +4 -3
  64. snowflake/cli/{plugins → _plugins}/snowpark/package_utils.py +5 -5
  65. snowflake/cli/{plugins/nativeapp → _plugins/snowpark}/plugin_spec.py +1 -1
  66. snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +109 -0
  67. snowflake/cli/{plugins → _plugins}/snowpark/snowpark_shared.py +0 -36
  68. snowflake/cli/{plugins → _plugins}/snowpark/zipper.py +16 -8
  69. snowflake/cli/{plugins → _plugins}/spcs/__init__.py +5 -7
  70. snowflake/cli/{plugins → _plugins}/spcs/compute_pool/commands.py +29 -28
  71. snowflake/cli/{plugins → _plugins}/spcs/compute_pool/manager.py +3 -3
  72. snowflake/cli/{plugins → _plugins}/spcs/image_registry/commands.py +3 -3
  73. snowflake/cli/{plugins → _plugins}/spcs/image_repository/commands.py +25 -19
  74. snowflake/cli/{plugins → _plugins}/spcs/image_repository/manager.py +1 -1
  75. snowflake/cli/{plugins → _plugins}/spcs/plugin_spec.py +1 -1
  76. snowflake/cli/{plugins → _plugins}/spcs/services/commands.py +66 -32
  77. snowflake/cli/{plugins → _plugins}/spcs/services/manager.py +43 -5
  78. snowflake/cli/{plugins → _plugins}/sql/commands.py +20 -17
  79. snowflake/cli/{plugins → _plugins}/sql/manager.py +1 -1
  80. snowflake/cli/{plugins → _plugins}/sql/plugin_spec.py +1 -1
  81. snowflake/cli/{plugins → _plugins}/stage/commands.py +20 -17
  82. snowflake/cli/{plugins → _plugins}/stage/diff.py +1 -47
  83. snowflake/cli/{plugins → _plugins}/stage/manager.py +54 -21
  84. snowflake/cli/{plugins → _plugins}/stage/plugin_spec.py +1 -1
  85. snowflake/cli/_plugins/stage/utils.py +54 -0
  86. snowflake/cli/{plugins → _plugins}/streamlit/commands.py +59 -62
  87. snowflake/cli/{plugins → _plugins}/streamlit/manager.py +51 -70
  88. snowflake/cli/_plugins/streamlit/plugin_spec.py +30 -0
  89. snowflake/cli/_plugins/workspace/action_context.py +17 -0
  90. snowflake/cli/_plugins/workspace/commands.py +194 -0
  91. snowflake/cli/_plugins/workspace/manager.py +73 -0
  92. snowflake/cli/{plugins → _plugins}/workspace/plugin_spec.py +1 -1
  93. snowflake/cli/api/cli_global_context.py +40 -13
  94. snowflake/cli/api/commands/common.py +25 -0
  95. snowflake/cli/api/commands/decorators.py +5 -4
  96. snowflake/cli/api/commands/experimental_behaviour.py +2 -3
  97. snowflake/cli/api/commands/flags.py +97 -179
  98. snowflake/cli/api/commands/overrideable_parameter.py +143 -0
  99. snowflake/cli/api/commands/snow_typer.py +14 -6
  100. snowflake/cli/api/commands/typer_pre_execute.py +3 -3
  101. snowflake/cli/api/commands/utils.py +18 -0
  102. snowflake/cli/api/config.py +18 -5
  103. snowflake/cli/api/console/abc.py +5 -2
  104. snowflake/cli/api/constants.py +11 -0
  105. snowflake/cli/api/entities/application_entity.py +12 -0
  106. snowflake/cli/api/entities/application_package_entity.py +553 -0
  107. snowflake/cli/api/entities/common.py +51 -0
  108. snowflake/cli/api/entities/snowpark_entity.py +29 -0
  109. snowflake/cli/api/entities/streamlit_entity.py +12 -0
  110. snowflake/cli/api/entities/utils.py +357 -0
  111. snowflake/cli/api/exceptions.py +31 -5
  112. snowflake/cli/api/feature_flags.py +0 -1
  113. snowflake/cli/api/identifiers.py +41 -9
  114. snowflake/cli/api/project/definition.py +37 -6
  115. snowflake/cli/api/project/definition_conversion.py +194 -0
  116. snowflake/cli/api/project/definition_manager.py +12 -1
  117. snowflake/cli/api/project/project_verification.py +3 -3
  118. snowflake/cli/api/project/schemas/entities/{application_entity.py → application_entity_model.py} +21 -9
  119. snowflake/cli/api/project/schemas/entities/{application_package_entity.py → application_package_entity_model.py} +43 -15
  120. snowflake/cli/api/project/schemas/entities/common.py +80 -6
  121. snowflake/cli/api/project/schemas/entities/entities.py +38 -8
  122. snowflake/cli/api/project/schemas/entities/snowpark_entity.py +176 -0
  123. snowflake/cli/api/project/schemas/entities/streamlit_entity_model.py +73 -0
  124. snowflake/cli/api/project/schemas/identifier_model.py +10 -1
  125. snowflake/cli/api/project/schemas/native_app/application.py +8 -9
  126. snowflake/cli/api/project/schemas/native_app/package.py +7 -1
  127. snowflake/cli/api/project/schemas/project_definition.py +98 -27
  128. snowflake/cli/api/project/schemas/updatable_model.py +11 -3
  129. snowflake/cli/api/project/util.py +23 -6
  130. snowflake/cli/api/rendering/jinja.py +14 -8
  131. snowflake/cli/api/rendering/project_definition_templates.py +1 -1
  132. snowflake/cli/api/rendering/sql_templates.py +43 -11
  133. snowflake/cli/api/secure_path.py +16 -18
  134. snowflake/cli/api/secure_utils.py +90 -1
  135. snowflake/cli/api/sql_execution.py +48 -19
  136. snowflake/cli/api/utils/definition_rendering.py +18 -8
  137. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0rc1.dist-info}/METADATA +13 -13
  138. snowflake_cli_labs-3.0.0rc1.dist-info/RECORD +236 -0
  139. snowflake_cli_labs-3.0.0rc1.dist-info/entry_points.txt +2 -0
  140. snowflake/cli/api/commands/project_initialisation.py +0 -65
  141. snowflake/cli/app/build_and_push.sh +0 -8
  142. snowflake/cli/plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -172
  143. snowflake/cli/plugins/nativeapp/manager.py +0 -823
  144. snowflake/cli/plugins/object_stage_deprecated/__init__.py +0 -15
  145. snowflake/cli/plugins/object_stage_deprecated/commands.py +0 -122
  146. snowflake/cli/plugins/object_stage_deprecated/plugin_spec.py +0 -32
  147. snowflake/cli/plugins/snowpark/commands.py +0 -548
  148. snowflake/cli/plugins/snowpark/common.py +0 -307
  149. snowflake/cli/plugins/snowpark/manager.py +0 -109
  150. snowflake/cli/plugins/snowpark/plugin_spec.py +0 -30
  151. snowflake/cli/plugins/snowpark/snowpark_package_paths.py +0 -65
  152. snowflake/cli/plugins/spcs/jobs/commands.py +0 -78
  153. snowflake/cli/plugins/spcs/jobs/manager.py +0 -53
  154. snowflake/cli/plugins/streamlit/plugin_spec.py +0 -30
  155. snowflake/cli/plugins/workspace/commands.py +0 -35
  156. snowflake/cli/templates/default_snowpark/.gitignore +0 -4
  157. snowflake/cli/templates/default_snowpark/app/__init__.py +0 -0
  158. snowflake/cli/templates/default_snowpark/app/common.py +0 -2
  159. snowflake/cli/templates/default_snowpark/app/functions.py +0 -15
  160. snowflake/cli/templates/default_snowpark/app/procedures.py +0 -22
  161. snowflake/cli/templates/default_snowpark/requirements.txt +0 -1
  162. snowflake/cli/templates/default_snowpark/snowflake.yml +0 -23
  163. snowflake/cli/templates/default_streamlit/.gitignore +0 -4
  164. snowflake/cli/templates/default_streamlit/common/hello.py +0 -2
  165. snowflake/cli/templates/default_streamlit/environment.yml +0 -6
  166. snowflake/cli/templates/default_streamlit/pages/my_page.py +0 -3
  167. snowflake/cli/templates/default_streamlit/snowflake.yml +0 -10
  168. snowflake/cli/templates/default_streamlit/streamlit_app.py +0 -4
  169. snowflake_cli_labs-2.8.0rc1.dist-info/RECORD +0 -240
  170. snowflake_cli_labs-2.8.0rc1.dist-info/entry_points.txt +0 -2
  171. /snowflake/cli/{app → _app}/__init__.py +0 -0
  172. /snowflake/cli/{app → _app}/api_impl/__init__.py +0 -0
  173. /snowflake/cli/{app → _app}/api_impl/plugin/__init__.py +0 -0
  174. /snowflake/cli/{app → _app}/api_impl/plugin/plugin_config_provider_impl.py +0 -0
  175. /snowflake/cli/{app → _app}/commands_registration/__init__.py +0 -0
  176. /snowflake/cli/{app → _app}/commands_registration/threadsafe.py +0 -0
  177. /snowflake/cli/{app → _app}/constants.py +0 -0
  178. /snowflake/cli/{app → _app}/dev/__init__.py +0 -0
  179. /snowflake/cli/{app → _app}/dev/commands_structure.py +0 -0
  180. /snowflake/cli/{app → _app}/dev/docs/__init__.py +0 -0
  181. /snowflake/cli/{app → _app}/dev/docs/project_definition_generate_json_schema.py +0 -0
  182. /snowflake/cli/{app → _app}/dev/docs/template_utils.py +0 -0
  183. /snowflake/cli/{app → _app}/dev/docs/templates/definition_description.rst.jinja2 +0 -0
  184. /snowflake/cli/{app → _app}/dev/docs/templates/overview.rst.jinja2 +0 -0
  185. /snowflake/cli/{app → _app}/dev/pycharm_remote_debug.py +0 -0
  186. /snowflake/cli/{app → _app}/loggers.py +0 -0
  187. /snowflake/cli/{plugins → _plugins}/__init__.py +0 -0
  188. /snowflake/cli/{plugins → _plugins}/connection/__init__.py +0 -0
  189. /snowflake/cli/{plugins → _plugins}/cortex/__init__.py +0 -0
  190. /snowflake/cli/{plugins → _plugins}/cortex/types.py +0 -0
  191. /snowflake/cli/{plugins → _plugins}/git/__init__.py +0 -0
  192. /snowflake/cli/{plugins → _plugins}/init/__init__.py +0 -0
  193. /snowflake/cli/{plugins → _plugins}/nativeapp/__init__.py +0 -0
  194. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/__init__.py +0 -0
  195. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/sandbox.py +0 -0
  196. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -0
  197. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/models.py +0 -0
  198. /snowflake/cli/{plugins → _plugins}/nativeapp/constants.py +0 -0
  199. /snowflake/cli/{plugins → _plugins}/nativeapp/feature_flags.py +0 -0
  200. /snowflake/cli/{plugins → _plugins}/nativeapp/policy.py +0 -0
  201. /snowflake/cli/{plugins → _plugins}/nativeapp/utils.py +0 -0
  202. /snowflake/cli/{plugins → _plugins}/nativeapp/version/__init__.py +0 -0
  203. /snowflake/cli/{plugins → _plugins}/notebook/__init__.py +0 -0
  204. /snowflake/cli/{plugins → _plugins}/notebook/exceptions.py +0 -0
  205. /snowflake/cli/{plugins → _plugins}/object/__init__.py +0 -0
  206. /snowflake/cli/{plugins → _plugins}/object/common.py +0 -0
  207. /snowflake/cli/{plugins → _plugins}/snowpark/__init__.py +0 -0
  208. /snowflake/cli/{plugins → _plugins}/snowpark/package/__init__.py +0 -0
  209. /snowflake/cli/{plugins → _plugins}/snowpark/package/utils.py +0 -0
  210. /snowflake/cli/{plugins → _plugins}/spcs/common.py +0 -0
  211. /snowflake/cli/{plugins → _plugins}/spcs/compute_pool/__init__.py +0 -0
  212. /snowflake/cli/{plugins → _plugins}/spcs/image_registry/__init__.py +0 -0
  213. /snowflake/cli/{plugins → _plugins}/spcs/image_registry/manager.py +0 -0
  214. /snowflake/cli/{plugins → _plugins}/spcs/image_repository/__init__.py +0 -0
  215. /snowflake/cli/{plugins/spcs/jobs → _plugins/spcs/services}/__init__.py +0 -0
  216. /snowflake/cli/{plugins/spcs/services → _plugins/sql}/__init__.py +0 -0
  217. /snowflake/cli/{plugins → _plugins}/sql/snowsql_templating.py +0 -0
  218. /snowflake/cli/{plugins/sql → _plugins/stage}/__init__.py +0 -0
  219. /snowflake/cli/{plugins → _plugins}/stage/md5.py +0 -0
  220. /snowflake/cli/{plugins/stage → _plugins/streamlit}/__init__.py +0 -0
  221. /snowflake/cli/{plugins/streamlit → _plugins/workspace}/__init__.py +0 -0
  222. /snowflake/cli/{plugins/workspace → api/project/schemas/entities}/__init__.py +0 -0
  223. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0rc1.dist-info}/WHEEL +0 -0
  224. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0rc1.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,194 @@
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 pathlib import Path
19
+ from textwrap import dedent
20
+ from typing import List, Optional
21
+
22
+ import typer
23
+ import yaml
24
+ from snowflake.cli._plugins.nativeapp.artifacts import BundleMap
25
+ from snowflake.cli._plugins.nativeapp.common_flags import (
26
+ ForceOption,
27
+ ValidateOption,
28
+ )
29
+ from snowflake.cli._plugins.workspace.manager import WorkspaceManager
30
+ from snowflake.cli.api.cli_global_context import get_cli_context
31
+ from snowflake.cli.api.commands.decorators import with_project_definition
32
+ from snowflake.cli.api.commands.snow_typer import SnowTyper
33
+ from snowflake.cli.api.entities.common import EntityActions
34
+ from snowflake.cli.api.exceptions import IncompatibleParametersError
35
+ from snowflake.cli.api.output.types import MessageResult
36
+ from snowflake.cli.api.project.definition_conversion import (
37
+ convert_project_definition_to_v2,
38
+ )
39
+ from snowflake.cli.api.project.definition_manager import DefinitionManager
40
+ from snowflake.cli.api.secure_path import SecurePath
41
+
42
+ ws = SnowTyper(
43
+ name="ws",
44
+ help="Deploy and interact with snowflake.yml-based entities.",
45
+ )
46
+ log = logging.getLogger(__name__)
47
+
48
+
49
+ @ws.command()
50
+ def migrate(
51
+ accept_templates: bool = typer.Option(
52
+ False, "-t", "--accept-templates", help="Allows the migration of templates."
53
+ ),
54
+ **options,
55
+ ):
56
+ """Migrates the Snowpark and Streamlit project definition files from V1 to V2."""
57
+ pd = DefinitionManager().unrendered_project_definition
58
+
59
+ if pd.meets_version_requirement("2"):
60
+ return MessageResult("Project definition is already at version 2.")
61
+
62
+ pd_v2 = convert_project_definition_to_v2(pd, accept_templates)
63
+
64
+ SecurePath("snowflake.yml").rename("snowflake_V1.yml")
65
+ with open("snowflake.yml", "w") as file:
66
+ yaml.dump(
67
+ pd_v2.model_dump(
68
+ exclude_unset=True, exclude_none=True, mode="json", by_alias=True
69
+ ),
70
+ file,
71
+ )
72
+ return MessageResult("Project definition migrated to version 2.")
73
+
74
+
75
+ @ws.command(requires_connection=True, hidden=True)
76
+ @with_project_definition()
77
+ def validate(
78
+ **options,
79
+ ):
80
+ """Validates the project definition file."""
81
+ # If we get to this point, @with_project_definition() has already validated the PDF schema
82
+ return MessageResult("Project definition is valid.")
83
+
84
+
85
+ @ws.command(requires_connection=True, hidden=True)
86
+ @with_project_definition()
87
+ def bundle(
88
+ entity_id: str = typer.Option(
89
+ help=f"""The ID of the entity you want to bundle.""",
90
+ ),
91
+ **options,
92
+ ):
93
+ """
94
+ Prepares a local folder with the configured artifacts of the specified entity.
95
+ """
96
+
97
+ cli_context = get_cli_context()
98
+ ws = WorkspaceManager(
99
+ project_definition=cli_context.project_definition,
100
+ project_root=cli_context.project_root,
101
+ )
102
+
103
+ bundle_map: BundleMap = ws.perform_action(entity_id, EntityActions.BUNDLE)
104
+ return MessageResult(f"Bundle generated at {bundle_map.deploy_root()}")
105
+
106
+
107
+ @ws.command(requires_connection=True)
108
+ @with_project_definition()
109
+ def deploy(
110
+ entity_id: str = typer.Option(
111
+ help=f"""The ID of the entity you want to deploy.""",
112
+ ),
113
+ # TODO The following options should be generated automatically, depending on the specified entity type
114
+ prune: Optional[bool] = typer.Option(
115
+ default=None,
116
+ help=f"""Whether to delete specified files from the stage if they don't exist locally. If set, the command deletes files that exist in the stage, but not in the local filesystem. This option cannot be used when paths are specified.""",
117
+ ),
118
+ recursive: Optional[bool] = typer.Option(
119
+ None,
120
+ "--recursive/--no-recursive",
121
+ "-r",
122
+ help=f"""Whether to traverse and deploy files from subdirectories. If set, the command deploys all files and subdirectories; otherwise, only files in the current directory are deployed.""",
123
+ ),
124
+ paths: Optional[List[Path]] = typer.Argument(
125
+ default=None,
126
+ show_default=False,
127
+ help=dedent(
128
+ f"""
129
+ Paths, relative to the the project root, of files or directories you want to upload to a stage. If a file is
130
+ specified, it must match one of the artifacts src pattern entries in snowflake.yml. If a directory is
131
+ specified, it will be searched for subfolders or files to deploy based on artifacts src pattern entries. If
132
+ unspecified, the command syncs all local changes to the stage."""
133
+ ).strip(),
134
+ ),
135
+ validate: bool = ValidateOption,
136
+ **options,
137
+ ):
138
+ """
139
+ Deploys the specified entity.
140
+ """
141
+ if prune is None and recursive is None and not paths:
142
+ prune = True
143
+ recursive = True
144
+ else:
145
+ if prune is None:
146
+ prune = False
147
+ if recursive is None:
148
+ recursive = False
149
+
150
+ if paths and prune:
151
+ raise IncompatibleParametersError(["paths", "--prune"])
152
+
153
+ cli_context = get_cli_context()
154
+ ws = WorkspaceManager(
155
+ project_definition=cli_context.project_definition,
156
+ project_root=cli_context.project_root,
157
+ )
158
+
159
+ ws.perform_action(
160
+ entity_id,
161
+ EntityActions.DEPLOY,
162
+ prune=prune,
163
+ recursive=recursive,
164
+ paths=paths,
165
+ validate=validate,
166
+ )
167
+ return MessageResult("Deployed successfully.")
168
+
169
+
170
+ @ws.command(requires_connection=True)
171
+ @with_project_definition()
172
+ def drop(
173
+ entity_id: str = typer.Option(
174
+ help=f"""The ID of the entity you want to drop.""",
175
+ ),
176
+ # TODO The following options should be generated automatically, depending on the specified entity type
177
+ force: Optional[bool] = ForceOption,
178
+ **options,
179
+ ):
180
+ """
181
+ Drops the specified entity.
182
+ """
183
+
184
+ cli_context = get_cli_context()
185
+ ws = WorkspaceManager(
186
+ project_definition=cli_context.project_definition,
187
+ project_root=cli_context.project_root,
188
+ )
189
+
190
+ ws.perform_action(
191
+ entity_id,
192
+ EntityActions.DROP,
193
+ force_drop=force,
194
+ )
@@ -0,0 +1,73 @@
1
+ from pathlib import Path
2
+ from typing import Dict
3
+
4
+ from snowflake.cli._plugins.workspace.action_context import ActionContext
5
+ from snowflake.cli.api.cli_global_context import get_cli_context
6
+ from snowflake.cli.api.console import cli_console as cc
7
+ from snowflake.cli.api.entities.common import EntityActions, get_sql_executor
8
+ from snowflake.cli.api.exceptions import InvalidProjectDefinitionVersionError
9
+ from snowflake.cli.api.project.definition import default_role
10
+ from snowflake.cli.api.project.schemas.entities.entities import (
11
+ Entity,
12
+ v2_entity_model_to_entity_map,
13
+ )
14
+ from snowflake.cli.api.project.schemas.project_definition import (
15
+ DefinitionV20,
16
+ ProjectDefinition,
17
+ )
18
+ from snowflake.cli.api.project.util import to_identifier
19
+
20
+
21
+ class WorkspaceManager:
22
+ """
23
+ Instantiates entity instances from entity models, providing higher-order functionality on entity compositions.
24
+ """
25
+
26
+ def __init__(self, project_definition: ProjectDefinition, project_root: Path):
27
+ if not project_definition.meets_version_requirement("2"):
28
+ raise InvalidProjectDefinitionVersionError(
29
+ "2.x", project_definition.definition_version
30
+ )
31
+ self._entities_cache: Dict[str, Entity] = {}
32
+ self._project_definition: DefinitionV20 = project_definition
33
+ self._project_root = project_root
34
+ self._default_role = default_role()
35
+ if self._default_role is None:
36
+ self._default_role = get_sql_executor().current_role()
37
+ self.default_warehouse = None
38
+ cli_context = get_cli_context()
39
+ if cli_context.connection.warehouse:
40
+ self.default_warehouse = to_identifier(cli_context.connection.warehouse)
41
+
42
+ def get_entity(self, entity_id: str):
43
+ """
44
+ Returns an entity instance with the given ID. If exists, reuses the previously returned instance, or instantiates a new one otherwise.
45
+ """
46
+ if entity_id in self._entities_cache:
47
+ return self._entities_cache[entity_id]
48
+ entity_model = self._project_definition.entities.get(entity_id, None)
49
+ if entity_model is None:
50
+ raise ValueError(f"No such entity ID: {entity_id}")
51
+ entity_model_cls = entity_model.__class__
52
+ entity_cls = v2_entity_model_to_entity_map[entity_model_cls]
53
+ self._entities_cache[entity_id] = entity_cls(entity_model)
54
+ return self._entities_cache[entity_id]
55
+
56
+ def perform_action(self, entity_id: str, action: EntityActions, *args, **kwargs):
57
+ """
58
+ Instantiates an entity of the given ID and calls the given action on it.
59
+ """
60
+ entity = self.get_entity(entity_id)
61
+ if entity.supports(action):
62
+ action_ctx = ActionContext(
63
+ console=cc,
64
+ project_root=self.project_root(),
65
+ default_role=self._default_role,
66
+ default_warehouse=self.default_warehouse,
67
+ )
68
+ return entity.perform(action, action_ctx, *args, **kwargs)
69
+ else:
70
+ raise ValueError(f'This entity type does not support "{action.value}"')
71
+
72
+ def project_root(self) -> Path:
73
+ return self._project_root
@@ -12,13 +12,13 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ from snowflake.cli._plugins.workspace import commands
15
16
  from snowflake.cli.api.plugins.command import (
16
17
  SNOWCLI_ROOT_COMMAND_PATH,
17
18
  CommandSpec,
18
19
  CommandType,
19
20
  plugin_hook_impl,
20
21
  )
21
- from snowflake.cli.plugins.workspace import commands
22
22
 
23
23
 
24
24
  @plugin_hook_impl
@@ -15,13 +15,17 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import re
18
+ import warnings
18
19
  from pathlib import Path
19
- from typing import Callable, Optional
20
+ from typing import TYPE_CHECKING, Callable, Optional
20
21
 
21
22
  from snowflake.cli.api.exceptions import InvalidSchemaError
22
23
  from snowflake.cli.api.output.formats import OutputFormat
23
- from snowflake.cli.api.project.schemas.project_definition import ProjectDefinition
24
24
  from snowflake.connector import SnowflakeConnection
25
+ from snowflake.connector.compat import IS_WINDOWS
26
+
27
+ if TYPE_CHECKING:
28
+ from snowflake.cli.api.project.schemas.project_definition import ProjectDefinition
25
29
 
26
30
  schema_pattern = re.compile(r".+\..+")
27
31
 
@@ -38,7 +42,7 @@ class _ConnectionContext:
38
42
  self._user: Optional[str] = None
39
43
  self._password: Optional[str] = None
40
44
  self._authenticator: Optional[str] = None
41
- self._private_key_path: Optional[str] = None
45
+ self._private_key_file: Optional[str] = None
42
46
  self._warehouse: Optional[str] = None
43
47
  self._mfa_passcode: Optional[str] = None
44
48
  self._enable_diag: Optional[bool] = False
@@ -121,11 +125,11 @@ class _ConnectionContext:
121
125
  self._authenticator = value
122
126
 
123
127
  @property
124
- def private_key_path(self) -> Optional[str]:
125
- return self._private_key_path
128
+ def private_key_file(self) -> Optional[str]:
129
+ return self._private_key_file
126
130
 
127
- def set_private_key_path(self, value: Optional[str]):
128
- self._private_key_path = value
131
+ def set_private_key_file(self, value: Optional[str]):
132
+ self._private_key_file = value
129
133
 
130
134
  @property
131
135
  def warehouse(self) -> Optional[str]:
@@ -202,7 +206,7 @@ class _ConnectionContext:
202
206
  "user": self.user,
203
207
  "password": self.password,
204
208
  "authenticator": self.authenticator,
205
- "private_key_path": self.private_key_path,
209
+ "private_key_file": self.private_key_file,
206
210
  "database": self.database,
207
211
  "schema": self.schema,
208
212
  "role": self.role,
@@ -213,7 +217,16 @@ class _ConnectionContext:
213
217
  }
214
218
 
215
219
  def _build_connection(self):
216
- from snowflake.cli.app.snow_connector import connect_to_snowflake
220
+ from snowflake.cli._app.snow_connector import connect_to_snowflake
221
+
222
+ # Ignore warnings about bad owner or permissions on Windows
223
+ # Telemetry omit our warning filter from config.py
224
+ if IS_WINDOWS:
225
+ warnings.filterwarnings(
226
+ action="ignore",
227
+ message="Bad owner or permissions.*",
228
+ module="snowflake.connector.config_manager",
229
+ )
217
230
 
218
231
  return connect_to_snowflake(
219
232
  temporary_connection=self.temporary_connection,
@@ -367,8 +380,8 @@ class _CliGlobalContextAccess:
367
380
  return self._manager.project_definition
368
381
 
369
382
  @property
370
- def project_root(self):
371
- return self._manager.project_root
383
+ def project_root(self) -> Path:
384
+ return Path(self._manager.project_root)
372
385
 
373
386
  @property
374
387
  def template_context(self) -> dict:
@@ -386,5 +399,19 @@ class _CliGlobalContextAccess:
386
399
  return self._manager.output_format == OutputFormat.JSON
387
400
 
388
401
 
389
- cli_context_manager: _CliGlobalContextManager = _CliGlobalContextManager()
390
- cli_context: _CliGlobalContextAccess = _CliGlobalContextAccess(cli_context_manager)
402
+ _CLI_CONTEXT_MANAGER: _CliGlobalContextManager | None = None
403
+ _CLI_CONTEXT: _CliGlobalContextAccess | None = None
404
+
405
+
406
+ def get_cli_context_manager() -> _CliGlobalContextManager:
407
+ global _CLI_CONTEXT_MANAGER
408
+ if _CLI_CONTEXT_MANAGER is None:
409
+ _CLI_CONTEXT_MANAGER = _CliGlobalContextManager()
410
+ return _CLI_CONTEXT_MANAGER
411
+
412
+
413
+ def get_cli_context() -> _CliGlobalContextAccess:
414
+ global _CLI_CONTEXT
415
+ if _CLI_CONTEXT is None:
416
+ _CLI_CONTEXT = _CliGlobalContextAccess(get_cli_context_manager())
417
+ return _CLI_CONTEXT
@@ -0,0 +1,25 @@
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
@@ -19,7 +19,7 @@ from functools import wraps
19
19
  from inspect import Signature
20
20
  from typing import Callable, Dict, List, Optional, get_type_hints
21
21
 
22
- from snowflake.cli.api.cli_global_context import cli_context
22
+ from snowflake.cli.api.cli_global_context import get_cli_context
23
23
  from snowflake.cli.api.commands.flags import (
24
24
  AccountOption,
25
25
  AuthenticatorOption,
@@ -125,8 +125,9 @@ def with_experimental_behaviour(
125
125
 
126
126
 
127
127
  def _execute_before_command_using_global_options(**options):
128
- from snowflake.cli.app.loggers import create_loggers
128
+ from snowflake.cli._app.loggers import create_loggers
129
129
 
130
+ cli_context = get_cli_context()
130
131
  create_loggers(cli_context.verbose, cli_context.enable_tracebacks)
131
132
 
132
133
 
@@ -234,7 +235,7 @@ GLOBAL_CONNECTION_OPTIONS = [
234
235
  default=AuthenticatorOption,
235
236
  ),
236
237
  inspect.Parameter(
237
- "private_key_path",
238
+ "private_key_file",
238
239
  inspect.Parameter.KEYWORD_ONLY,
239
240
  annotation=Optional[str],
240
241
  default=PrivateKeyPathOption,
@@ -342,7 +343,7 @@ GLOBAL_OPTIONS = [
342
343
 
343
344
 
344
345
  def with_output(func):
345
- from snowflake.cli.app.printing import print_result
346
+ from snowflake.cli._app.printing import print_result
346
347
 
347
348
  @wraps(func)
348
349
  def wrapper(*args, **kwargs):
@@ -11,9 +11,8 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
-
15
- from snowflake.cli.api.cli_global_context import cli_context
14
+ from snowflake.cli.api.cli_global_context import get_cli_context
16
15
 
17
16
 
18
17
  def experimental_behaviour_enabled() -> bool:
19
- return cli_context.experimental
18
+ return get_cli_context().experimental