From 18ce6111217d66229c2868cac6e0bf7f7f70099f Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 27 Apr 2017 13:59:20 -0700 Subject: [PATCH] Replace clint by tqdm for progressbar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #241 – As clint as some indirect Python 2 dependency and tqdm has not. --- setup.cfg | 2 +- setup.py | 2 +- twine/cli.py | 4 ++-- twine/repository.py | 35 ++++++++++++++++++++++------------- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/setup.cfg b/setup.cfg index e7b2bceb..df6c5ef8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,7 +8,7 @@ ignore = [metadata] requires-dist = - clint + tqdm requests >= 2.5.0 requests-toolbelt >= 0.5.1 pkginfo >= 1.0 diff --git a/setup.py b/setup.py index a0dbefaa..b41d330e 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ install_requires = [ - "clint", + "tqdm >= 4.11", "pkginfo >= 1.0", "requests >= 2.5.0", "requests-toolbelt >= 0.5.1", diff --git a/twine/cli.py b/twine/cli.py index 1d482905..68f568c4 100644 --- a/twine/cli.py +++ b/twine/cli.py @@ -18,7 +18,7 @@ import pkg_resources import setuptools -import clint +import tqdm import requests import requests_toolbelt import pkginfo @@ -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__), ] diff --git a/twine/repository.py b/twine/repository.py index 43b0b3a8..83678f49 100644 --- a/twine/repository.py +++ b/twine/repository.py @@ -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 tqdm import requests from requests import adapters @@ -33,6 +33,15 @@ OLD_WAREHOUSE = 'https://upload.pypi.io/' +class ProgressBar(tqdm): + + def update_to(self, n): + """ + identical to update, except `n` should be current value and not delta. + """ + self.update(n - self.n) + + class Repository(object): def __init__(self, repository_url, username, password): self.url = repository_url @@ -121,18 +130,18 @@ def _upload(self, package): (package.basefilename, fp, "application/octet-stream"), )) encoder = MultipartEncoder(data_to_send) - bar = ProgressBar(expected_size=encoder.len, filled_char='=') - monitor = MultipartEncoderMonitor( - encoder, lambda monitor: bar.show(monitor.bytes_read) - ) - - resp = self.session.post( - self.url, - data=monitor, - allow_redirects=False, - headers={'Content-Type': monitor.content_type}, - ) - bar.done() + with ProgressBar(total=encoder.len, unit='bytes', + unit_scale=True, leave=False) as bar: + monitor = MultipartEncoderMonitor( + encoder, lambda monitor: bar.update_to(monitor.bytes_read) + ) + + resp = self.session.post( + self.url, + data=monitor, + allow_redirects=False, + headers={'Content-Type': monitor.content_type}, + ) return resp