1717
1818import click
1919from rich import print as rich_print
20+ from rich .progress import (
21+ BarColumn ,
22+ Progress ,
23+ TextColumn ,
24+ TimeElapsedColumn ,
25+ )
2026from rich .tree import Tree
2127
2228from flytekit .constants import CopyFileDetection
2329from flytekit .core .context_manager import FlyteContextManager
2430from flytekit .core .python_auto_container import PICKLE_FILE_PATH
2531from flytekit .core .utils import timeit
2632from flytekit .exceptions .user import FlyteDataNotFoundException
27- from flytekit .loggers import logger
33+ from flytekit .loggers import is_display_progress_enabled , logger
2834from flytekit .tools .ignore import DockerIgnore , FlyteIgnore , GitIgnore , Ignore , IgnoreGroup , StandardIgnore
2935from flytekit .tools .script_mode import _filehash_update , _pathhash_update , ls_files , tar_strip_file_attributes
3036
@@ -120,6 +126,18 @@ def fast_package(
120126 if options and (
121127 options .copy_style == CopyFileDetection .LOADED_MODULES or options .copy_style == CopyFileDetection .ALL
122128 ):
129+ create_tarball_progress = Progress (
130+ TimeElapsedColumn (),
131+ TextColumn ("[progress.description]{task.description}." ),
132+ BarColumn (),
133+ TextColumn ("{task.fields[files_added_progress]}" ),
134+ )
135+
136+ compress_tarball_progress = Progress (
137+ TimeElapsedColumn (),
138+ TextColumn ("[progress.description]{task.description}" ),
139+ )
140+
123141 ls , ls_digest = ls_files (str (source ), options .copy_style , deref_symlinks , ignore )
124142 logger .debug (f"Hash digest: { ls_digest } " )
125143
@@ -130,13 +148,30 @@ def fast_package(
130148 archive_fname = f"{ FAST_PREFIX } { ls_digest } { FAST_FILEENDING } "
131149 if output_dir is None :
132150 output_dir = tempfile .mkdtemp ()
133- click .secho (f"No output path provided, using a temporary directory at { output_dir } instead" , fg = "yellow" )
151+ click .secho (
152+ f"No output path provided, using a temporary directory at { output_dir } instead" ,
153+ fg = "yellow" ,
154+ )
134155 archive_fname = os .path .join (output_dir , archive_fname )
135156
157+ # add the tarfile task to progress and start it
158+ total_files = len (ls )
159+ files_processed = 0
160+ tar_task = create_tarball_progress .add_task (
161+ f"Creating tarball with [{ total_files } ] files..." ,
162+ total = total_files ,
163+ files_added_progress = f"{ files_processed } /{ total_files } files" ,
164+ )
165+
166+ if is_display_progress_enabled ():
167+ create_tarball_progress .start ()
168+
169+ create_tarball_progress .start_task (tar_task )
136170 with tempfile .TemporaryDirectory () as tmp_dir :
137171 tar_path = os .path .join (tmp_dir , "tmp.tar" )
138172 with tarfile .open (tar_path , "w" , dereference = deref_symlinks ) as tar :
139173 for ws_file in ls :
174+ files_processed = files_processed + 1
140175 rel_path = os .path .relpath (ws_file , start = source )
141176 tar .add (
142177 os .path .join (source , ws_file ),
@@ -145,7 +180,34 @@ def fast_package(
145180 filter = lambda x : tar_strip_file_attributes (x ),
146181 )
147182
183+ create_tarball_progress .update (
184+ tar_task ,
185+ advance = 1 ,
186+ description = f"Added file { rel_path } " ,
187+ refresh = True ,
188+ files_added_progress = f"{ files_processed } /{ total_files } files" ,
189+ )
190+
191+ create_tarball_progress .stop_task (tar_task )
192+ if is_display_progress_enabled ():
193+ create_tarball_progress .stop ()
194+ compress_tarball_progress .start ()
195+
196+ tpath = pathlib .Path (tar_path )
197+ size_mbs = tpath .stat ().st_size / 1024 / 1024
198+ compress_task = compress_tarball_progress .add_task (f"Compressing tarball size { size_mbs :.2f} MB..." , total = 1 )
199+ compress_tarball_progress .start_task (compress_task )
148200 compress_tarball (tar_path , archive_fname )
201+ arpath = pathlib .Path (archive_fname )
202+ asize_mbs = arpath .stat ().st_size / 1024 / 1024
203+ compress_tarball_progress .update (
204+ compress_task ,
205+ advance = 1 ,
206+ description = f"Tarball { size_mbs :.2f} MB compressed to { asize_mbs :.2f} MB" ,
207+ )
208+ compress_tarball_progress .stop_task (compress_task )
209+ if is_display_progress_enabled ():
210+ compress_tarball_progress .stop ()
149211
150212 # Original tar command - This condition to be removed in the future after serialize is removed.
151213 else :
0 commit comments