4
4
from snowflake .cli ._plugins .connection .util import make_snowsight_url
5
5
from snowflake .cli ._plugins .notebook .notebook_entity_model import NotebookEntityModel
6
6
from snowflake .cli ._plugins .notebook .notebook_project_paths import NotebookProjectPaths
7
- from snowflake .cli ._plugins .stage .manager import StageManager
8
7
from snowflake .cli ._plugins .workspace .context import ActionContext
9
- from snowflake .cli .api .artifacts .utils import bundle_artifacts
8
+ from snowflake .cli .api .artifacts .upload import sync_artifacts_with_stage
10
9
from snowflake .cli .api .cli_global_context import get_cli_context
11
10
from snowflake .cli .api .console .console import cli_console
12
11
from snowflake .cli .api .entities .common import EntityBase
@@ -22,12 +21,15 @@ class NotebookEntity(EntityBase[NotebookEntityModel]):
22
21
A notebook.
23
22
"""
24
23
24
+ @property
25
+ def _stage_path_from_model (self ) -> str :
26
+ if self .model .stage_path is None :
27
+ return f"{ _DEFAULT_NOTEBOOK_STAGE_NAME } /{ self .fqn .name } "
28
+ return self .model .stage_path
29
+
25
30
@functools .cached_property
26
31
def _stage_path (self ) -> StagePath :
27
- stage_path = self .model .stage_path
28
- if stage_path is None :
29
- stage_path = f"{ _DEFAULT_NOTEBOOK_STAGE_NAME } /{ self .fqn .name } "
30
- return StagePath .from_stage_str (stage_path )
32
+ return StagePath .from_stage_str (self ._stage_path_from_model )
31
33
32
34
@functools .cached_property
33
35
def _project_paths (self ):
@@ -41,26 +43,6 @@ def _object_exists(self) -> bool:
41
43
except ProgrammingError :
42
44
return False
43
45
44
- def _upload_artifacts (self ):
45
- stage_fqn = self ._stage_path .stage_fqn
46
- stage_manager = StageManager ()
47
- cli_console .step (f"Creating stage { stage_fqn } if not exists" )
48
- stage_manager .create (fqn = stage_fqn )
49
-
50
- cli_console .step ("Uploading artifacts" )
51
-
52
- # creating bundle map to handle glob patterns logic
53
- bundle_map = bundle_artifacts (self ._project_paths , self .model .artifacts )
54
- for absolute_src , absolute_dest in bundle_map .all_mappings (
55
- absolute = True , expand_directories = True
56
- ):
57
- artifact_stage_path = self ._stage_path / (
58
- absolute_dest .relative_to (self ._project_paths .bundle_root ).parent
59
- )
60
- stage_manager .put (
61
- local_path = absolute_src , stage_path = artifact_stage_path , overwrite = True
62
- )
63
-
64
46
def get_create_sql (self , replace : bool ) -> str :
65
47
main_file_stage_path = self ._stage_path / (
66
48
self .model .notebook_file .absolute ().relative_to (
@@ -99,6 +81,7 @@ def action_deploy(
99
81
self ,
100
82
action_ctx : ActionContext ,
101
83
replace : bool ,
84
+ prune : bool ,
102
85
* args ,
103
86
** kwargs ,
104
87
) -> str :
@@ -108,7 +91,13 @@ def action_deploy(
108
91
f"Notebook { self .fqn .name } already exists. Consider using --replace."
109
92
)
110
93
with cli_console .phase (f"Uploading artifacts to { self ._stage_path } " ):
111
- self ._upload_artifacts ()
94
+ sync_artifacts_with_stage (
95
+ project_paths = self ._project_paths ,
96
+ stage_root = self ._stage_path_from_model ,
97
+ prune = prune ,
98
+ artifacts = self .model .artifacts ,
99
+ )
100
+
112
101
with cli_console .phase (f"Creating notebook { self .fqn } " ):
113
102
return self .action_create (replace = replace )
114
103
0 commit comments