Skip to content

Commit fcc269e

Browse files
committed
Enhance download_and_extract
Signed-off-by: jerome_Hsieh <[email protected]>
1 parent 8143ac3 commit fcc269e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

monai/apps/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def extractall(
301301
)
302302

303303

304-
def get_filename_from_url(data_url: str):
304+
def _get_filename_from_url(data_url: str):
305305
try:
306306
if "drive.google.com" in data_url:
307307
response = requests.head(data_url, allow_redirects=True)
@@ -327,7 +327,7 @@ def get_filename_from_url(data_url: str):
327327
filename = _basename(data_url)
328328
return filename
329329
except Exception as e:
330-
raise Exception(f"Error processing URL: {e}")
330+
raise Exception(f"Error processing URL: {e}") from e
331331

332332

333333
def download_and_extract(
@@ -359,7 +359,7 @@ def download_and_extract(
359359
be False.
360360
progress: whether to display progress bar.
361361
"""
362-
url_filename_ext = "".join(Path(get_filename_from_url(url)).suffixes)
362+
url_filename_ext = "".join(Path(_get_filename_from_url(url)).suffixes)
363363
filepath_ext = "".join(Path(_basename(filepath)).suffixes)
364364
if filepath not in ["", "."]:
365365
if filepath_ext == "":
@@ -371,6 +371,6 @@ def download_and_extract(
371371
if filepath_ext and filepath_ext != url_filename_ext:
372372
raise ValueError(f"File extension mismatch: expected extension {url_filename_ext}, but get {filepath_ext}")
373373
with tempfile.TemporaryDirectory() as tmp_dir:
374-
filename = filepath or Path(tmp_dir, get_filename_from_url(url)).resolve()
374+
filename = filepath or Path(tmp_dir, _get_filename_from_url(url)).resolve()
375375
download_url(url=url, filepath=filename, hash_val=hash_val, hash_type=hash_type, progress=progress)
376376
extractall(filepath=filename, output_dir=output_dir, file_type=file_type, has_base=has_base)

0 commit comments

Comments
 (0)