Skip to content

Commit

Permalink
add success condition for download_url function
Browse files Browse the repository at this point in the history
  • Loading branch information
CunliangGeng committed Aug 25, 2023
1 parent f410a6f commit d96c159
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/nplinker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def get_headers(file: str | PathLike) -> list[str]:
dl = find_delimiter(file)
return headers.split(dl)


def is_file_format(file: str | PathLike, format: str = "tsv") -> bool:
"""Check if the file is in the given format.
Expand All @@ -102,6 +103,7 @@ def is_file_format(file: str | PathLike, format: str = "tsv") -> bool:
except csv.Error:
return False


# Functions below are adapted from torchvision library,
# see: https://github.com/pytorch/vision/blob/main/torchvision/datasets/utils.py.
#
Expand Down Expand Up @@ -170,8 +172,11 @@ def download_url(url: str,
with httpx.stream(http_method,
url,
follow_redirects=allow_http_redirect) as response:
if not response.is_success:
raise RuntimeError(
f"Failed to download url {url} with status code {response.status_code}"
)
total = int(response.headers.get("Content-Length", 0))

with tqdm(total=total,
unit_scale=True,
unit_divisor=1024,
Expand Down

0 comments on commit d96c159

Please sign in to comment.