Skip to content

Commit

Permalink
Replace clint by tqdm for progressbar
Browse files Browse the repository at this point in the history
Closes pypa#241 – As clint as some indirect Python 2 dependency and tqdm has
not.
  • Loading branch information
Carreau committed Apr 27, 2017
1 parent 6fa84f5 commit 4da3b23
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 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 =
clint
tqdm
requests >= 2.5.0
requests-toolbelt >= 0.5.1
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 = [
"clint",
"tqdm",
"pkginfo >= 1.0",
"requests >= 2.5.0",
"requests-toolbelt >= 0.5.1",
Expand Down
4 changes: 2 additions & 2 deletions twine/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import pkg_resources
import setuptools

import clint
import tqdm
import requests
import requests_toolbelt
import pkginfo
Expand All @@ -38,7 +38,7 @@ def list_dependencies_and_versions():
('requests', requests.__version__),
('setuptools', setuptools.__version__),
('requests-toolbelt', requests_toolbelt.__version__),
('clint', clint.__version__),
('tqdm', tqdm.__version__),
]


Expand Down
13 changes: 9 additions & 4 deletions twine/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
from __future__ import absolute_import, unicode_literals, print_function

from clint.textui.progress import Bar as ProgressBar
from tqdm import tqdm as ProgressBar

import requests
from requests import adapters
Expand Down Expand Up @@ -121,9 +121,14 @@ def _upload(self, package):
(package.basefilename, fp, "application/octet-stream"),
))
encoder = MultipartEncoder(data_to_send)
bar = ProgressBar(expected_size=encoder.len, filled_char='=')
bar = ProgressBar(total=encoder.len, unit='bytes', unit_scale=True, leave=False)
def update_progressbar(monitor, _cache=[0]):
total_read = monitor.bytes_read
bar.update(total_read - _cache[0])
_cache[0] = total_read

monitor = MultipartEncoderMonitor(
encoder, lambda monitor: bar.show(monitor.bytes_read)
encoder, update_progressbar
)

resp = self.session.post(
Expand All @@ -132,7 +137,7 @@ def _upload(self, package):
allow_redirects=False,
headers={'Content-Type': monitor.content_type},
)
bar.done()
bar.close()

return resp

Expand Down

0 comments on commit 4da3b23

Please sign in to comment.