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 May 2, 2017
1 parent 6fa84f5 commit 18ce611
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 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
35 changes: 22 additions & 13 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 @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 18ce611

Please sign in to comment.