Skip to content

Commit

Permalink
chore: remove tqdm (#990)
Browse files Browse the repository at this point in the history
* chore: remove tqdm

Signed-off-by: ThibaultFy <thibault.fouqueray@gmail.com>

* chore: changelog

Signed-off-by: ThibaultFy <thibault.fouqueray@gmail.com>

* chore: add logging

Signed-off-by: ThibaultFy <thibault.fouqueray@gmail.com>

* chore: wrap function in try expects with logs

Signed-off-by: ThibaultFy <thibault.fouqueray@gmail.com>

* chore: fix event logger

Signed-off-by: ThibaultFy <thibault.fouqueray@gmail.com>

* chore: change logger

Signed-off-by: Guilhem Barthés <guilhem.barthes@owkin.com>

* chore: typo

Signed-off-by: Guilhem Barthés <guilhem.barthes@owkin.com>

---------

Signed-off-by: ThibaultFy <thibault.fouqueray@gmail.com>
Signed-off-by: Guilhem Barthés <guilhem.barthes@owkin.com>
Co-authored-by: Guilhem Barthés <guilhem.barthes@owkin.com>
  • Loading branch information
ThibaultFy and guilhem-barthes authored Sep 13, 2024
1 parent b7b0f09 commit 5033cd0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
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))
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

0 comments on commit 5033cd0

Please sign in to comment.