Skip to content

Commit 2bc5fdd

Browse files
✨ introduce proper logging (#138)
* update workflow before publishing python package * fix dependency issue and bump version * point to website in project description * fix broken dependency * improve doc * add github token to download artifacts * ensure only read-access @wvangeit * yet another attempt at downloading artifacts * make sure to use repo that ran the trigger wf * another attempt at fixing * change owner * allow publishing to testpypi also when pr * minor change * revert minor (but breaking) change * minor fix * add debug messages * another debug message * hopefully the final version * final fix * minor fix * move master and tag to individual jobs * add debug messages * dev->post * add python script for determining semantic version * minor changes * minor changes * improve error handling and add version file to artifacts * check if release * minor fix * ensure to enter venv * also when tagging * source venv in publishin workflow * ensure only master * add script for testing 'pure' semver * adapt workflows to new python script * minor change * attempt to evaluate expressions correctly * several fixes to fix tests * ensure repo is checked out in publish workflow * several small fixes * cleanup * debug * minor cleanup * mionr changes * add debug message * minor change * minor change * yet another try * minor change * minor change * minor change * mionr change * minor changes * correct workflow run id * cosmetic change * avoid using gh * change to a single job for publishing * minor cleanup * swap loops in clean up jobs * correction * update server compatibility to new url * minor change to trigger ci * fix logging * capitalize @pcrespov
1 parent 3df9fc5 commit 2bc5fdd

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

clients/python/client/osparc/_files_api.py

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import json
3+
import logging
34
import math
45
import random
56
import shutil
@@ -17,6 +18,7 @@
1718
from osparc_client import FilesApi as _FilesApi
1819
from osparc_client import FileUploadCompletionBody, FileUploadData, UploadedPart
1920
from tqdm.asyncio import tqdm
21+
from tqdm.contrib.logging import logging_redirect_tqdm
2022

2123
from . import ApiClient, File
2224
from ._http_client import AsyncHttpClient
@@ -28,6 +30,8 @@
2830
file_chunk_generator,
2931
)
3032

33+
_logger = logging.getLogger(__name__)
34+
3135

3236
class FilesApi(_FilesApi):
3337
"""Class for interacting with files"""
@@ -113,41 +117,44 @@ async def upload_file_async(
113117
)
114118

115119
uploaded_parts: list[UploadedPart] = []
116-
print("- uploading chunks...")
117120
async with AsyncHttpClient(
118121
configuration=self.api_client.configuration, timeout=timeout_seconds
119122
) as session:
120-
async for chunck, size in tqdm(
121-
file_chunk_generator(file, chunk_size), total=n_urls
122-
):
123-
index, url = next(url_iter)
124-
uploaded_parts.append(
125-
await self._upload_chunck(
126-
http_client=session,
127-
chunck=chunck,
128-
chunck_size=size,
129-
upload_link=url,
130-
index=index,
123+
with logging_redirect_tqdm():
124+
_logger.info("Uploading %i chunks", n_urls)
125+
async for chunck, size in tqdm(
126+
file_chunk_generator(file, chunk_size),
127+
total=n_urls,
128+
disable=(not _logger.isEnabledFor(logging.INFO)),
129+
):
130+
index, url = next(url_iter)
131+
uploaded_parts.append(
132+
await self._upload_chunck(
133+
http_client=session,
134+
chunck=chunck,
135+
chunck_size=size,
136+
upload_link=url,
137+
index=index,
138+
)
131139
)
132-
)
133140

134-
async with AsyncHttpClient(
135-
configuration=self.api_client.configuration,
136-
request_type="post",
137-
url=links.abort_upload,
138-
base_url=self.api_client.configuration.host,
139-
follow_redirects=True,
140-
auth=self._auth,
141-
timeout=timeout_seconds,
142-
) as session:
143-
print(
144-
"- completing upload (this might take a couple of minutes)..."
145-
)
146-
server_file: File = await self._complete_multipart_upload(
147-
session, links.complete_upload, client_file, uploaded_parts
148-
)
149-
print("- file upload complete")
150-
return server_file
141+
async with AsyncHttpClient(
142+
configuration=self.api_client.configuration,
143+
request_type="post",
144+
url=links.abort_upload,
145+
base_url=self.api_client.configuration.host,
146+
follow_redirects=True,
147+
auth=self._auth,
148+
timeout=timeout_seconds,
149+
) as session:
150+
_logger.info(
151+
"Completing upload (this might take a couple of minutes)..."
152+
)
153+
server_file: File = await self._complete_multipart_upload(
154+
session, links.complete_upload, client_file, uploaded_parts
155+
)
156+
_logger.info("File upload complete")
157+
return server_file
151158

152159
async def _complete_multipart_upload(
153160
self,

0 commit comments

Comments
 (0)