Skip to content

Commit

Permalink
More robust download
Browse files Browse the repository at this point in the history
  • Loading branch information
Zethson committed Mar 3, 2025
1 parent fc5ca02 commit 17900e0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name-template: "0.10.0 🌈"
tag-template: 0.10.0
name-template: "0.10.1 🌈"
tag-template: 0.10.1
exclude-labels:
- "skip-changelog"

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
- os: ubuntu-22.04
python: "3.13"
run_mode: "fast"
# - os: ubuntu-latest
# python: "3.13"
# run_mode: slow
# pip-flags: "--pre"
- os: ubuntu-latest
python: "3.13"
run_mode: slow
pip-flags: "--pre"

env:
OS: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion pertpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = "Lukas Heumos"
__email__ = "[email protected]"
__version__ = "0.10.0"
__version__ = "0.10.1"

import warnings

Expand Down
49 changes: 27 additions & 22 deletions pertpy/data/_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,35 @@ def _download( # pragma: no cover

Path(output_path).mkdir(parents=True, exist_ok=True)
lock_path = f"{output_path}/{output_file_name}.lock"
with FileLock(lock_path):
if Path(download_to_path).exists() and not overwrite:
logger.warning(f"File {download_to_path} already exists!")
return

temp_file_name = f"{download_to_path}.part"
try:
with FileLock(lock_path, timeout=30):
if Path(download_to_path).exists() and not overwrite:
logger.warning(f"File {download_to_path} already exists!")
return

response = requests.get(url, stream=True)
total = int(response.headers.get("content-length", 0))
temp_file_name = f"{download_to_path}.part"
response = requests.get(url, stream=True)
total = int(response.headers.get("content-length", 0))

with Progress(refresh_per_second=5) as progress:
task = progress.add_task("[red]Downloading...", total=total)
with Path(temp_file_name).open("wb") as file:
for data in response.iter_content(block_size):
file.write(data)
progress.update(task, advance=block_size)
progress.update(task, completed=total, refresh=True)
with Progress(refresh_per_second=5) as progress:
task = progress.add_task("[red]Downloading...", total=total)
with Path(temp_file_name).open("wb") as file:
for data in response.iter_content(block_size):
file.write(data)
progress.update(task, advance=block_size)
progress.update(task, completed=total, refresh=True)

Path(temp_file_name).replace(download_to_path)
Path(temp_file_name).replace(download_to_path)

if is_zip:
output_path = output_path or tempfile.gettempdir()
with ZipFile(download_to_path, "r") as zip_obj:
zip_obj.extractall(path=output_path)
zip_obj.namelist()

Path(lock_path).unlink()
if is_zip:
output_path = output_path or tempfile.gettempdir()
with ZipFile(download_to_path, "r") as zip_obj:
zip_obj.extractall(path=output_path)
zip_obj.namelist()
finally:
if Path(lock_path).exists():
try:
Path(lock_path).unlink()
except OSError:
pass
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ requires = ["hatchling"]

[project]
name = "pertpy"
version = "0.10.0"
version = "0.10.1"
description = "Perturbation Analysis in the scverse ecosystem."
readme = "README.md"
requires-python = ">=3.10,<3.14"
Expand Down

0 comments on commit 17900e0

Please sign in to comment.