1+ import logging
2+
3+ logger = logging .getLogger ("root.artifacts" )
4+
15import json
26import os
37import shutil
@@ -40,6 +44,7 @@ def get_index_path(self) -> Path:
4044 def get_artifact_path_in_cache (self , artifact_name : str ) -> Path :
4145 artifact_path = self ._cache_path / artifact_name
4246 if not artifact_path .exists ():
47+ logger .error (f'Artifact "{ artifact_name } " not in cache' )
4348 raise FileNotFoundError (f'Artifact "{ artifact_name } " not in cache' )
4449 return artifact_path
4550
@@ -52,13 +57,18 @@ def download_artifact_to_cache(
5257 ) -> None :
5358 artifact_path = self ._cache_path / artifact_name
5459 if artifact_path .exists ():
60+ logger .info (f"Artifact already in cache using { hit_strategy = } " )
5561 if hit_strategy == self .HitStrategy .RAISE :
62+ logger .error (f'Artifact "{ artifact_name } " already in cache' )
5663 raise ValueError (f'Artifact "{ artifact_name } " already in cache' )
5764 elif hit_strategy == self .HitStrategy .PASS :
65+ logger .info (f"Skipped artifact" )
5866 return
5967 elif hit_strategy == self .HitStrategy .OVERWRITE :
68+ logger .info (f"Overwriting artifact" )
6069 shutil .rmtree (artifact_path )
6170 else :
71+ logger .error (f'Unexcpected value "{ hit_strategy = } "' )
6272 raise RuntimeError (f'Unexcpected value "{ hit_strategy = } "' )
6373
6474 artifact_path .mkdir (exist_ok = False )
@@ -70,6 +80,7 @@ def download_artifact_to_cache(
7080 download_url = artifact_meta [ARTF_META_URL_FIELD ]
7181
7282 with tempfile .TemporaryDirectory () as temp_dir :
83+ logger .info ("Downloading artifact to temporary directory" )
7384 download_path = self ._download_file (
7485 artifact_name = artifact_name ,
7586 download_url = download_url ,
@@ -108,6 +119,7 @@ def _download_file(
108119 with_progress_bar : bool ,
109120 ) -> Path :
110121 response = requests .get (download_url , stream = True )
122+ logger .info (f"{ response .status_code } response from { download_url } " )
111123 response .raise_for_status ()
112124
113125 dl_filename = None
@@ -123,10 +135,13 @@ def _download_file(
123135 dl_filename = "=" .join (split_param [1 :]).strip ().strip ("'\" " )
124136 break
125137
126- # otherwise, use name from URL:
127- if dl_filename is None :
138+ if dl_filename :
139+ logger .info (f"Resolved filename from response header { dl_filename } " )
140+ else :
141+ # otherwise, use name from URL:
128142 parsed_url = urlparse (download_url )
129143 dl_filename = Path (parsed_url .path ).name
144+ logger .info (f"Resolved filename from url { dl_filename } " )
130145
131146 total_size = int (response .headers .get ("content-length" , 0 ))
132147 block_size = 1024 # 1 KB
@@ -168,13 +183,16 @@ def _finalize_download(
168183 attempt_unpack = True
169184
170185 if attempt_unpack :
186+ logger .info ("Unpacking archive and moving to destination" )
171187 shutil .unpack_archive (dl_path_str , target_path )
172188 else :
189+ logger .info ("Moving archive to destination" )
173190 shutil .move (dl_path_str , target_path / "" )
174191
175192 def _get_artifact_meta (self , artifact_name : str ) -> Dict :
176193 file_path = self ._index_path / artifact_name / ARTF_META_FILENAME
177194 if not file_path .exists ():
195+ logger .error (f'File "{ file_path } " does not exist' )
178196 raise FileNotFoundError (f'File "{ file_path } " does not exist' )
179197 with open (file_path , "r" ) as file :
180198 meta_info = json .load (file )
0 commit comments