From 9b450603ad75ddad2625920c3eb7c22c676f992e Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 2 Oct 2019 15:48:44 +0100 Subject: [PATCH 01/17] add repology badge --- .meta/.readme.rst | 10 ++++++++++ README.rst | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/.meta/.readme.rst b/.meta/.readme.rst index a6768b71c..7061df8f4 100644 --- a/.meta/.readme.rst +++ b/.meta/.readme.rst @@ -116,6 +116,16 @@ Latest Docker release docker pull tqdm/tqdm docker run -i --rm tqdm/tqdm --help +Other +~~~~~ + +There are other (unofficial) places where ``tqdm`` may be downloaded, particularly for CLI use: + +|Repology| + +.. |Repology| image:: https://repology.org/badge/tiny-repos/python:tqdm.svg + :target: https://repology.org/project/python:tqdm/versions + Changelog --------- diff --git a/README.rst b/README.rst index 534475943..31b31c571 100644 --- a/README.rst +++ b/README.rst @@ -116,6 +116,16 @@ Latest Docker release docker pull tqdm/tqdm docker run -i --rm tqdm/tqdm --help +Other +~~~~~ + +There are other (unofficial) places where ``tqdm`` may be downloaded, particularly for CLI use: + +|Repology| + +.. |Repology| image:: https://repology.org/badge/tiny-repos/python:tqdm.svg + :target: https://repology.org/project/python:tqdm/versions + Changelog --------- From 1b1ec3e3abc798b6d4a01426657acc89d01137f6 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 2 Oct 2019 23:47:53 +0100 Subject: [PATCH 02/17] remove broken funding link --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 44774f14e..ccd8f44ff 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,2 @@ -github: casperdcl +# github: casperdcl custom: https://caspersci.uk.to/donate From a6c4ce4ee08e72fd025ccdd278745bc722086408 Mon Sep 17 00:00:00 2001 From: RedBug312 Date: Fri, 14 Jul 2017 23:17:54 +0800 Subject: [PATCH 03/17] fix print_status when using widechars in desc --- tqdm/std.py | 6 +++--- tqdm/utils.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tqdm/std.py b/tqdm/std.py index 8c73c8f0f..56d0628d7 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -12,7 +12,7 @@ from __future__ import division # compatibility functions and utilities from .utils import _supports_unicode, _environ_cols_wrapper, _range, _unich, \ - _term_move_up, _unicode, WeakSet, _basestring, _OrderedDict, \ + _term_move_up, _unicode, WeakSet, _basestring, _OrderedDict, _text_width, \ Comparable, RE_ANSI, _is_ascii, SimpleTextIOWrapper, FormatReplace from ._monitor import TMonitor # native libraries @@ -300,7 +300,7 @@ def fp_write(s): last_len = [0] def print_status(s): - len_s = len(s) + len_s = _text_width(s) fp_write('\r' + s + (' ' * max(last_len[0] - len_s, 0))) last_len[0] = len_s @@ -474,7 +474,7 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, # Formatting progress bar space available for bar's display full_bar = Bar( frac, - max(1, ncols - len(RE_ANSI.sub('', nobar))) if ncols else 10, + max(1, ncols - _text_width(RE_ANSI.sub('', nobar))) if ncols else 10, charset=Bar.ASCII if ascii is True else ascii or Bar.UTF) if not _is_ascii(full_bar.charset) and _is_ascii(bar_format): bar_format = _unicode(bar_format) diff --git a/tqdm/utils.py b/tqdm/utils.py index 6ccd57383..cb534edad 100644 --- a/tqdm/utils.py +++ b/tqdm/utils.py @@ -283,3 +283,16 @@ def _environ_cols_linux(fp): # pragma: no cover def _term_move_up(): # pragma: no cover return '' if (os.name == 'nt') and (colorama is None) else '\x1b[A' + + +def _text_width(s): # pragma: no cover + try: + from unicodedata import east_asian_width + except ImportError: + return len(s) + else: + try: + return len(s) + sum(east_asian_width(ch) in 'FW' for ch in s) + except UnicodeDecodeError: # Py2 + s = s.decode('utf-8') + return len(s) + sum(east_asian_width(ch) in 'FW' for ch in s) From 825f7dc7ea4f101f324619ddcc09276455166093 Mon Sep 17 00:00:00 2001 From: RedBug312 Date: Sun, 16 Jul 2017 13:18:06 +0800 Subject: [PATCH 04/17] except TypeError instead of UnicodeDecodeError --- tqdm/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tqdm/utils.py b/tqdm/utils.py index cb534edad..ee8a8769a 100644 --- a/tqdm/utils.py +++ b/tqdm/utils.py @@ -293,6 +293,6 @@ def _text_width(s): # pragma: no cover else: try: return len(s) + sum(east_asian_width(ch) in 'FW' for ch in s) - except UnicodeDecodeError: # Py2 + except TypeError: # Py2 s = s.decode('utf-8') return len(s) + sum(east_asian_width(ch) in 'FW' for ch in s) From 124d72a4e341cc62ce7450d577073a9ba08a1a6d Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Fri, 14 Jul 2017 23:17:54 +0800 Subject: [PATCH 05/17] Recognize wide characters in description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … by using unicodedata.east_asian_width. Co-authored-by: RedBug312 --- tqdm/std.py | 2 +- tqdm/utils.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tqdm/std.py b/tqdm/std.py index 56d0628d7..543362306 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -490,7 +490,7 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, return nobar full_bar = Bar( 0, - max(1, ncols - len(RE_ANSI.sub('', nobar))) if ncols else 10, + max(1, ncols - _text_width(RE_ANSI.sub('', nobar))) if ncols else 10, charset=Bar.BLANK) return bar_format.format(bar=full_bar, **format_dict) else: diff --git a/tqdm/utils.py b/tqdm/utils.py index ee8a8769a..17b6aba6f 100644 --- a/tqdm/utils.py +++ b/tqdm/utils.py @@ -286,6 +286,7 @@ def _term_move_up(): # pragma: no cover def _text_width(s): # pragma: no cover + # TODO consider using wcswidth third-party package for 0-width characters try: from unicodedata import east_asian_width except ImportError: From 261ddddf455ed81c236b6ed2575b518c796b7d9d Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Sun, 8 Sep 2019 01:34:20 +0200 Subject: [PATCH 06/17] Add tests for wide characters in description Making tests work with Python 2 was annoying, so I just skip them there. It'll be EOLd in a few months anyway. --- tqdm/tests/tests_tqdm.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tqdm/tests/tests_tqdm.py b/tqdm/tests/tests_tqdm.py index dcd21b84e..2ce4620a9 100644 --- a/tqdm/tests/tests_tqdm.py +++ b/tqdm/tests/tests_tqdm.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Advice: use repr(our_file.read()) to print the full output of tqdm # (else '\r' will replace the previous lines and you'll see only the latest. @@ -277,6 +278,12 @@ def test_format_meter(): assert format_meter(20, 100, 12, ncols=14, rate=8.1, bar_format=r'{l_bar}{bar}|{n_fmt}/{total_fmt}') == \ " 20%|" + unich(0x258d) + " |20/100" + # Check wide characters + if sys.version_info >= (3,): + assert format_meter(0, 1000, 13, ncols=68, prefix='fullwidth: ') == \ + "fullwidth: 0%| | 0/1000 [00:13 Date: Thu, 10 Oct 2019 17:46:42 +0100 Subject: [PATCH 07/17] attempt to fix perf - fixes #803 - closes #410 - closes #805 --- tqdm/utils.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tqdm/utils.py b/tqdm/utils.py index 17b6aba6f..925752d24 100644 --- a/tqdm/utils.py +++ b/tqdm/utils.py @@ -285,15 +285,11 @@ def _term_move_up(): # pragma: no cover return '' if (os.name == 'nt') and (colorama is None) else '\x1b[A' -def _text_width(s): # pragma: no cover +try: # TODO consider using wcswidth third-party package for 0-width characters - try: - from unicodedata import east_asian_width - except ImportError: - return len(s) - else: - try: - return len(s) + sum(east_asian_width(ch) in 'FW' for ch in s) - except TypeError: # Py2 - s = s.decode('utf-8') - return len(s) + sum(east_asian_width(ch) in 'FW' for ch in s) + from unicodedata import east_asian_width +except ImportError: + _text_width = len +else: + def _text_width(s): + return len(s) + sum(east_asian_width(ch) in 'FW' for ch in _unicode(s)) From b3d77399fd6ce069ac7a01ba81bae4a6c4d60648 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Fri, 11 Oct 2019 13:05:26 +0100 Subject: [PATCH 08/17] unicode width speed improvement, clear fix --- tqdm/std.py | 2 +- tqdm/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tqdm/std.py b/tqdm/std.py index 543362306..b4923312c 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -300,7 +300,7 @@ def fp_write(s): last_len = [0] def print_status(s): - len_s = _text_width(s) + len_s = len(s) fp_write('\r' + s + (' ' * max(last_len[0] - len_s, 0))) last_len[0] = len_s diff --git a/tqdm/utils.py b/tqdm/utils.py index 925752d24..724b144a5 100644 --- a/tqdm/utils.py +++ b/tqdm/utils.py @@ -292,4 +292,4 @@ def _term_move_up(): # pragma: no cover _text_width = len else: def _text_width(s): - return len(s) + sum(east_asian_width(ch) in 'FW' for ch in _unicode(s)) + return sum(2 if east_asian_width(ch) in 'FW' else 1 for ch in _unicode(s)) From 1db4511ec464d3976e4775c99c77f72a42c1b90c Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Fri, 11 Oct 2019 16:59:31 +0100 Subject: [PATCH 09/17] add CII Best Practices badge --- .meta/.readme.rst | 4 +++- README.rst | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.meta/.readme.rst b/.meta/.readme.rst index 7061df8f4..40ed99120 100644 --- a/.meta/.readme.rst +++ b/.meta/.readme.rst @@ -847,7 +847,7 @@ The monitor thread may be disabled application-wide by setting Contributions ------------- -|GitHub-Commits| |GitHub-Issues| |GitHub-PRs| |OpenHub-Status| |GitHub-Contributions| +|GitHub-Commits| |GitHub-Issues| |GitHub-PRs| |OpenHub-Status| |GitHub-Contributions| |CII Best Practices| All source code is hosted on `GitHub `__. Contributions are welcome. @@ -906,6 +906,8 @@ Citation information: |DOI| (publication), |DOI-code| (code) :target: https://codecov.io/gh/tqdm/tqdm .. |Codacy-Grade| image:: https://api.codacy.com/project/badge/Grade/3f965571598f44549c7818f29cdcf177 :target: https://www.codacy.com/app/tqdm/tqdm/dashboard +.. |CII Best Practices| image:: https://bestpractices.coreinfrastructure.org/projects/3264/badge + :target: https://bestpractices.coreinfrastructure.org/projects/3264 .. |GitHub-Status| image:: https://img.shields.io/github/tag/tqdm/tqdm.svg?maxAge=86400&logo=github&logoColor=white :target: https://github.com/tqdm/tqdm/releases .. |GitHub-Forks| image:: https://img.shields.io/github/forks/tqdm/tqdm.svg?logo=github&logoColor=white diff --git a/README.rst b/README.rst index 31b31c571..6a103192c 100644 --- a/README.rst +++ b/README.rst @@ -1013,7 +1013,7 @@ The monitor thread may be disabled application-wide by setting Contributions ------------- -|GitHub-Commits| |GitHub-Issues| |GitHub-PRs| |OpenHub-Status| |GitHub-Contributions| +|GitHub-Commits| |GitHub-Issues| |GitHub-PRs| |OpenHub-Status| |GitHub-Contributions| |CII Best Practices| All source code is hosted on `GitHub `__. Contributions are welcome. @@ -1072,6 +1072,8 @@ Citation information: |DOI| (publication), |DOI-code| (code) :target: https://codecov.io/gh/tqdm/tqdm .. |Codacy-Grade| image:: https://api.codacy.com/project/badge/Grade/3f965571598f44549c7818f29cdcf177 :target: https://www.codacy.com/app/tqdm/tqdm/dashboard +.. |CII Best Practices| image:: https://bestpractices.coreinfrastructure.org/projects/3264/badge + :target: https://bestpractices.coreinfrastructure.org/projects/3264 .. |GitHub-Status| image:: https://img.shields.io/github/tag/tqdm/tqdm.svg?maxAge=86400&logo=github&logoColor=white :target: https://github.com/tqdm/tqdm/releases .. |GitHub-Forks| image:: https://img.shields.io/github/forks/tqdm/tqdm.svg?logo=github&logoColor=white From fa2e30fb7f83f8b82eccbc01980eed5d0ceaff53 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 2 Oct 2019 23:44:07 -0700 Subject: [PATCH 10/17] MNT: set stack level on warnings This makes it much easier to find where in client code needs to be fixed. --- tqdm/_main.py | 2 +- tqdm/_tqdm_gui.py | 2 +- tqdm/_tqdm_notebook.py | 2 +- tqdm/_utils.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tqdm/_main.py b/tqdm/_main.py index ec5cd7a0e..07b6730b1 100644 --- a/tqdm/_main.py +++ b/tqdm/_main.py @@ -4,4 +4,4 @@ from warnings import warn warn("This function will be removed in tqdm==5.0.0\n" "Please use `tqdm.cli.*` instead of `tqdm._main.*`", - TqdmDeprecationWarning) + TqdmDeprecationWarning, stacklevel=2) diff --git a/tqdm/_tqdm_gui.py b/tqdm/_tqdm_gui.py index f31a2483b..541f104fb 100644 --- a/tqdm/_tqdm_gui.py +++ b/tqdm/_tqdm_gui.py @@ -4,4 +4,4 @@ from warnings import warn warn("This function will be removed in tqdm==5.0.0\n" "Please use `tqdm.gui.*` instead of `tqdm._tqdm_gui.*`", - TqdmDeprecationWarning) + TqdmDeprecationWarning, stacklevel=2) diff --git a/tqdm/_tqdm_notebook.py b/tqdm/_tqdm_notebook.py index d424112fb..dde999817 100644 --- a/tqdm/_tqdm_notebook.py +++ b/tqdm/_tqdm_notebook.py @@ -4,4 +4,4 @@ from warnings import warn warn("This function will be removed in tqdm==5.0.0\n" "Please use `tqdm.notebook.*` instead of `tqdm._tqdm_notebook.*`", - TqdmDeprecationWarning) + TqdmDeprecationWarning, stacklevel=2) diff --git a/tqdm/_utils.py b/tqdm/_utils.py index 1c01ad055..31f78ed70 100644 --- a/tqdm/_utils.py +++ b/tqdm/_utils.py @@ -3,4 +3,4 @@ from warnings import warn warn("This function will be removed in tqdm==5.0.0\n" "Please use `tqdm.utils.*` instead of `tqdm._utils.*`", - TqdmDeprecationWarning) + TqdmDeprecationWarning, stacklevel=2) From 6e50fa2719117525f7172569792e0d734d7198d8 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sat, 12 Oct 2019 22:49:45 +0100 Subject: [PATCH 11/17] add stacklevel=2 to more warnings --- tqdm/__init__.py | 4 ++-- tqdm/_monitor.py | 2 +- tqdm/_tqdm.py | 2 +- tqdm/autonotebook.py | 2 +- tqdm/gui.py | 2 +- tqdm/std.py | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tqdm/__init__.py b/tqdm/__init__.py index 9e682f02d..670d6457e 100644 --- a/tqdm/__init__.py +++ b/tqdm/__init__.py @@ -24,7 +24,7 @@ def tqdm_notebook(*args, **kwargs): # pragma: no cover from warnings import warn warn("This function will be removed in tqdm==5.0.0\n" "Please use `tqdm.notebook.tqdm` instead of `tqdm.tqdm_notebook`", - TqdmDeprecationWarning) + TqdmDeprecationWarning, stacklevel=2) return _tqdm_notebook(*args, **kwargs) @@ -36,5 +36,5 @@ def tnrange(*args, **kwargs): # pragma: no cover from .notebook import trange as _tnrange from warnings import warn warn("Please use `tqdm.notebook.trange` instead of `tqdm.tnrange`", - TqdmDeprecationWarning) + TqdmDeprecationWarning, stacklevel=2) return _tnrange(*args, **kwargs) diff --git a/tqdm/_monitor.py b/tqdm/_monitor.py index 17c5a1abd..e1e257069 100644 --- a/tqdm/_monitor.py +++ b/tqdm/_monitor.py @@ -93,7 +93,7 @@ def run(self): if instances != self.get_instances(): # pragma: nocover warn("Set changed size during iteration" + " (see https://github.com/tqdm/tqdm/issues/481)", - TqdmSynchronisationWarning) + TqdmSynchronisationWarning, stacklevel=2) def report(self): return not self.was_killed.is_set() diff --git a/tqdm/_tqdm.py b/tqdm/_tqdm.py index 57c3d75bf..694318ee7 100644 --- a/tqdm/_tqdm.py +++ b/tqdm/_tqdm.py @@ -4,4 +4,4 @@ from warnings import warn warn("This function will be removed in tqdm==5.0.0\n" "Please use `tqdm.std.*` instead of `tqdm._tqdm.*`", - TqdmDeprecationWarning) + TqdmDeprecationWarning, stacklevel=2) diff --git a/tqdm/autonotebook.py b/tqdm/autonotebook.py index bafe0e801..0bcd42a13 100644 --- a/tqdm/autonotebook.py +++ b/tqdm/autonotebook.py @@ -14,5 +14,5 @@ from warnings import warn warn("Using `tqdm.autonotebook.tqdm` in notebook mode." " Use `tqdm.tqdm` instead to force console mode" - " (e.g. in jupyter console)", TqdmExperimentalWarning) + " (e.g. in jupyter console)", TqdmExperimentalWarning, stacklevel=2) __all__ = ["tqdm", "trange"] diff --git a/tqdm/gui.py b/tqdm/gui.py index dbac9d676..35f5c5e55 100644 --- a/tqdm/gui.py +++ b/tqdm/gui.py @@ -41,7 +41,7 @@ def __init__(self, *args, **kwargs): if self.disable or not kwargs['gui']: return - warn('GUI is experimental/alpha', TqdmExperimentalWarning) + warn('GUI is experimental/alpha', TqdmExperimentalWarning, stacklevel=2) self.mpl = mpl self.plt = plt self.sp = None diff --git a/tqdm/std.py b/tqdm/std.py index b4923312c..7e7b593dd 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -516,7 +516,7 @@ def __new__(cls, *args, **kwargs): except Exception as e: # pragma: nocover warn("tqdm:disabling monitor support" " (monitor_interval = 0) due to:\n" + str(e), - TqdmMonitorWarning) + TqdmMonitorWarning, stacklevel=2) cls.monitor_interval = 0 # Return the instance return instance @@ -1033,7 +1033,7 @@ def __exit__(self, exc_type, exc_value, traceback): # maybe eager thread cleanup upon external error if (exc_type, exc_value, traceback) == (None, None, None): raise - warn("AttributeError ignored", TqdmWarning) + warn("AttributeError ignored", TqdmWarning, stacklevel=2) def __del__(self): self.close() From 9baa46e84fc910e4cf7d070de6a00b4c3342506e Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 23 Oct 2019 00:46:27 +0100 Subject: [PATCH 12/17] fix example/tqdm_wget unknown total - fixes #826 --- examples/tqdm_wget.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/tqdm_wget.py b/examples/tqdm_wget.py index e49039b3c..7e9f6c53a 100644 --- a/examples/tqdm_wget.py +++ b/examples/tqdm_wget.py @@ -48,9 +48,10 @@ def update_to(b=1, bsize=1, tsize=None): bsize : int, optional Size of each block (in tqdm units) [default: 1]. tsize : int, optional - Total size (in tqdm units). If [default: None] remains unchanged. + Total size (in tqdm units). If [default: None] or -1, + remains unchanged. """ - if tsize is not None: + if tsize not in (None, -1): t.total = tsize t.update((b - last_b[0]) * bsize) last_b[0] = b From 5f0eb91ac1ebff8f73195f2d2026a837f225dc14 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sat, 26 Oct 2019 00:27:32 +0100 Subject: [PATCH 13/17] Revert "remove broken funding link" This reverts commit 1b1ec3e3abc798b6d4a01426657acc89d01137f6. --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index ccd8f44ff..44774f14e 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,2 @@ -# github: casperdcl +github: casperdcl custom: https://caspersci.uk.to/donate From 84102ab0ced2d01b6b3bb1d6224eee8c08019578 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 29 Oct 2019 11:32:00 +0000 Subject: [PATCH 14/17] update issue/pr templates would fix things like #830 --- .github/ISSUE_TEMPLATE.md | 6 ++++++ .github/PULL_REQUEST_TEMPLATE.md | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 1a7be1879..008292495 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,3 +1,8 @@ +- [ ] I have marked all applicable categories: + + [ ] exception-raising bug + + [ ] visual output bug + + [ ] documentation request (i.e. "X is missing from the documentation." If instead I want to ask "how to use X?" I understand [StackOverflow#tqdm] is more appropriate) + + [ ] new feature request - [ ] I have visited the [source website], and in particular read the [known issues] - [ ] I have searched through the [issue tracker] for duplicates @@ -11,3 +16,4 @@ [source website]: https://github.com/tqdm/tqdm/ [known issues]: https://github.com/tqdm/tqdm/#faq-and-known-issues [issue tracker]: https://github.com/tqdm/tqdm/issues?q= + [StackOverflow#tqdm]: https://stackoverflow.com/questions/tagged/tqdm diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 9ab758cbf..4c7471d8b 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,3 +1,12 @@ +- [ ] I have marked all applicable categories: + + [ ] exception-raising fix + + [ ] visual output fix + + [ ] documentation modification + + [ ] new feature +- [ ] If applicable, I have mentioned the relevant/related issue(s) + +Less important but also useful: + - [ ] I have visited the [source website], and in particular read the [known issues] - [ ] I have searched through the [issue tracker] for duplicates @@ -7,7 +16,6 @@ import tqdm, sys print(tqdm.__version__, sys.version, sys.platform) ``` -- [ ] If applicable, I have mentioned the relevant/related issue(s) [source website]: https://github.com/tqdm/tqdm/ [known issues]: https://github.com/tqdm/tqdm/#faq-and-known-issues From 59f457a8ceb64f6aaf02113c035516c2caa181d4 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 29 Oct 2019 12:27:29 +0000 Subject: [PATCH 15/17] potential future pandas fix - related to #824 --- tqdm/std.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tqdm/std.py b/tqdm/std.py index 7e7b593dd..ba7ef2134 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -645,7 +645,10 @@ def pandas(tclass, *targs, **tkwargs): """ from pandas.core.frame import DataFrame from pandas.core.series import Series - from pandas import Panel + try: + from pandas import Panel + except Import Error: # TODO: pandas>0.25.2 + Panel = None try: # pandas>=0.18.0 from pandas.core.window import _Rolling_and_Expanding except ImportError: # pragma: no cover @@ -752,7 +755,8 @@ def wrapper(*args, **kwargs): DataFrameGroupBy.progress_apply = inner_generator() DataFrame.progress_applymap = inner_generator('applymap') - Panel.progress_apply = inner_generator() + if Panel is not None: + Panel.progress_apply = inner_generator() if PanelGroupBy is not None: PanelGroupBy.progress_apply = inner_generator() From b3589f6736e037eb160e0329814006447eaf347c Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 31 Oct 2019 15:38:21 +0000 Subject: [PATCH 16/17] silly syntax error fix --- tqdm/std.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tqdm/std.py b/tqdm/std.py index ba7ef2134..36e7f8994 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -647,7 +647,7 @@ def pandas(tclass, *targs, **tkwargs): from pandas.core.series import Series try: from pandas import Panel - except Import Error: # TODO: pandas>0.25.2 + except ImportError: # TODO: pandas>0.25.2 Panel = None try: # pandas>=0.18.0 from pandas.core.window import _Rolling_and_Expanding From b17b5940d8b03786bb57f2fba12cd2508a3c5a94 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 31 Oct 2019 16:31:18 +0000 Subject: [PATCH 17/17] update parallel example - fixes #407 --- .meta/.readme.rst | 10 +++++----- README.rst | 10 +++++----- examples/parallel_bars.py | 33 ++++++++++++++++----------------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/.meta/.readme.rst b/.meta/.readme.rst index 40ed99120..65690c75d 100644 --- a/.meta/.readme.rst +++ b/.meta/.readme.rst @@ -284,7 +284,7 @@ of a neat one-line progress bar. ``tqdm(zip(a, b))`` should be replaced with ``zip(tqdm(a), b)`` or even ``zip(tqdm(a), tqdm(b))``. - `Hanging pipes in python2 `__: - when using ``tqdm`` on the CLI, you may need to use python 3.5+ for correct + when using ``tqdm`` on the CLI, you may need to use Python 3.5+ for correct buffering. If you come across any other difficulties, browse and file |GitHub-Issues|. @@ -488,7 +488,8 @@ available to keep nested bars on their respective lines. For manual control over positioning (e.g. for multi-processing use), you may specify ``position=n`` where ``n=0`` for the outermost bar, -``n=1`` for the next, and so on: +``n=1`` for the next, and so on. However, it's best to check if `tqdm` can work +without manual `position` first. .. code:: python @@ -507,11 +508,10 @@ you may specify ``position=n`` where ``n=0`` for the outermost bar, if __name__ == '__main__': freeze_support() # for Windows support - p = Pool(len(L), initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),)) + p = Pool(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),)) p.map(progresser, L) -Note that in python 3, threads do not require manual positioning, -and ``tqdm.write`` is safe to use: +Note that in Python 3, ``tqdm.write`` is thread-safe: .. code:: python diff --git a/README.rst b/README.rst index 6a103192c..22fbcb2df 100644 --- a/README.rst +++ b/README.rst @@ -284,7 +284,7 @@ of a neat one-line progress bar. ``tqdm(zip(a, b))`` should be replaced with ``zip(tqdm(a), b)`` or even ``zip(tqdm(a), tqdm(b))``. - `Hanging pipes in python2 `__: - when using ``tqdm`` on the CLI, you may need to use python 3.5+ for correct + when using ``tqdm`` on the CLI, you may need to use Python 3.5+ for correct buffering. If you come across any other difficulties, browse and file |GitHub-Issues|. @@ -654,7 +654,8 @@ available to keep nested bars on their respective lines. For manual control over positioning (e.g. for multi-processing use), you may specify ``position=n`` where ``n=0`` for the outermost bar, -``n=1`` for the next, and so on: +``n=1`` for the next, and so on. However, it's best to check if `tqdm` can work +without manual `position` first. .. code:: python @@ -673,11 +674,10 @@ you may specify ``position=n`` where ``n=0`` for the outermost bar, if __name__ == '__main__': freeze_support() # for Windows support - p = Pool(len(L), initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),)) + p = Pool(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),)) p.map(progresser, L) -Note that in python 3, threads do not require manual positioning, -and ``tqdm.write`` is safe to use: +Note that in Python 3, ``tqdm.write`` is thread-safe: .. code:: python diff --git a/examples/parallel_bars.py b/examples/parallel_bars.py index b62020a16..e49a2775f 100644 --- a/examples/parallel_bars.py +++ b/examples/parallel_bars.py @@ -1,38 +1,41 @@ from __future__ import print_function from time import sleep from tqdm import tqdm, trange +from random import random from multiprocessing import Pool, freeze_support from concurrent.futures import ThreadPoolExecutor from functools import partial import sys +NUM_SUBITERS = 9 +PY2 = sys.version_info[:1] <= (2,) -L = list(range(9))[::-1] - -def progresser(n, auto_position=False): - interval = 0.001 / (len(L) - n + 2) +def progresser(n, auto_position=True, write_safe=False): + interval = random() * 0.002 / (NUM_SUBITERS - n + 2) total = 5000 text = "#{}, est. {:<04.2}s".format(n, interval * total) for _ in tqdm(range(total), desc=text, position=None if auto_position else n): sleep(interval) # NB: may not clear instances with higher `position` upon completion # since this worker may not know about other bars #796 - if auto_position: + if write_safe: # we think we know about other bars (currently only py3 threading) if n == 6: tqdm.write("n == 6 completed") -if sys.version_info[:1] > (2,): - progresser_thread = partial(progresser, auto_position=True) -else: - progresser_thread = progresser - if __name__ == '__main__': freeze_support() # for Windows support + L = list(range(NUM_SUBITERS))[::-1] + + print("Manual nesting") + for i in trange(16, desc="1"): + for _ in trange(16, desc="2 @ %d" % i, leave=i % 2): + sleep(0.01) + print("Multi-processing") - p = Pool(len(L), initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),)) + p = Pool(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),)) p.map(progresser, L) # unfortunately need ncols @@ -41,10 +44,6 @@ def progresser(n, auto_position=False): ncols = t.ncols or 80 print(("{msg:<{ncols}}").format(msg="Multi-threading", ncols=ncols)) - with ThreadPoolExecutor(4) as p: + with ThreadPoolExecutor() as p: + progresser_thread = partial(progresser, write_safe=not PY2) p.map(progresser_thread, L) - - print("Manual nesting") - for i in trange(16, desc="1"): - for _ in trange(16, desc="2 @ %d" % i, leave=i % 2): - sleep(0.01)