From f3b74929bd8e44ba817cd4237eb6e40a9d10b6bf 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 | 15 +++++++++++---- 4 files changed, 15 insertions(+), 8 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..ee7c987e 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 @@ -32,6 +32,13 @@ WAREHOUSE = 'https://upload.pypi.org/' 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): @@ -121,9 +128,9 @@ 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) monitor = MultipartEncoderMonitor( - encoder, lambda monitor: bar.show(monitor.bytes_read) + encoder, lambda monitor: bar.update_to(monitor.bytes_read) ) resp = self.session.post( @@ -132,7 +139,7 @@ def _upload(self, package): allow_redirects=False, headers={'Content-Type': monitor.content_type}, ) - bar.done() + bar.close() return resp