snowflake-cli-labs 3.0.0rc1__py3-none-any.whl → 3.0.0rc3__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 (92) hide show
  1. snowflake/cli/__about__.py +1 -1
  2. snowflake/cli/_app/cli_app.py +10 -1
  3. snowflake/cli/_app/commands_registration/builtin_plugins.py +2 -0
  4. snowflake/cli/_app/secret.py +9 -0
  5. snowflake/cli/_app/snow_connector.py +110 -51
  6. snowflake/cli/_app/telemetry.py +8 -4
  7. snowflake/cli/_app/version_check.py +74 -0
  8. snowflake/cli/_plugins/git/commands.py +55 -14
  9. snowflake/cli/_plugins/git/manager.py +53 -7
  10. snowflake/cli/_plugins/helpers/commands.py +57 -0
  11. snowflake/cli/{api/commands/typer_pre_execute.py → _plugins/helpers/plugin_spec.py} +14 -10
  12. snowflake/cli/_plugins/nativeapp/application_entity.py +651 -0
  13. snowflake/cli/{api/project/schemas/entities → _plugins/nativeapp}/application_entity_model.py +2 -2
  14. snowflake/cli/_plugins/nativeapp/application_package_entity.py +1107 -0
  15. snowflake/cli/{api/project/schemas/entities → _plugins/nativeapp}/application_package_entity_model.py +3 -3
  16. snowflake/cli/_plugins/nativeapp/artifacts.py +10 -9
  17. snowflake/cli/_plugins/nativeapp/bundle_context.py +1 -1
  18. snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py +1 -1
  19. snowflake/cli/_plugins/nativeapp/codegen/compiler.py +1 -1
  20. snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +1 -1
  21. snowflake/cli/_plugins/nativeapp/codegen/snowpark/extension_function_utils.py +1 -1
  22. snowflake/cli/_plugins/nativeapp/codegen/snowpark/models.py +1 -1
  23. snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py +3 -6
  24. snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +50 -32
  25. snowflake/cli/_plugins/nativeapp/commands.py +84 -16
  26. snowflake/cli/_plugins/nativeapp/exceptions.py +0 -9
  27. snowflake/cli/_plugins/nativeapp/manager.py +56 -92
  28. snowflake/cli/_plugins/nativeapp/policy.py +3 -0
  29. snowflake/cli/_plugins/nativeapp/project_model.py +2 -2
  30. snowflake/cli/_plugins/nativeapp/run_processor.py +65 -272
  31. snowflake/cli/_plugins/nativeapp/same_account_install_method.py +70 -0
  32. snowflake/cli/_plugins/nativeapp/teardown_processor.py +11 -154
  33. snowflake/cli/_plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +150 -40
  34. snowflake/cli/_plugins/nativeapp/version/commands.py +6 -24
  35. snowflake/cli/_plugins/nativeapp/version/version_processor.py +35 -235
  36. snowflake/cli/_plugins/snowpark/commands.py +5 -5
  37. snowflake/cli/_plugins/snowpark/common.py +4 -4
  38. snowflake/cli/_plugins/snowpark/models.py +2 -1
  39. snowflake/cli/{api/entities → _plugins/snowpark}/snowpark_entity.py +2 -2
  40. snowflake/cli/{api/project/schemas/entities/snowpark_entity.py → _plugins/snowpark/snowpark_entity_model.py} +3 -6
  41. snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +1 -1
  42. snowflake/cli/_plugins/stage/manager.py +9 -4
  43. snowflake/cli/_plugins/streamlit/commands.py +4 -4
  44. snowflake/cli/_plugins/streamlit/manager.py +17 -4
  45. snowflake/cli/{api/entities → _plugins/streamlit}/streamlit_entity.py +2 -2
  46. snowflake/cli/{api/project/schemas/entities → _plugins/streamlit}/streamlit_entity_model.py +5 -12
  47. snowflake/cli/_plugins/workspace/action_context.py +2 -1
  48. snowflake/cli/_plugins/workspace/commands.py +127 -48
  49. snowflake/cli/_plugins/workspace/manager.py +1 -0
  50. snowflake/cli/_plugins/workspace/plugin_spec.py +1 -1
  51. snowflake/cli/api/cli_global_context.py +136 -313
  52. snowflake/cli/api/commands/flags.py +76 -91
  53. snowflake/cli/api/commands/snow_typer.py +7 -5
  54. snowflake/cli/api/config.py +1 -1
  55. snowflake/cli/api/connections.py +214 -0
  56. snowflake/cli/api/console/abc.py +4 -2
  57. snowflake/cli/api/entities/common.py +4 -0
  58. snowflake/cli/api/entities/utils.py +41 -31
  59. snowflake/cli/api/errno.py +1 -0
  60. snowflake/cli/api/identifiers.py +7 -3
  61. snowflake/cli/api/project/definition.py +11 -0
  62. snowflake/cli/api/project/definition_conversion.py +175 -16
  63. snowflake/cli/api/project/schemas/entities/common.py +15 -14
  64. snowflake/cli/api/project/schemas/entities/entities.py +13 -10
  65. snowflake/cli/api/project/schemas/project_definition.py +107 -45
  66. snowflake/cli/api/project/schemas/v1/__init__.py +0 -0
  67. snowflake/cli/api/project/schemas/{identifier_model.py → v1/identifier_model.py} +0 -7
  68. snowflake/cli/api/project/schemas/v1/native_app/__init__.py +0 -0
  69. snowflake/cli/api/project/schemas/{native_app → v1/native_app}/native_app.py +4 -4
  70. snowflake/cli/api/project/schemas/v1/snowpark/__init__.py +0 -0
  71. snowflake/cli/api/project/schemas/{snowpark → v1/snowpark}/callable.py +2 -2
  72. snowflake/cli/api/project/schemas/{snowpark → v1/snowpark}/snowpark.py +2 -2
  73. snowflake/cli/api/project/schemas/v1/streamlit/__init__.py +0 -0
  74. snowflake/cli/api/project/schemas/{streamlit → v1/streamlit}/streamlit.py +2 -1
  75. snowflake/cli/api/rendering/project_definition_templates.py +4 -0
  76. snowflake/cli/api/rendering/sql_templates.py +7 -0
  77. snowflake/cli/api/sql_execution.py +6 -15
  78. snowflake/cli/api/utils/definition_rendering.py +3 -1
  79. {snowflake_cli_labs-3.0.0rc1.dist-info → snowflake_cli_labs-3.0.0rc3.dist-info}/METADATA +9 -9
  80. {snowflake_cli_labs-3.0.0rc1.dist-info → snowflake_cli_labs-3.0.0rc3.dist-info}/RECORD +88 -81
  81. snowflake/cli/api/entities/application_entity.py +0 -12
  82. snowflake/cli/api/entities/application_package_entity.py +0 -553
  83. snowflake/cli/api/project/schemas/snowpark/__init__.py +0 -13
  84. snowflake/cli/api/project/schemas/streamlit/__init__.py +0 -13
  85. /snowflake/cli/{api/project/schemas/native_app → _plugins/helpers}/__init__.py +0 -0
  86. /snowflake/cli/api/project/schemas/{native_app → v1/native_app}/application.py +0 -0
  87. /snowflake/cli/api/project/schemas/{native_app → v1/native_app}/package.py +0 -0
  88. /snowflake/cli/api/project/schemas/{native_app → v1/native_app}/path_mapping.py +0 -0
  89. /snowflake/cli/api/project/schemas/{snowpark → v1/snowpark}/argument.py +0 -0
  90. {snowflake_cli_labs-3.0.0rc1.dist-info → snowflake_cli_labs-3.0.0rc3.dist-info}/WHEEL +0 -0
  91. {snowflake_cli_labs-3.0.0rc1.dist-info → snowflake_cli_labs-3.0.0rc3.dist-info}/entry_points.txt +0 -0
  92. {snowflake_cli_labs-3.0.0rc1.dist-info → snowflake_cli_labs-3.0.0rc3.dist-info}/licenses/LICENSE +0 -0
