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

remove tqdm dependency #359

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 5 additions & 1 deletion b2sdk/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ def __exit__(self, exc_type, exc_val, exc_tb):
class TqdmProgressListener(AbstractProgressListener):
"""
Progress listener based on tqdm library.

This listener displays a nice progress bar, but requires `tqdm` package to be installed.
"""

def __init__(self, *args, **kwargs):
if tqdm is None:
raise ModuleNotFoundError("No module named 'tqdm' found")
self.tqdm = None # set in set_total_bytes()
self.prev_value = 0
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -212,7 +216,7 @@ def get_calls(self) -> list[str]:

def make_progress_listener(description: str, quiet: bool) -> AbstractProgressListener:
"""
Return a progress listener object depending on some conditions.
Produce the best progress listener available for the given parameters.

:param description: listener description
:param quiet: if ``True``, do not output anything
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+tqdm_removal.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove `tqdm` dependency. Now `tqdm` has to be explicitly installed to use `TqdmProgressListener` class.
8 changes: 4 additions & 4 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ dependencies = [
"importlib-metadata>=3.3.0; python_version < '3.8'",
"logfury<2.0.0,>=1.0.1",
"requests<3.0.0,>=2.9.1",
"tqdm<5.0.0,>=4.5.0",
"typing-extensions>=4.7.1; python_version < '3.12'",
"packaging>=21.0",
]
Expand Down Expand Up @@ -180,6 +179,7 @@ test = [
"pytest-lazy-fixture==0.6.3",
"pytest-xdist==2.5.0",
"pytest-timeout==2.1.0",
"tqdm<5.0.0,>=4.5.0",
]
release = [
"towncrier==23.11.0; python_version>='3.8'",
Expand Down
33 changes: 33 additions & 0 deletions test/unit/test_progress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
######################################################################
#
# File: test/unit/test_progress.py
#
# Copyright 2024 Backblaze Inc. All Rights Reserved.
#
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
import pytest
from apiver_deps import TqdmProgressListener, make_progress_listener


@pytest.mark.parametrize(
"tqdm_available, quiet, expected_listener",
[
(True, False, "TqdmProgressListener"),
(False, False, "SimpleProgressListener"),
(False, True, "DoNothingProgressListener"),
],
)
def test_make_progress_listener(tqdm_available, quiet, expected_listener, monkeypatch):
if not tqdm_available:
monkeypatch.setattr("b2sdk.progress.tqdm", None)

assert make_progress_listener("description", quiet).__class__.__name__ == expected_listener


def test_tqdm_progress_listener__without_tqdm_module(monkeypatch):
monkeypatch.setattr("b2sdk.progress.tqdm", None)

with pytest.raises(ModuleNotFoundError):
TqdmProgressListener("description")