Skip to content

Commit

Permalink
Merge pull request #258 from roboflow/fix/make-tqdm-logging-controlla…
Browse files Browse the repository at this point in the history
…ble-via-envvar

Added an environment variable to silence TQDM output
  • Loading branch information
capjamesg authored Jun 6, 2024
2 parents aa309a5 + 2a48213 commit 76b4483
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions roboflow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def get_conditional_configuration_variable(key, default):
DEFAULT_JOB_NAME = "Annotated via API"

RF_WORKSPACES = get_conditional_configuration_variable("workspaces", default={})
TQDM_DISABLE = os.getenv("TQDM_DISABLE", None)


def load_roboflow_api_key(workspace_url=None):
Expand Down
7 changes: 5 additions & 2 deletions roboflow/core/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
API_URL,
APP_URL,
DEMO_KEYS,
TQDM_DISABLE,
TYPE_CLASSICATION,
TYPE_INSTANCE_SEGMENTATION,
TYPE_KEYPOINT_DETECTION,
Expand Down Expand Up @@ -740,9 +741,10 @@ def bar_progress(current, total, width=80):
# write the zip file to the desired location
with open(location + "/roboflow.zip", "wb") as f:
total_length = int(response.headers.get("content-length"))
desc = None if TQDM_DISABLE else f"Downloading Dataset Version Zip in {location} to {format}:"
for chunk in tqdm(
response.iter_content(chunk_size=1024),
desc=f"Downloading Dataset Version Zip in {location} to {format}:",
desc=desc,
total=int(total_length / 1024) + 1,
):
if chunk:
Expand All @@ -766,10 +768,11 @@ def __extract_zip(self, location, format):
Raises:
RuntimeError: If there is an error unzipping the file
""" # noqa: E501 // docs
desc = None if TQDM_DISABLE else f"Extracting Dataset Version Zip to {location} in {format}:"
with zipfile.ZipFile(location + "/roboflow.zip", "r") as zip_ref:
for member in tqdm(
zip_ref.infolist(),
desc=f"Extracting Dataset Version Zip to {location} in {format}:",
desc=desc,
):
try:
zip_ref.extract(member, location)
Expand Down

0 comments on commit 76b4483

Please sign in to comment.