@@ -1,553 +0,0 @@
1
- import json
2
- from contextlib import contextmanager
3
- from pathlib import Path
4
- from textwrap import dedent
5
- from typing import Callable, List, Optional
6
-
7
- import typer
8
- from click import ClickException
9
- from snowflake.cli._plugins.nativeapp.artifacts import build_bundle
10
- from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext
11
- from snowflake.cli._plugins.nativeapp.codegen.compiler import NativeAppCompiler
12
- from snowflake.cli._plugins.nativeapp.constants import (
13
- ALLOWED_SPECIAL_COMMENTS,
14
- COMMENT_COL,
15
- EXTERNAL_DISTRIBUTION,
16
- INTERNAL_DISTRIBUTION,
17
- NAME_COL,
18
- OWNER_COL,
19
- SPECIAL_COMMENT,
20
- )
21
- from snowflake.cli._plugins.nativeapp.exceptions import (
22
- ApplicationPackageAlreadyExistsError,
23
- ApplicationPackageDoesNotExistError,
24
- CouldNotDropApplicationPackageWithVersions,
25
- SetupScriptFailedValidation,
26
- )
27
- from snowflake.cli._plugins.nativeapp.utils import (
28
- needs_confirmation,
29
- )
30
- from snowflake.cli._plugins.stage.manager import StageManager
31
- from snowflake.cli._plugins.workspace.action_context import ActionContext
32
- from snowflake.cli.api.console.abc import AbstractConsole
33
- from snowflake.cli.api.entities.common import EntityBase, get_sql_executor
34
- from snowflake.cli.api.entities.utils import (
35
- drop_generic_object,
36
- ensure_correct_owner,
37
- execute_post_deploy_hooks,
38
- generic_sql_error_handler,
39
- render_script_templates,
40
- sync_deploy_root_with_stage,
41
- validation_item_to_str,
42
- )
43
- from snowflake.cli.api.errno import (
44
- DOES_NOT_EXIST_OR_NOT_AUTHORIZED,
45
- )
46
- from snowflake.cli.api.exceptions import SnowflakeSQLExecutionError
47
- from snowflake.cli.api.project.schemas.entities.application_package_entity_model import (
48
- ApplicationPackageEntityModel,
49
- )
50
- from snowflake.cli.api.project.schemas.entities.common import PostDeployHook
51
- from snowflake.cli.api.project.util import extract_schema
52
- from snowflake.cli.api.rendering.jinja import (
53
- get_basic_jinja_env,
54
- )
55
- from snowflake.connector import ProgrammingError
56
- from snowflake.connector.cursor import DictCursor
57
-
58
-
59
- class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
60
- """
61
- A Native App application package.
62
- """
63
-
64
- def action_bundle(self, ctx: ActionContext):
65
- model = self._entity_model
66
- bundle_map = build_bundle(
67
- ctx.project_root, Path(model.deploy_root), model.artifacts
68
- )
69
- bundle_context = BundleContext(
70
- package_name=model.identifier,
71
- artifacts=model.artifacts,
72
- project_root=ctx.project_root,
73
- bundle_root=Path(model.bundle_root),
74
- deploy_root=Path(model.deploy_root),
75
- generated_root=Path(model.generated_root),
76
- )
77
- compiler = NativeAppCompiler(bundle_context)
78
- compiler.compile_artifacts()
79
- return bundle_map
80
-
81
- def action_deploy(
82
- self,
83
- ctx: ActionContext,
84
- prune: bool,
85
- recursive: bool,
86
- paths: List[Path],
87
- validate: bool,
88
- ):
89
- model = self._entity_model
90
- package_name = model.fqn.identifier
91
- if model.meta and model.meta.role:
92
- package_role = model.meta.role
93
- else:
94
- package_role = ctx.default_role
95
-
96
- # 1. Create a bundle
97
- bundle_map = self.action_bundle(ctx)
98
-
99
- # 2. Create an empty application package, if none exists
100
- self.create_app_package(
101
- console=ctx.console,
102
- package_name=package_name,
103
- package_role=package_role,
104
- package_distribution=model.distribution,
105
- )
106
-
107
- with get_sql_executor().use_role(package_role):
108
- # 3. Upload files from deploy root local folder to the above stage
109
- stage_fqn = f"{package_name}.{model.stage}"
110
- stage_schema = extract_schema(stage_fqn)
111
- sync_deploy_root_with_stage(
112
- console=ctx.console,
113
- deploy_root=Path(model.deploy_root),
114
- package_name=package_name,
115
- stage_schema=stage_schema,
116
- bundle_map=bundle_map,
117
- role=package_role,
118
- prune=prune,
119
- recursive=recursive,
120
- stage_fqn=stage_fqn,
121
- local_paths_to_sync=paths,
122
- print_diff=True,
123
- )
124
-
125
- if model.meta and model.meta.post_deploy:
126
- self.execute_post_deploy_hooks(
127
- console=ctx.console,
128
- project_root=ctx.project_root,
129
- post_deploy_hooks=model.meta.post_deploy,
130
- package_name=package_name,
131
- package_warehouse=model.meta.warehouse or ctx.default_warehouse,
132
- )
133
-
134
- if validate:
135
- self.validate_setup_script(
136
- console=ctx.console,
137
- package_name=package_name,
138
- package_role=package_role,
139
- stage_fqn=stage_fqn,
140
- use_scratch_stage=False,
141
- scratch_stage_fqn="",
142
- deploy_to_scratch_stage_fn=lambda *args: None,
143
- )
144
-
145
- def action_drop(
146
- self,
147
- ctx: ActionContext,
148
- force_drop: bool,
149
- ):
150
- model = self._entity_model
151
- package_name = model.fqn.identifier
152
- if model.meta and model.meta.role:
153
- package_role = model.meta.role
154
- else:
155
- package_role = ctx.default_role
156
-
157
- self.drop(
158
- console=ctx.console,
159
- package_name=package_name,
160
- package_role=package_role,
161
- force_drop=force_drop,
162
- )
163
-
164
- @staticmethod
165
- def get_existing_app_pkg_info(
166
- package_name: str,
167
- package_role: str,
168
- ) -> Optional[dict]:
169
- """
170
- Check for an existing application package by the same name as in project definition, in account.
171
- It executes a 'show application packages like' query and returns the result as single row, if one exists.
172
- """
173
- sql_executor = get_sql_executor()
174
- with sql_executor.use_role(package_role):
175
- return sql_executor.show_specific_object(
176
- "application packages", package_name, name_col=NAME_COL
177
- )
178
-
179
- @staticmethod
180
- def get_app_pkg_distribution_in_snowflake(
181
- package_name: str,
182
- package_role: str,
183
- ) -> str:
184
- """
185
- Returns the 'distribution' attribute of a 'describe application package' SQL query, in lowercase.
186
- """
187
- sql_executor = get_sql_executor()
188
- with sql_executor.use_role(package_role):
189
- try:
190
- desc_cursor = sql_executor.execute_query(
191
- f"describe application package {package_name}"
192
- )
193
- except ProgrammingError as err:
194
- generic_sql_error_handler(err)
195
-
196
- if desc_cursor.rowcount is None or desc_cursor.rowcount == 0:
197
- raise SnowflakeSQLExecutionError()
198
- else:
199
- for row in desc_cursor:
200
- if row[0].lower() == "distribution":
201
- return row[1].lower()
202
- raise ProgrammingError(
203
- msg=dedent(
204
- f"""\
205
- Could not find the 'distribution' attribute for application package {package_name} in the output of SQL query:
206
- 'describe application package {package_name}'
207
- """
208
- )
209
- )
210
-
211
- @classmethod
212
- def verify_project_distribution(
213
- cls,
214
- console: AbstractConsole,
215
- package_name: str,
216
- package_role: str,
217
- package_distribution: str,
218
- expected_distribution: Optional[str] = None,
219
- ) -> bool:
220
- """
221
- Returns true if the 'distribution' attribute of an existing application package in snowflake
222
- is the same as the the attribute specified in project definition file.
223
- """
224
- actual_distribution = (
225
- expected_distribution
226
- if expected_distribution
227
- else cls.get_app_pkg_distribution_in_snowflake(
228
- package_name=package_name,
229
- package_role=package_role,
230
- )
231
- )
232
- project_def_distribution = package_distribution.lower()
233
- if actual_distribution != project_def_distribution:
234
- console.warning(
235
- dedent(
236
- f"""\
237
- Application package {package_name} in your Snowflake account has distribution property {actual_distribution},
238
- which does not match the value specified in project definition file: {project_def_distribution}.
239
- """
240
- )
241
- )
242
- return False
243
- return True
244
-
245
- @staticmethod
246
- @contextmanager
247
- def use_package_warehouse(
248
- package_warehouse: Optional[str],
249
- ):
250
- if package_warehouse:
251
- with get_sql_executor().use_warehouse(package_warehouse):
252
- yield
253
- else:
254
- raise ClickException(
255
- dedent(
256
- f"""\
257
- Application package warehouse cannot be empty.
258
- Please provide a value for it in your connection information or your project definition file.
259
- """
260
- )
261
- )
262
-
263
- @classmethod
264
- def apply_package_scripts(
265
- cls,
266
- console: AbstractConsole,
267
- package_scripts: List[str],
268
- package_warehouse: Optional[str],
269
- project_root: Path,
270
- package_role: str,
271
- package_name: str,
272
- ) -> None:
273
- """
274
- Assuming the application package exists and we are using the correct role,
275
- applies all package scripts in-order to the application package.
276
- """
277
-
278
- if package_scripts:
279
- console.warning(
280
- "WARNING: native_app.package.scripts is deprecated. Please migrate to using native_app.package.post_deploy."
281
- )
282
-
283
- queued_queries = render_script_templates(
284
- project_root,
285
- dict(package_name=package_name),
286
- package_scripts,
287
- get_basic_jinja_env(),
288
- )
289
-
290
- # once we're sure all the templates expanded correctly, execute all of them
291
- with cls.use_package_warehouse(
292
- package_warehouse=package_warehouse,
293
- ):
294
- try:
295
- for i, queries in enumerate(queued_queries):
296
- console.step(f"Applying package script: {package_scripts[i]}")
297
- get_sql_executor().execute_queries(queries)
298
- except ProgrammingError as err:
299
- generic_sql_error_handler(
300
- err, role=package_role, warehouse=package_warehouse
301
- )
302
-
303
- @classmethod
304
- def create_app_package(
305
- cls,
306
- console: AbstractConsole,
307
- package_name: str,
308
- package_role: str,
309
- package_distribution: str,
310
- ) -> None:
311
- """
312
- Creates the application package with our up-to-date stage if none exists.
313
- """
314
-
315
- # 1. Check for existing existing application package
316
- show_obj_row = cls.get_existing_app_pkg_info(
317
- package_name=package_name,
318
- package_role=package_role,
319
- )
320
-
321
- if show_obj_row:
322
- # 1. Check for the right owner role
323
- ensure_correct_owner(
324
- row=show_obj_row, role=package_role, obj_name=package_name
325
- )
326
-
327
- # 2. Check distribution of the existing application package
328
- actual_distribution = cls.get_app_pkg_distribution_in_snowflake(
329
- package_name=package_name,
330
- package_role=package_role,
331
- )
332
- if not cls.verify_project_distribution(
333
- console=console,
334
- package_name=package_name,
335
- package_role=package_role,
336
- package_distribution=package_distribution,
337
- expected_distribution=actual_distribution,
338
- ):
339
- console.warning(
340
- f"Continuing to execute `snow app run` on application package {package_name} with distribution '{actual_distribution}'."
341
- )
342
-
343
- # 3. If actual_distribution is external, skip comment check
344
- if actual_distribution == INTERNAL_DISTRIBUTION:
345
- row_comment = show_obj_row[COMMENT_COL]
346
-
347
- if row_comment not in ALLOWED_SPECIAL_COMMENTS:
348
- raise ApplicationPackageAlreadyExistsError(package_name)
349
-
350
- return
351
-
352
- # If no application package pre-exists, create an application package, with the specified distribution in the project definition file.
353
- sql_executor = get_sql_executor()
354
- with sql_executor.use_role(package_role):
355
- console.step(f"Creating new application package {package_name} in account.")
356
- sql_executor.execute_query(
357
- dedent(
358
- f"""\
359
- create application package {package_name}
360
- comment = {SPECIAL_COMMENT}
361
- distribution = {package_distribution}
362
- """
363
- )
364
- )
365
-
366
- @classmethod
367
- def execute_post_deploy_hooks(
368
- cls,
369
- console: AbstractConsole,
370
- project_root: Path,
371
- post_deploy_hooks: Optional[List[PostDeployHook]],
372
- package_name: str,
373
- package_warehouse: Optional[str],
374
- ):
375
- with cls.use_package_warehouse(package_warehouse):
376
- execute_post_deploy_hooks(
377
- console=console,
378
- project_root=project_root,
379
- post_deploy_hooks=post_deploy_hooks,
380
- deployed_object_type="application package",
381
- database_name=package_name,
382
- )
383
-
384
- @classmethod
385
- def validate_setup_script(
386
- cls,
387
- console: AbstractConsole,
388
- package_name: str,
389
- package_role: str,
390
- stage_fqn: str,
391
- use_scratch_stage: bool,
392
- scratch_stage_fqn: str,
393
- deploy_to_scratch_stage_fn: Callable,
394
- ):
395
- """Validates Native App setup script SQL."""
396
- with console.phase(f"Validating Snowflake Native App setup script."):
397
- validation_result = cls.get_validation_result(
398
- console=console,
399
- package_name=package_name,
400
- package_role=package_role,
401
- stage_fqn=stage_fqn,
402
- use_scratch_stage=use_scratch_stage,
403
- scratch_stage_fqn=scratch_stage_fqn,
404
- deploy_to_scratch_stage_fn=deploy_to_scratch_stage_fn,
405
- )
406
-
407
- # First print warnings, regardless of the outcome of validation
408
- for warning in validation_result.get("warnings", []):
409
- console.warning(validation_item_to_str(warning))
410
-
411
- # Then print errors
412
- for error in validation_result.get("errors", []):
413
- # Print them as warnings for now since we're going to be
414
- # revamping CLI output soon
415
- console.warning(validation_item_to_str(error))
416
-
417
- # Then raise an exception if validation failed
418
- if validation_result["status"] == "FAIL":
419
- raise SetupScriptFailedValidation()
420
-
421
- @staticmethod
422
- def get_validation_result(
423
- console: AbstractConsole,
424
- package_name: str,
425
- package_role: str,
426
- stage_fqn: str,
427
- use_scratch_stage: bool,
428
- scratch_stage_fqn: str,
429
- deploy_to_scratch_stage_fn: Callable,
430
- ):
431
- """Call system$validate_native_app_setup() to validate deployed Native App setup script."""
432
- if use_scratch_stage:
433
- stage_fqn = scratch_stage_fqn
434
- deploy_to_scratch_stage_fn()
435
- prefixed_stage_fqn = StageManager.get_standard_stage_prefix(stage_fqn)
436
- sql_executor = get_sql_executor()
437
- try:
438
- cursor = sql_executor.execute_query(
439
- f"call system$validate_native_app_setup('{prefixed_stage_fqn}')"
440
- )
441
- except ProgrammingError as err:
442
- if err.errno == DOES_NOT_EXIST_OR_NOT_AUTHORIZED:
443
- raise ApplicationPackageDoesNotExistError(package_name)
444
- generic_sql_error_handler(err)
445
- else:
446
- if not cursor.rowcount:
447
- raise SnowflakeSQLExecutionError()
448
- return json.loads(cursor.fetchone()[0])
449
- finally:
450
- if use_scratch_stage:
451
- console.step(f"Dropping stage {scratch_stage_fqn}.")
452
- with sql_executor.use_role(package_role):
453
- sql_executor.execute_query(
454
- f"drop stage if exists {scratch_stage_fqn}"
455
- )
456
-
457
- @classmethod
458
- def drop(
459
- cls,
460
- console: AbstractConsole,
461
- package_name: str,
462
- package_role: str,
463
- force_drop: bool,
464
- ):
465
- sql_executor = get_sql_executor()
466
- needs_confirm = True
467
-
468
- # 1. If existing application package is not found, exit gracefully
469
- show_obj_row = cls.get_existing_app_pkg_info(
470
- package_name=package_name,
471
- package_role=package_role,
472
- )
473
- if show_obj_row is None:
474
- console.warning(
475
- f"Role {package_role} does not own any application package with the name {package_name}, or the application package does not exist."
476
- )
477
- return
478
-
479
- # 2. Check for the right owner
480
- ensure_correct_owner(row=show_obj_row, role=package_role, obj_name=package_name)
481
-
482
- with sql_executor.use_role(package_role):
483
- # 3. Check for versions in the application package
484
- show_versions_query = f"show versions in application package {package_name}"
485
- show_versions_cursor = sql_executor.execute_query(
486
- show_versions_query, cursor_class=DictCursor
487
- )
488
- if show_versions_cursor.rowcount is None:
489
- raise SnowflakeSQLExecutionError(show_versions_query)
490
-
491
- if show_versions_cursor.rowcount > 0:
492
- # allow dropping a package with versions when --force is set
493
- if not force_drop:
494
- raise CouldNotDropApplicationPackageWithVersions(
495
- "Drop versions first, or use --force to override."
496
- )
497
-
498
- # 4. Check distribution of the existing application package
499
- actual_distribution = cls.get_app_pkg_distribution_in_snowflake(
500
- package_name=package_name,
501
- package_role=package_role,
502
- )
503
- if not cls.verify_project_distribution(
504
- console=console,
505
- package_name=package_name,
506
- package_role=package_role,
507
- package_distribution=actual_distribution,
508
- ):
509
- console.warning(
510
- f"Dropping application package {package_name} with distribution '{actual_distribution}'."
511
- )
512
-
513
- # 5. If distribution is internal, check if created by the Snowflake CLI
514
- row_comment = show_obj_row[COMMENT_COL]
515
- if actual_distribution == INTERNAL_DISTRIBUTION:
516
- if row_comment in ALLOWED_SPECIAL_COMMENTS:
517
- needs_confirm = False
518
- else:
519
- if needs_confirmation(needs_confirm, force_drop):
520
- console.warning(
521
- f"Application package {package_name} was not created by Snowflake CLI."
522
- )
523
- else:
524
- if needs_confirmation(needs_confirm, force_drop):
525
- console.warning(
526
- f"Application package {package_name} in your Snowflake account has distribution property '{EXTERNAL_DISTRIBUTION}' and could be associated with one or more of your listings on Snowflake Marketplace."
527
- )
528
-
529
- if needs_confirmation(needs_confirm, force_drop):
530
- should_drop_object = typer.confirm(
531
- dedent(
532
- f"""\
533
- Application package details:
534
- Name: {package_name}
535
- Created on: {show_obj_row["created_on"]}
536
- Distribution: {actual_distribution}
537
- Owner: {show_obj_row[OWNER_COL]}
538
- Comment: {show_obj_row[COMMENT_COL]}
539
- Are you sure you want to drop it?
540
- """
541
- )
542
- )
543
- if not should_drop_object:
544
- console.message(f"Did not drop application package {package_name}.")
545
- return # The user desires to keep the application package, therefore exit gracefully
546
-
547
- # All validations have passed, drop object
548
- drop_generic_object(
549
- console=console,
550
- object_type="application package",
551
- object_name=package_name,
552
- role=package_role,
553
- )
@@ -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,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.