Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove tqdm #990

Merged
merged 7 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions backend/image_transfer/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from typing import Optional
from typing import Union

import structlog
from dxf import DXF
from dxf import DXFBase
from requests import HTTPError
from tqdm import tqdm

from image_transfer.common import Authenticator
from image_transfer.common import Blob
Expand All @@ -23,6 +23,8 @@
from substrapp.docker_registry import RegistryPreconditionFailedException
from substrapp.utils import safezip

logger = structlog.get_logger("worker")


def add_blobs_to_zip(
dxf_base: DXFBase,
Expand Down Expand Up @@ -58,15 +60,23 @@ def add_blobs_to_zip(

def download_blob_to_zip(dxf_base: DXFBase, blob: Blob, zip_file: safezip.ZipFile):
repository_dxf = DXF.from_base(dxf_base, blob.repository)
bytes_iterator, total_size = repository_dxf.pull_blob(blob.digest, size=True)
try:
bytes_iterator, total_size = repository_dxf.pull_blob(blob.digest, size=True)
except Exception as e:
logger.exception(f"Failed to download blob {blob}", e=e)
raise e

# we write the blob directly to the zip file
with tqdm(total=total_size, unit="B", unit_scale=True) as pbar:
blob_path_in_zip = f"blobs/{blob.digest}"
blob_path_in_zip = f"blobs/{blob.digest}"
try:
with zip_file.open(blob_path_in_zip, "w", force_zip64=True) as blob_in_zip:
for chunk in bytes_iterator:
blob_in_zip.write(chunk)
pbar.update(len(chunk))
guilhem-barthes marked this conversation as resolved.
Show resolved Hide resolved
except Exception as e:
logger.exception(f"Failed to write blob {blob} to zip file", e=e)
raise e

logger.info(f"Blob {blob} of size {total_size} downloaded and stored in zip file")
return blob_path_in_zip


Expand Down
1 change: 0 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ django-filter==24.2
pydantic==2.4.0
redis==5.0.0
mozilla-django-oidc==4.0.1
tqdm==4.66.4
python-dxf==12.1.0
watchdog==2.1.9
# Prevent error linked to Deprecation warnings
Expand Down
1 change: 1 addition & 0 deletions changes/990.removed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`tqdm` dependency, only used in logging
Loading