-
Notifications
You must be signed in to change notification settings - Fork 308
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
Conversation
twine/repository.py
Outdated
@@ -121,9 +121,14 @@ 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) | |||
def update_progressbar(monitor, _cache=[0]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This relies on a little Python quirk that isn't as intuitive. Thoughts on factoring this out into it's own object and then passing a method of that object to MultipartEncoderMonitor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use a variable that lives at the same scope as the function instead of relying on this. I agree with @SethMichaelLarson that this isn't going to be easy to maintain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a custom subclass of tqdm
with a update_to
method.
setup.py
Outdated
@@ -19,7 +19,7 @@ | |||
|
|||
|
|||
install_requires = [ | |||
"clint", | |||
"tqdm", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a lower limit here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
twine/repository.py
Outdated
@@ -121,9 +121,14 @@ 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) | |||
def update_progressbar(monitor, _cache=[0]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use a variable that lives at the same scope as the function instead of relying on this. I agree with @SethMichaelLarson that this isn't going to be easy to maintain.
setup.cfg
Outdated
@@ -8,7 +8,7 @@ ignore = | |||
|
|||
[metadata] | |||
requires-dist = | |||
clint | |||
tqdm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you have this match the version in install_requires
. I'd really rather not use newer features of very recent versions of setuptools, e.g., ~=
. Can we just use >=
, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to match setup.py
. When people install from a wheel, we want the requirements to match those that they see when installing from an sdist.
twine/repository.py
Outdated
""" | ||
identical to update, except `n` should be current value and not delta. | ||
""" | ||
self.update(n-self.n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm disappointed Flake8 didn't catch this, but can you add spaces around -
?
Done and done. I did not realized that |
No worries. All I know is that even last year, setuptools didn't support it as well as it could. Plus setuptools is one of those things people don't ever consider upgrading unless they run into issues, so there's such a wide swath of versions that we need to avoid using features that are too new. |
There are still some Flake8 warnings that need cleaning up. https://travis-ci.org/pypa/twine/jobs/227188445#L201 You can find them locally with |
pep8ified. |
@@ -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 |
There was a problem hiding this comment.
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
twine/repository.py
Outdated
@@ -132,7 +142,7 @@ def _upload(self, package): | |||
allow_redirects=False, | |||
headers={'Content-Type': monitor.content_type}, | |||
) | |||
bar.done() | |||
bar.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can tqdm.tqdm
be used as a context manager? If so it would be nice to use it like one so that .close()
is always called, even on exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not it might be worth it to do something like this:
bar = ProgressBar(total=encoder.len, unit='bytes', unit_scale=True, leave=False)
try:
# Setup monitor and response here.
finally:
bar.close()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://pypi.python.org/pypi/tqdm#manual leads me to believe that in fact tqdm
can be used as a context manager.
Personally, I'd rather this look like it does except that we do:
with bar:
resp = self.session.post(
# ...
)
Because I'd rather keep the scope of the context-manager small.
setup.cfg
Outdated
@@ -8,7 +8,7 @@ ignore = | |||
|
|||
[metadata] | |||
requires-dist = | |||
clint | |||
tqdm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to match setup.py
. When people install from a wheel, we want the requirements to match those that they see when installing from an sdist.
twine/repository.py
Outdated
@@ -132,7 +142,7 @@ def _upload(self, package): | |||
allow_redirects=False, | |||
headers={'Content-Type': monitor.content_type}, | |||
) | |||
bar.done() | |||
bar.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://pypi.python.org/pypi/tqdm#manual leads me to believe that in fact tqdm
can be used as a context manager.
Personally, I'd rather this look like it does except that we do:
with bar:
resp = self.session.post(
# ...
)
Because I'd rather keep the scope of the context-manager small.
@Carreau for what it's worth, if this is more work than you'd like to complete, let me know and I'll add the final polishing touches for you. |
18ce611
to
42e55e0
Compare
Closes pypa#241 – As clint as some indirect Python 2 dependency and tqdm has not.
No it's ok, thanks for the proposal ! Now contexmanagerified, and setup.cfg fixed. |
Thanks @Carreau!! 🍰 |
Class-based, inspired by [twine#242](pypa/twine#242), [here](pypa/twine@42e55e06).
Closes #241 – As clint as some indirect Python 2 dependency and tqdm has
not.