Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace clint by tqdm for progressbar #242

Merged
merged 1 commit into from
May 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 >= 4.11
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this has no effect. Should be:

from tqdm import 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