snowflake-cli 3.0.1__py3-none-any.whl → 3.1.0__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.
- snowflake/cli/__about__.py +1 -1
- snowflake/cli/_app/cli_app.py +3 -0
- snowflake/cli/_app/dev/docs/templates/overview.rst.jinja2 +1 -1
- snowflake/cli/_app/dev/docs/templates/usage.rst.jinja2 +2 -2
- snowflake/cli/_app/telemetry.py +69 -4
- snowflake/cli/_plugins/connection/commands.py +40 -2
- snowflake/cli/_plugins/git/commands.py +6 -3
- snowflake/cli/_plugins/git/manager.py +5 -0
- snowflake/cli/_plugins/nativeapp/artifacts.py +13 -3
- snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py +1 -1
- snowflake/cli/_plugins/nativeapp/codegen/compiler.py +7 -0
- snowflake/cli/_plugins/nativeapp/codegen/sandbox.py +10 -10
- snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +2 -2
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/extension_function_utils.py +1 -1
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py +8 -8
- snowflake/cli/_plugins/nativeapp/commands.py +135 -186
- snowflake/cli/_plugins/nativeapp/entities/application.py +176 -24
- snowflake/cli/_plugins/nativeapp/entities/application_package.py +112 -136
- snowflake/cli/_plugins/nativeapp/exceptions.py +12 -0
- snowflake/cli/_plugins/nativeapp/manager.py +3 -26
- snowflake/cli/_plugins/nativeapp/v2_conversions/{v2_to_v1_decorator.py → compat.py} +131 -72
- snowflake/cli/_plugins/nativeapp/version/commands.py +30 -29
- snowflake/cli/_plugins/nativeapp/version/version_processor.py +1 -43
- snowflake/cli/_plugins/snowpark/commands.py +0 -2
- snowflake/cli/_plugins/snowpark/common.py +60 -18
- snowflake/cli/_plugins/snowpark/package/anaconda_packages.py +2 -2
- snowflake/cli/_plugins/snowpark/package/commands.py +0 -2
- snowflake/cli/_plugins/snowpark/package_utils.py +27 -38
- snowflake/cli/_plugins/snowpark/snowpark_entity_model.py +5 -2
- snowflake/cli/_plugins/spcs/image_repository/commands.py +4 -37
- snowflake/cli/_plugins/spcs/image_repository/manager.py +4 -1
- snowflake/cli/_plugins/spcs/services/commands.py +36 -4
- snowflake/cli/_plugins/spcs/services/manager.py +36 -4
- snowflake/cli/_plugins/stage/commands.py +8 -3
- snowflake/cli/_plugins/stage/diff.py +16 -16
- snowflake/cli/_plugins/stage/manager.py +164 -73
- snowflake/cli/_plugins/stage/md5.py +1 -1
- snowflake/cli/_plugins/workspace/commands.py +21 -1
- snowflake/cli/_plugins/workspace/context.py +38 -0
- snowflake/cli/_plugins/workspace/manager.py +23 -13
- snowflake/cli/api/cli_global_context.py +3 -3
- snowflake/cli/api/commands/flags.py +23 -7
- snowflake/cli/api/config.py +7 -4
- snowflake/cli/api/connections.py +12 -1
- snowflake/cli/api/entities/common.py +4 -2
- snowflake/cli/api/entities/utils.py +17 -37
- snowflake/cli/api/exceptions.py +32 -0
- snowflake/cli/api/identifiers.py +8 -0
- snowflake/cli/api/project/definition_conversion.py +139 -40
- snowflake/cli/api/project/schemas/entities/common.py +11 -0
- snowflake/cli/api/project/schemas/project_definition.py +30 -25
- snowflake/cli/api/sql_execution.py +5 -7
- snowflake/cli/api/stage_path.py +241 -0
- snowflake/cli/api/utils/definition_rendering.py +3 -5
- {snowflake_cli-3.0.1.dist-info → snowflake_cli-3.1.0.dist-info}/METADATA +11 -11
- {snowflake_cli-3.0.1.dist-info → snowflake_cli-3.1.0.dist-info}/RECORD +59 -59
- snowflake/cli/_plugins/nativeapp/teardown_processor.py +0 -70
- snowflake/cli/_plugins/workspace/action_context.py +0 -18
- {snowflake_cli-3.0.1.dist-info → snowflake_cli-3.1.0.dist-info}/WHEEL +0 -0
- {snowflake_cli-3.0.1.dist-info → snowflake_cli-3.1.0.dist-info}/entry_points.txt +0 -0
- {snowflake_cli-3.0.1.dist-info → snowflake_cli-3.1.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -31,6 +31,7 @@ from snowflake.cli._plugins.nativeapp.exceptions import (
|
|
|
31
31
|
ApplicationPackageAlreadyExistsError,
|
|
32
32
|
ApplicationPackageDoesNotExistError,
|
|
33
33
|
CouldNotDropApplicationPackageWithVersions,
|
|
34
|
+
ObjectPropertyNotFoundError,
|
|
34
35
|
SetupScriptFailedValidation,
|
|
35
36
|
)
|
|
36
37
|
from snowflake.cli._plugins.nativeapp.policy import (
|
|
@@ -42,7 +43,7 @@ from snowflake.cli._plugins.nativeapp.policy import (
|
|
|
42
43
|
from snowflake.cli._plugins.nativeapp.utils import needs_confirmation
|
|
43
44
|
from snowflake.cli._plugins.stage.diff import DiffResult
|
|
44
45
|
from snowflake.cli._plugins.stage.manager import StageManager
|
|
45
|
-
from snowflake.cli._plugins.workspace.
|
|
46
|
+
from snowflake.cli._plugins.workspace.context import ActionContext
|
|
46
47
|
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
47
48
|
from snowflake.cli.api.console.abc import AbstractConsole
|
|
48
49
|
from snowflake.cli.api.entities.common import EntityBase, get_sql_executor
|
|
@@ -50,7 +51,6 @@ from snowflake.cli.api.entities.utils import (
|
|
|
50
51
|
drop_generic_object,
|
|
51
52
|
execute_post_deploy_hooks,
|
|
52
53
|
generic_sql_error_handler,
|
|
53
|
-
render_script_templates,
|
|
54
54
|
sync_deploy_root_with_stage,
|
|
55
55
|
validation_item_to_str,
|
|
56
56
|
)
|
|
@@ -75,7 +75,6 @@ from snowflake.cli.api.project.util import (
|
|
|
75
75
|
to_identifier,
|
|
76
76
|
unquote_identifier,
|
|
77
77
|
)
|
|
78
|
-
from snowflake.cli.api.rendering.jinja import get_basic_jinja_env
|
|
79
78
|
from snowflake.cli.api.utils.cursor import find_all_rows
|
|
80
79
|
from snowflake.connector import DictCursor, ProgrammingError
|
|
81
80
|
from snowflake.connector.cursor import SnowflakeCursor
|
|
@@ -150,20 +149,23 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
150
149
|
A Native App application package.
|
|
151
150
|
"""
|
|
152
151
|
|
|
153
|
-
def action_bundle(self,
|
|
152
|
+
def action_bundle(self, action_ctx: ActionContext, *args, **kwargs):
|
|
154
153
|
model = self._entity_model
|
|
154
|
+
workspace_ctx = self._workspace_ctx
|
|
155
155
|
return self.bundle(
|
|
156
|
-
project_root=
|
|
157
|
-
deploy_root=
|
|
158
|
-
bundle_root=
|
|
159
|
-
generated_root=
|
|
156
|
+
project_root=workspace_ctx.project_root,
|
|
157
|
+
deploy_root=workspace_ctx.project_root / model.deploy_root,
|
|
158
|
+
bundle_root=workspace_ctx.project_root / model.bundle_root,
|
|
159
|
+
generated_root=(
|
|
160
|
+
workspace_ctx.project_root / model.deploy_root / model.generated_root
|
|
161
|
+
),
|
|
160
162
|
package_name=model.identifier,
|
|
161
163
|
artifacts=model.artifacts,
|
|
162
164
|
)
|
|
163
165
|
|
|
164
166
|
def action_deploy(
|
|
165
167
|
self,
|
|
166
|
-
|
|
168
|
+
action_ctx: ActionContext,
|
|
167
169
|
prune: bool,
|
|
168
170
|
recursive: bool,
|
|
169
171
|
paths: List[Path],
|
|
@@ -175,6 +177,7 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
175
177
|
**kwargs,
|
|
176
178
|
):
|
|
177
179
|
model = self._entity_model
|
|
180
|
+
workspace_ctx = self._workspace_ctx
|
|
178
181
|
package_name = model.fqn.identifier
|
|
179
182
|
|
|
180
183
|
if force:
|
|
@@ -185,15 +188,17 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
185
188
|
policy = DenyAlwaysPolicy()
|
|
186
189
|
|
|
187
190
|
return self.deploy(
|
|
188
|
-
console=
|
|
189
|
-
project_root=
|
|
190
|
-
deploy_root=
|
|
191
|
-
bundle_root=
|
|
192
|
-
generated_root=
|
|
191
|
+
console=workspace_ctx.console,
|
|
192
|
+
project_root=workspace_ctx.project_root,
|
|
193
|
+
deploy_root=workspace_ctx.project_root / model.deploy_root,
|
|
194
|
+
bundle_root=workspace_ctx.project_root / model.bundle_root,
|
|
195
|
+
generated_root=(
|
|
196
|
+
workspace_ctx.project_root / model.deploy_root / model.generated_root
|
|
197
|
+
),
|
|
193
198
|
artifacts=model.artifacts,
|
|
194
199
|
bundle_map=None,
|
|
195
200
|
package_name=package_name,
|
|
196
|
-
package_role=(model.meta and model.meta.role) or
|
|
201
|
+
package_role=(model.meta and model.meta.role) or workspace_ctx.default_role,
|
|
197
202
|
package_distribution=model.distribution,
|
|
198
203
|
prune=prune,
|
|
199
204
|
recursive=recursive,
|
|
@@ -202,32 +207,39 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
202
207
|
validate=validate,
|
|
203
208
|
stage_fqn=stage_fqn or f"{package_name}.{model.stage}",
|
|
204
209
|
package_warehouse=(
|
|
205
|
-
(model.meta and model.meta.warehouse) or
|
|
210
|
+
(model.meta and model.meta.warehouse) or workspace_ctx.default_warehouse
|
|
206
211
|
),
|
|
207
212
|
post_deploy_hooks=model.meta and model.meta.post_deploy,
|
|
208
|
-
package_scripts=[], # Package scripts are not supported in PDFv2
|
|
209
213
|
policy=policy,
|
|
210
214
|
)
|
|
211
215
|
|
|
212
|
-
def action_drop(self,
|
|
216
|
+
def action_drop(self, action_ctx: ActionContext, force_drop: bool, *args, **kwargs):
|
|
213
217
|
model = self._entity_model
|
|
218
|
+
workspace_ctx = self._workspace_ctx
|
|
214
219
|
package_name = model.fqn.identifier
|
|
215
220
|
if model.meta and model.meta.role:
|
|
216
221
|
package_role = model.meta.role
|
|
217
222
|
else:
|
|
218
|
-
package_role =
|
|
223
|
+
package_role = workspace_ctx.default_role
|
|
219
224
|
|
|
220
225
|
self.drop(
|
|
221
|
-
console=
|
|
226
|
+
console=workspace_ctx.console,
|
|
222
227
|
package_name=package_name,
|
|
223
228
|
package_role=package_role,
|
|
224
229
|
force_drop=force_drop,
|
|
225
230
|
)
|
|
226
231
|
|
|
227
232
|
def action_validate(
|
|
228
|
-
self,
|
|
233
|
+
self,
|
|
234
|
+
action_ctx: ActionContext,
|
|
235
|
+
interactive: bool,
|
|
236
|
+
force: bool,
|
|
237
|
+
use_scratch_stage: bool = True,
|
|
238
|
+
*args,
|
|
239
|
+
**kwargs,
|
|
229
240
|
):
|
|
230
241
|
model = self._entity_model
|
|
242
|
+
workspace_ctx = self._workspace_ctx
|
|
231
243
|
package_name = model.fqn.identifier
|
|
232
244
|
if force:
|
|
233
245
|
policy = AllowAlwaysPolicy()
|
|
@@ -237,42 +249,43 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
237
249
|
policy = DenyAlwaysPolicy()
|
|
238
250
|
|
|
239
251
|
self.validate_setup_script(
|
|
240
|
-
console=
|
|
241
|
-
project_root=
|
|
242
|
-
deploy_root=
|
|
243
|
-
bundle_root=
|
|
244
|
-
generated_root=
|
|
252
|
+
console=workspace_ctx.console,
|
|
253
|
+
project_root=workspace_ctx.project_root,
|
|
254
|
+
deploy_root=workspace_ctx.project_root / model.deploy_root,
|
|
255
|
+
bundle_root=workspace_ctx.project_root / model.bundle_root,
|
|
256
|
+
generated_root=(
|
|
257
|
+
workspace_ctx.project_root / model.deploy_root / model.generated_root
|
|
258
|
+
),
|
|
245
259
|
artifacts=model.artifacts,
|
|
246
260
|
package_name=package_name,
|
|
247
|
-
package_role=(model.meta and model.meta.role) or
|
|
261
|
+
package_role=(model.meta and model.meta.role) or workspace_ctx.default_role,
|
|
248
262
|
package_distribution=model.distribution,
|
|
249
263
|
prune=True,
|
|
250
264
|
recursive=True,
|
|
251
265
|
paths=[],
|
|
252
266
|
stage_fqn=f"{package_name}.{model.stage}",
|
|
253
267
|
package_warehouse=(
|
|
254
|
-
(model.meta and model.meta.warehouse) or
|
|
268
|
+
(model.meta and model.meta.warehouse) or workspace_ctx.default_warehouse
|
|
255
269
|
),
|
|
256
|
-
post_deploy_hooks=model.meta and model.meta.post_deploy,
|
|
257
|
-
package_scripts=[], # Package scripts are not supported in PDFv2
|
|
258
270
|
policy=policy,
|
|
259
|
-
use_scratch_stage=
|
|
271
|
+
use_scratch_stage=use_scratch_stage,
|
|
260
272
|
scratch_stage_fqn=f"{package_name}.{model.scratch_stage}",
|
|
261
273
|
)
|
|
262
|
-
|
|
274
|
+
workspace_ctx.console.message("Setup script is valid")
|
|
263
275
|
|
|
264
276
|
def action_version_list(
|
|
265
|
-
self,
|
|
277
|
+
self, action_ctx: ActionContext, *args, **kwargs
|
|
266
278
|
) -> SnowflakeCursor:
|
|
267
279
|
model = self._entity_model
|
|
280
|
+
workspace_ctx = self._workspace_ctx
|
|
268
281
|
return self.version_list(
|
|
269
282
|
package_name=model.fqn.identifier,
|
|
270
|
-
package_role=(model.meta and model.meta.role) or
|
|
283
|
+
package_role=(model.meta and model.meta.role) or workspace_ctx.default_role,
|
|
271
284
|
)
|
|
272
285
|
|
|
273
286
|
def action_version_create(
|
|
274
287
|
self,
|
|
275
|
-
|
|
288
|
+
action_ctx: ActionContext,
|
|
276
289
|
version: Optional[str],
|
|
277
290
|
patch: Optional[int],
|
|
278
291
|
skip_git_check: bool,
|
|
@@ -282,16 +295,19 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
282
295
|
**kwargs,
|
|
283
296
|
):
|
|
284
297
|
model = self._entity_model
|
|
298
|
+
workspace_ctx = self._workspace_ctx
|
|
285
299
|
package_name = model.fqn.identifier
|
|
286
300
|
return self.version_create(
|
|
287
|
-
console=
|
|
288
|
-
project_root=
|
|
289
|
-
deploy_root=
|
|
290
|
-
bundle_root=
|
|
291
|
-
generated_root=
|
|
301
|
+
console=workspace_ctx.console,
|
|
302
|
+
project_root=workspace_ctx.project_root,
|
|
303
|
+
deploy_root=workspace_ctx.project_root / model.deploy_root,
|
|
304
|
+
bundle_root=workspace_ctx.project_root / model.bundle_root,
|
|
305
|
+
generated_root=(
|
|
306
|
+
workspace_ctx.project_root / model.deploy_root / model.generated_root
|
|
307
|
+
),
|
|
292
308
|
artifacts=model.artifacts,
|
|
293
309
|
package_name=package_name,
|
|
294
|
-
package_role=(model.meta and model.meta.role) or
|
|
310
|
+
package_role=(model.meta and model.meta.role) or workspace_ctx.default_role,
|
|
295
311
|
package_distribution=model.distribution,
|
|
296
312
|
prune=True,
|
|
297
313
|
recursive=True,
|
|
@@ -300,10 +316,9 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
300
316
|
validate=True,
|
|
301
317
|
stage_fqn=f"{package_name}.{model.stage}",
|
|
302
318
|
package_warehouse=(
|
|
303
|
-
(model.meta and model.meta.warehouse) or
|
|
319
|
+
(model.meta and model.meta.warehouse) or workspace_ctx.default_warehouse
|
|
304
320
|
),
|
|
305
321
|
post_deploy_hooks=model.meta and model.meta.post_deploy,
|
|
306
|
-
package_scripts=[], # Package scripts are not supported in PDFv2
|
|
307
322
|
version=version,
|
|
308
323
|
patch=patch,
|
|
309
324
|
skip_git_check=skip_git_check,
|
|
@@ -313,7 +328,7 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
313
328
|
|
|
314
329
|
def action_version_drop(
|
|
315
330
|
self,
|
|
316
|
-
|
|
331
|
+
action_ctx: ActionContext,
|
|
317
332
|
version: Optional[str],
|
|
318
333
|
interactive: bool,
|
|
319
334
|
force: bool,
|
|
@@ -321,16 +336,19 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
321
336
|
**kwargs,
|
|
322
337
|
):
|
|
323
338
|
model = self._entity_model
|
|
339
|
+
workspace_ctx = self._workspace_ctx
|
|
324
340
|
package_name = model.fqn.identifier
|
|
325
341
|
return self.version_drop(
|
|
326
|
-
console=
|
|
327
|
-
project_root=
|
|
328
|
-
deploy_root=
|
|
329
|
-
bundle_root=
|
|
330
|
-
generated_root=
|
|
342
|
+
console=workspace_ctx.console,
|
|
343
|
+
project_root=workspace_ctx.project_root,
|
|
344
|
+
deploy_root=workspace_ctx.project_root / model.deploy_root,
|
|
345
|
+
bundle_root=workspace_ctx.project_root / model.bundle_root,
|
|
346
|
+
generated_root=(
|
|
347
|
+
workspace_ctx.project_root / model.deploy_root / model.generated_root
|
|
348
|
+
),
|
|
331
349
|
artifacts=model.artifacts,
|
|
332
350
|
package_name=package_name,
|
|
333
|
-
package_role=(model.meta and model.meta.role) or
|
|
351
|
+
package_role=(model.meta and model.meta.role) or workspace_ctx.default_role,
|
|
334
352
|
package_distribution=model.distribution,
|
|
335
353
|
version=version,
|
|
336
354
|
force=force,
|
|
@@ -380,7 +398,6 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
380
398
|
validate: bool,
|
|
381
399
|
stage_fqn: str,
|
|
382
400
|
post_deploy_hooks: list[PostDeployHook] | None,
|
|
383
|
-
package_scripts: List[str],
|
|
384
401
|
policy: PolicyBase,
|
|
385
402
|
) -> DiffResult:
|
|
386
403
|
# 1. Create a bundle if one wasn't passed in
|
|
@@ -405,16 +422,8 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
405
422
|
console.warning(e.message)
|
|
406
423
|
if not policy.should_proceed("Proceed with using this package?"):
|
|
407
424
|
raise typer.Abort() from e
|
|
408
|
-
with get_sql_executor().use_role(package_role):
|
|
409
|
-
cls.apply_package_scripts(
|
|
410
|
-
console=console,
|
|
411
|
-
package_scripts=package_scripts,
|
|
412
|
-
package_warehouse=package_warehouse,
|
|
413
|
-
project_root=project_root,
|
|
414
|
-
package_role=package_role,
|
|
415
|
-
package_name=package_name,
|
|
416
|
-
)
|
|
417
425
|
|
|
426
|
+
with get_sql_executor().use_role(package_role):
|
|
418
427
|
# 3. Upload files from deploy root local folder to the above stage
|
|
419
428
|
stage_schema = extract_schema(stage_fqn)
|
|
420
429
|
diff = sync_deploy_root_with_stage(
|
|
@@ -431,13 +440,13 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
431
440
|
print_diff=print_diff,
|
|
432
441
|
)
|
|
433
442
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
443
|
+
cls.execute_post_deploy_hooks(
|
|
444
|
+
console=console,
|
|
445
|
+
project_root=project_root,
|
|
446
|
+
post_deploy_hooks=post_deploy_hooks,
|
|
447
|
+
package_name=package_name,
|
|
448
|
+
package_warehouse=package_warehouse,
|
|
449
|
+
)
|
|
441
450
|
|
|
442
451
|
if validate:
|
|
443
452
|
cls.validate_setup_script(
|
|
@@ -455,8 +464,6 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
455
464
|
paths=paths,
|
|
456
465
|
stage_fqn=stage_fqn,
|
|
457
466
|
package_warehouse=package_warehouse,
|
|
458
|
-
post_deploy_hooks=post_deploy_hooks,
|
|
459
|
-
package_scripts=package_scripts,
|
|
460
467
|
policy=policy,
|
|
461
468
|
use_scratch_stage=False,
|
|
462
469
|
scratch_stage_fqn="",
|
|
@@ -500,7 +507,6 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
500
507
|
validate: bool,
|
|
501
508
|
stage_fqn: str,
|
|
502
509
|
post_deploy_hooks: list[PostDeployHook] | None,
|
|
503
|
-
package_scripts: List[str],
|
|
504
510
|
version: Optional[str],
|
|
505
511
|
patch: Optional[int],
|
|
506
512
|
force: bool,
|
|
@@ -593,7 +599,6 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
593
599
|
stage_fqn=stage_fqn,
|
|
594
600
|
package_warehouse=package_warehouse,
|
|
595
601
|
post_deploy_hooks=post_deploy_hooks,
|
|
596
|
-
package_scripts=package_scripts,
|
|
597
602
|
policy=policy,
|
|
598
603
|
)
|
|
599
604
|
|
|
@@ -685,7 +690,7 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
685
690
|
if err.msg.__contains__("does not exist or not authorized"):
|
|
686
691
|
raise ApplicationPackageDoesNotExistError(package_name)
|
|
687
692
|
else:
|
|
688
|
-
generic_sql_error_handler(err=err
|
|
693
|
+
generic_sql_error_handler(err=err)
|
|
689
694
|
return None
|
|
690
695
|
|
|
691
696
|
@classmethod
|
|
@@ -976,13 +981,10 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
976
981
|
for row in desc_cursor:
|
|
977
982
|
if row[0].lower() == "distribution":
|
|
978
983
|
return row[1].lower()
|
|
979
|
-
raise
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
'describe application package {package_name}'
|
|
984
|
-
"""
|
|
985
|
-
)
|
|
984
|
+
raise ObjectPropertyNotFoundError(
|
|
985
|
+
property_name="distribution",
|
|
986
|
+
object_type="application package",
|
|
987
|
+
object_name=package_name,
|
|
986
988
|
)
|
|
987
989
|
|
|
988
990
|
@classmethod
|
|
@@ -1037,53 +1039,6 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
1037
1039
|
)
|
|
1038
1040
|
)
|
|
1039
1041
|
|
|
1040
|
-
@classmethod
|
|
1041
|
-
def apply_package_scripts(
|
|
1042
|
-
cls,
|
|
1043
|
-
console: AbstractConsole,
|
|
1044
|
-
package_scripts: List[str],
|
|
1045
|
-
package_warehouse: Optional[str],
|
|
1046
|
-
project_root: Path,
|
|
1047
|
-
package_role: str,
|
|
1048
|
-
package_name: str,
|
|
1049
|
-
) -> None:
|
|
1050
|
-
"""
|
|
1051
|
-
Assuming the application package exists and we are using the correct role,
|
|
1052
|
-
applies all package scripts in-order to the application package.
|
|
1053
|
-
"""
|
|
1054
|
-
|
|
1055
|
-
metrics = get_cli_context().metrics
|
|
1056
|
-
metrics.set_counter_default(CLICounterField.PACKAGE_SCRIPTS, 0)
|
|
1057
|
-
|
|
1058
|
-
if not package_scripts:
|
|
1059
|
-
return
|
|
1060
|
-
|
|
1061
|
-
metrics.set_counter(CLICounterField.PACKAGE_SCRIPTS, 1)
|
|
1062
|
-
|
|
1063
|
-
console.warning(
|
|
1064
|
-
"WARNING: native_app.package.scripts is deprecated. Please migrate to using native_app.package.post_deploy."
|
|
1065
|
-
)
|
|
1066
|
-
|
|
1067
|
-
queued_queries = render_script_templates(
|
|
1068
|
-
project_root,
|
|
1069
|
-
dict(package_name=package_name),
|
|
1070
|
-
package_scripts,
|
|
1071
|
-
get_basic_jinja_env(),
|
|
1072
|
-
)
|
|
1073
|
-
|
|
1074
|
-
# once we're sure all the templates expanded correctly, execute all of them
|
|
1075
|
-
with cls.use_package_warehouse(
|
|
1076
|
-
package_warehouse=package_warehouse,
|
|
1077
|
-
):
|
|
1078
|
-
try:
|
|
1079
|
-
for i, queries in enumerate(queued_queries):
|
|
1080
|
-
console.step(f"Applying package script: {package_scripts[i]}")
|
|
1081
|
-
get_sql_executor().execute_queries(queries)
|
|
1082
|
-
except ProgrammingError as err:
|
|
1083
|
-
generic_sql_error_handler(
|
|
1084
|
-
err, role=package_role, warehouse=package_warehouse
|
|
1085
|
-
)
|
|
1086
|
-
|
|
1087
1042
|
@classmethod
|
|
1088
1043
|
def create_app_package(
|
|
1089
1044
|
cls,
|
|
@@ -1182,15 +1137,13 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
1182
1137
|
recursive: bool,
|
|
1183
1138
|
paths: List[Path] | None,
|
|
1184
1139
|
stage_fqn: str,
|
|
1185
|
-
post_deploy_hooks: list[PostDeployHook] | None,
|
|
1186
|
-
package_scripts: List[str],
|
|
1187
1140
|
policy: PolicyBase,
|
|
1188
1141
|
use_scratch_stage: bool,
|
|
1189
1142
|
scratch_stage_fqn: str,
|
|
1190
1143
|
):
|
|
1191
1144
|
"""Validates Native App setup script SQL."""
|
|
1192
1145
|
with console.phase(f"Validating Snowflake Native App setup script."):
|
|
1193
|
-
validation_result = cls.
|
|
1146
|
+
validation_result = cls.get_validation_result_static(
|
|
1194
1147
|
console=console,
|
|
1195
1148
|
project_root=project_root,
|
|
1196
1149
|
deploy_root=deploy_root,
|
|
@@ -1205,8 +1158,6 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
1205
1158
|
paths=paths,
|
|
1206
1159
|
stage_fqn=stage_fqn,
|
|
1207
1160
|
package_warehouse=package_warehouse,
|
|
1208
|
-
post_deploy_hooks=post_deploy_hooks,
|
|
1209
|
-
package_scripts=package_scripts,
|
|
1210
1161
|
policy=policy,
|
|
1211
1162
|
use_scratch_stage=use_scratch_stage,
|
|
1212
1163
|
scratch_stage_fqn=scratch_stage_fqn,
|
|
@@ -1226,8 +1177,36 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
1226
1177
|
if validation_result["status"] == "FAIL":
|
|
1227
1178
|
raise SetupScriptFailedValidation()
|
|
1228
1179
|
|
|
1180
|
+
def get_validation_result(self, use_scratch_stage: bool = True):
|
|
1181
|
+
model = self._entity_model
|
|
1182
|
+
workspace_ctx = self._workspace_ctx
|
|
1183
|
+
package_name = model.fqn.identifier
|
|
1184
|
+
return self.get_validation_result_static(
|
|
1185
|
+
console=workspace_ctx.console,
|
|
1186
|
+
project_root=workspace_ctx.project_root,
|
|
1187
|
+
deploy_root=workspace_ctx.project_root / model.deploy_root,
|
|
1188
|
+
bundle_root=workspace_ctx.project_root / model.bundle_root,
|
|
1189
|
+
generated_root=(
|
|
1190
|
+
workspace_ctx.project_root / model.deploy_root / model.generated_root
|
|
1191
|
+
),
|
|
1192
|
+
artifacts=model.artifacts,
|
|
1193
|
+
package_name=package_name,
|
|
1194
|
+
package_role=(model.meta and model.meta.role) or workspace_ctx.default_role,
|
|
1195
|
+
package_distribution=model.distribution,
|
|
1196
|
+
prune=True,
|
|
1197
|
+
recursive=True,
|
|
1198
|
+
paths=[],
|
|
1199
|
+
stage_fqn=f"{package_name}.{model.stage}",
|
|
1200
|
+
package_warehouse=(
|
|
1201
|
+
(model.meta and model.meta.warehouse) or workspace_ctx.default_warehouse
|
|
1202
|
+
),
|
|
1203
|
+
policy=AllowAlwaysPolicy(),
|
|
1204
|
+
use_scratch_stage=use_scratch_stage,
|
|
1205
|
+
scratch_stage_fqn=f"{package_name}.{model.scratch_stage}",
|
|
1206
|
+
)
|
|
1207
|
+
|
|
1229
1208
|
@classmethod
|
|
1230
|
-
def
|
|
1209
|
+
def get_validation_result_static(
|
|
1231
1210
|
cls,
|
|
1232
1211
|
console: AbstractConsole,
|
|
1233
1212
|
project_root: Path,
|
|
@@ -1243,8 +1222,6 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
1243
1222
|
recursive: bool,
|
|
1244
1223
|
paths: List[Path] | None,
|
|
1245
1224
|
stage_fqn: str,
|
|
1246
|
-
post_deploy_hooks: list[PostDeployHook] | None,
|
|
1247
|
-
package_scripts: List[str],
|
|
1248
1225
|
policy: PolicyBase,
|
|
1249
1226
|
use_scratch_stage: bool,
|
|
1250
1227
|
scratch_stage_fqn: str,
|
|
@@ -1270,8 +1247,7 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
|
|
|
1270
1247
|
validate=False,
|
|
1271
1248
|
stage_fqn=stage_fqn,
|
|
1272
1249
|
package_warehouse=package_warehouse,
|
|
1273
|
-
post_deploy_hooks=
|
|
1274
|
-
package_scripts=package_scripts,
|
|
1250
|
+
post_deploy_hooks=[],
|
|
1275
1251
|
policy=policy,
|
|
1276
1252
|
)
|
|
1277
1253
|
prefixed_stage_fqn = StageManager.get_standard_stage_prefix(stage_fqn)
|
|
@@ -111,3 +111,15 @@ class NoEventTableForAccount(ClickException):
|
|
|
111
111
|
|
|
112
112
|
def __init__(self):
|
|
113
113
|
super().__init__(f"{self.__doc__}\n\n{self.INSTRUCTIONS}")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class ObjectPropertyNotFoundError(RuntimeError):
|
|
117
|
+
def __init__(self, property_name: str, object_type: str, object_name: str):
|
|
118
|
+
super().__init__(
|
|
119
|
+
dedent(
|
|
120
|
+
f"""\
|
|
121
|
+
Could not find the '{property_name}' attribute for {object_type} {object_name} in the output of SQL query:
|
|
122
|
+
'describe {object_type} {object_name}'
|
|
123
|
+
"""
|
|
124
|
+
)
|
|
125
|
+
)
|
|
@@ -217,7 +217,7 @@ class NativeAppManager:
|
|
|
217
217
|
)
|
|
218
218
|
|
|
219
219
|
def get_existing_app_info(self) -> Optional[dict]:
|
|
220
|
-
return ApplicationEntity.
|
|
220
|
+
return ApplicationEntity.get_existing_app_info_static(
|
|
221
221
|
app_name=self.app_name,
|
|
222
222
|
app_role=self.app_role,
|
|
223
223
|
)
|
|
@@ -244,7 +244,7 @@ class NativeAppManager:
|
|
|
244
244
|
|
|
245
245
|
def get_snowsight_url(self) -> str:
|
|
246
246
|
"""Returns the URL that can be used to visit this app via Snowsight."""
|
|
247
|
-
return ApplicationEntity.
|
|
247
|
+
return ApplicationEntity.get_snowsight_url_static(
|
|
248
248
|
self.app_name, self.application_warehouse
|
|
249
249
|
)
|
|
250
250
|
|
|
@@ -256,25 +256,6 @@ class NativeAppManager:
|
|
|
256
256
|
package_distribution=self.package_distribution,
|
|
257
257
|
)
|
|
258
258
|
|
|
259
|
-
def _apply_package_scripts(self) -> None:
|
|
260
|
-
return ApplicationPackageEntity.apply_package_scripts(
|
|
261
|
-
console=cc,
|
|
262
|
-
package_scripts=self.package_scripts,
|
|
263
|
-
package_warehouse=self.package_warehouse,
|
|
264
|
-
project_root=self.project_root,
|
|
265
|
-
package_role=self.package_role,
|
|
266
|
-
package_name=self.package_name,
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
def execute_package_post_deploy_hooks(self) -> None:
|
|
270
|
-
execute_post_deploy_hooks(
|
|
271
|
-
console=cc,
|
|
272
|
-
project_root=self.project_root,
|
|
273
|
-
post_deploy_hooks=self.package_post_deploy_hooks,
|
|
274
|
-
deployed_object_type="application package",
|
|
275
|
-
database_name=self.package_name,
|
|
276
|
-
)
|
|
277
|
-
|
|
278
259
|
def execute_app_post_deploy_hooks(self) -> None:
|
|
279
260
|
execute_post_deploy_hooks(
|
|
280
261
|
console=cc,
|
|
@@ -334,15 +315,13 @@ class NativeAppManager:
|
|
|
334
315
|
paths=[],
|
|
335
316
|
stage_fqn=self.stage_fqn,
|
|
336
317
|
package_warehouse=self.package_warehouse,
|
|
337
|
-
post_deploy_hooks=self.package_post_deploy_hooks,
|
|
338
|
-
package_scripts=self.package_scripts,
|
|
339
318
|
policy=AllowAlwaysPolicy(),
|
|
340
319
|
use_scratch_stage=use_scratch_stage,
|
|
341
320
|
scratch_stage_fqn=self.scratch_stage_fqn,
|
|
342
321
|
)
|
|
343
322
|
|
|
344
323
|
def get_validation_result(self, use_scratch_stage: bool = False):
|
|
345
|
-
return ApplicationPackageEntity.
|
|
324
|
+
return ApplicationPackageEntity.get_validation_result_static(
|
|
346
325
|
console=cc,
|
|
347
326
|
project_root=self.project_root,
|
|
348
327
|
deploy_root=self.deploy_root,
|
|
@@ -357,8 +336,6 @@ class NativeAppManager:
|
|
|
357
336
|
paths=[],
|
|
358
337
|
stage_fqn=self.stage_fqn,
|
|
359
338
|
package_warehouse=self.package_warehouse,
|
|
360
|
-
post_deploy_hooks=self.package_post_deploy_hooks,
|
|
361
|
-
package_scripts=self.package_scripts,
|
|
362
339
|
policy=AllowAlwaysPolicy(),
|
|
363
340
|
use_scratch_stage=use_scratch_stage,
|
|
364
341
|
scratch_stage_fqn=self.scratch_stage_fqn,
|