Skip to content

Commit

Permalink
Merge pull request #256 from tqdm/tqdm-update
Browse files Browse the repository at this point in the history
update and tweak tqdm progressbar
  • Loading branch information
sigmavirus24 authored May 29, 2017
2 parents 43f1505 + 3b76685 commit 04cd2ff
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
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

0 comments on commit 04cd2ff

Please sign in to comment.