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

update and tweak tqdm progressbar #256

Merged
merged 1 commit into from
May 29, 2017
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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ignore =

[metadata]
requires-dist =
tqdm >= 4.11
tqdm >= 4.14
requests >= 2.5.0, != 2.15, != 2.16
requests-toolbelt >= 0.8.0
pkginfo >= 1.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


install_requires = [
"tqdm >= 4.11",
"tqdm >= 4.14",
"pkginfo >= 1.0",
"requests >= 2.5.0, != 2.15, != 2.16",
"requests-toolbelt >= 0.8.0",
Expand Down
8 changes: 4 additions & 4 deletions twine/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@


class ProgressBar(tqdm):

def update_to(self, n):
"""Update the bar in the way compatible with requests-toolbelt.

This is identical to tqdm.update, except ``n`` will be the current
value - not the delta as tqdm expects.
"""
self.update(n - self.n)
self.update(n - self.n) # will also do self.n = n


class Repository(object):
Expand Down Expand Up @@ -136,8 +135,9 @@ def _upload(self, package):
(package.basefilename, fp, "application/octet-stream"),
))
encoder = MultipartEncoder(data_to_send)
with ProgressBar(total=encoder.len, unit='bytes',
unit_scale=True, leave=False) as bar:
with ProgressBar(total=encoder.len,
unit='B', unit_scale=True, unit_divisor=1024,
miniters=1) as bar:
monitor = MultipartEncoderMonitor(
encoder, lambda monitor: bar.update_to(monitor.bytes_read)
)
Expand Down