Skip to content

Commit

Permalink
Replace clint by tqdm for progressbar
Browse files Browse the repository at this point in the history
Closes #241 – As clint as some indirect Python 2 dependency and tqdm has
not.
  • Loading branch information
Carreau committed Apr 29, 2017
1 parent 6fa84f5 commit f3b7492
Show file tree
Hide file tree
Showing 4 changed files with 15 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 >= 4.11",
"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
15 changes: 11 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 tqdm

import requests
from requests import adapters
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -132,7 +139,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 f3b7492

Please sign in to comment.