Replace clint by tqdm for progressbar#242
Conversation
| 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.
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.
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.
I created a custom subclass of tqdm with a update_to method.
|
|
||
| install_requires = [ | ||
| "clint", | ||
| "tqdm", |
There was a problem hiding this comment.
Please add a lower limit here.
| 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.
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.
| [metadata] | ||
| requires-dist = | ||
| clint | ||
| tqdm |
There was a problem hiding this comment.
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.
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.
| """ | ||
| identical to update, except `n` should be current value and not delta. | ||
| """ | ||
| self.update(n-self.n) |
There was a problem hiding this comment.
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. |
| 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.
Pretty sure this has no effect. Should be:
from tqdm import tqdm| headers={'Content-Type': monitor.content_type}, | ||
| ) | ||
| bar.done() | ||
| bar.close() |
There was a problem hiding this comment.
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.
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.
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.
| [metadata] | ||
| requires-dist = | ||
| clint | ||
| tqdm |
There was a problem hiding this comment.
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.
| headers={'Content-Type': monitor.content_type}, | ||
| ) | ||
| bar.done() | ||
| bar.close() |
There was a problem hiding this comment.
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).
Class-based, inspired by [twine#242](pypa/twine#242), [here](pypa/twine@42e55e06).
Class-based, inspired by [twine#242](pypa/twine#242), [here](pypa/twine@42e55e06).
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.