diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 44774f14e..0716fb69f 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,3 @@ github: casperdcl custom: https://caspersci.uk.to/donate +tidelift: pypi/tqdm diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index c0e6a70a7..302456a1d 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,8 +1,8 @@ blank_issues_enabled: false contact_links: - - name: "FAQs and Known Issues" + - name: FAQs and Known Issues url: https://github.com/tqdm/tqdm/#faq-and-known-issues - about: "Frequently asked questions and known issues" + about: Frequently asked questions and known issues - name: "StackOverflow#tqdm" url: https://stackoverflow.com/questions/tagged/tqdm about: "Stack Overflow questions tagged #tqdm" diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 000000000..9955d5fb8 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,14 @@ +# Security Policy + +## Supported Versions + +| Version | Supported | +| ----------- | ------------------ | +| >= 4.11.2 | :white_check_mark: | +| < 4.11.2 | :x: | + +## Security contact information + +To report a security vulnerability, please use the +[Tidelift security contact](https://tidelift.com/security). +Tidelift will coordinate the fix and disclosure. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 568df615f..68796c0e7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -131,13 +131,12 @@ sanity-checking. The tqdm repository managers should: -- follow the [Semantic Versioning](https://semver.org/) convention +- follow the [Semantic Versioning](https://semver.org) convention - take care of this (instead of users) to avoid PR conflicts solely due to the version file bumping Note: tools can be used to automate this process, such as -[bumpversion](https://github.com/peritus/bumpversion) or -[python-semanticversion](https://github.com/rbarrois/python-semanticversion/). +[python-semanticversion](https://github.com/rbarrois/python-semanticversion). ## Checking setup.py diff --git a/benchmarks/benchmarks.py b/benchmarks/benchmarks.py index 5698600da..37f5df419 100644 --- a/benchmarks/benchmarks.py +++ b/benchmarks/benchmarks.py @@ -22,7 +22,7 @@ def __init__(self, length): def run(self, cls): pbar = cls(self.iterable) t0 = self.time() - [0 for _ in pbar] + [0 for _ in pbar] # pylint: disable=pointless-statement t1 = self.time() return t1 - t0 diff --git a/examples/7zx.py b/examples/7zx.py index c5bc28b7e..edc5c95a1 100644 --- a/examples/7zx.py +++ b/examples/7zx.py @@ -77,11 +77,11 @@ def main(): unit="B", unit_scale=True) as tall: for fn, fcomp in zips.items(): md, sd = pty.openpty() - ex = subprocess.Popen( + ex = subprocess.Popen( # nosec cmd7zx + [fn], bufsize=1, stdout=md, # subprocess.PIPE, - stderr=subprocess.STDOUT) # nosec + stderr=subprocess.STDOUT) os.close(sd) with io.open(md, mode="rU", buffering=1) as m: with tqdm(total=sum(fcomp.values()), disable=len(zips) < 2, diff --git a/examples/include_no_requirements.py b/examples/include_no_requirements.py index 3682d8845..c51a85cb9 100644 --- a/examples/include_no_requirements.py +++ b/examples/include_no_requirements.py @@ -7,3 +7,5 @@ def tqdm(*args, **kwargs): if args: return args[0] return kwargs.get('iterable', None) + +__all__ = ['tqdm'] diff --git a/tests/tests_main.py b/tests/tests_main.py index aa477e5b5..c02c896bb 100644 --- a/tests/tests_main.py +++ b/tests/tests_main.py @@ -36,9 +36,9 @@ def test_pipes(): """Test command line pipes""" ls_out = subprocess.check_output(['ls']) # nosec ls = subprocess.Popen(['ls'], stdout=subprocess.PIPE) # nosec - res = subprocess.Popen( + res = subprocess.Popen( # nosec [sys.executable, '-c', 'from tqdm.cli import main; main()'], - stdin=ls.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # nosec + stdin=ls.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = res.communicate() assert ls.poll() == 0 @@ -61,7 +61,7 @@ def test_main_import(): sys.argv = ['', '--desc', 'Test CLI import', '--ascii', 'True', '--unit_scale', 'True'] try: - import tqdm.__main__ # NOQA + import tqdm.__main__ # NOQA, pylint: disable=unused-variable finally: sys.stdin, sys.argv = _SYS diff --git a/tests/tests_tqdm.py b/tests/tests_tqdm.py index 56033fef9..8cf006533 100644 --- a/tests/tests_tqdm.py +++ b/tests/tests_tqdm.py @@ -622,6 +622,21 @@ def test_max_interval(): t2.close() +def test_delay(): + """Test delay""" + timer = DiscreteTimer() + with closing(StringIO()) as our_file: + t = tqdm(total=2, file=our_file, leave=True, delay=3) + cpu_timify(t, timer) + timer.sleep(2) + t.update(1) + assert not our_file.getvalue() + timer.sleep(2) + t.update(1) + assert our_file.getvalue() + t.close() + + def test_min_iters(): """Test miniters""" with closing(StringIO()) as our_file: diff --git a/tox.ini b/tox.ini index 99a7c6dad..18f043e71 100644 --- a/tox.ini +++ b/tox.ini @@ -4,17 +4,11 @@ # and then run "tox" from this directory. [tox] -# deprecation warning: py{34} +# deprecation warning: py{27,py2,34,35} envlist=py{27,34,35,36,37,38,39,py2,py3}{,-tf}{,-keras}, perf, setup.py isolated_build=True -[coverage] -commands= - - coveralls - codecov -X pycov -e TOXENV - - codacy report -l Python -r coverage.xml --partial - -[extra] +[core] deps= pytest pytest-cov @@ -24,14 +18,14 @@ deps= coveralls codecov commands= - pytest --cov=tqdm --cov-report=xml --cov-report=term -k "not perf" - {[coverage]commands} -allowlist_externals=codacy + - coveralls + codecov -X pycov -e TOXENV + - codacy report -l Python -r coverage.xml --partial [testenv] -passenv=CI GITHUB_* TOXENV CODECOV_* COVERALLS_* CODACY_* HOME +passenv=TOXENV CI GITHUB_* CODECOV_* COVERALLS_* CODACY_* HOME deps= - {[extra]deps} + {[core]deps} cython matplotlib numpy @@ -39,17 +33,19 @@ deps= keras: keras py{36,37,38,39}: rich tf: tensorflow -commands={[extra]commands} -allowlist_externals={[extra]allowlist_externals} +commands= + pytest --cov=tqdm --cov-report=xml --cov-report=term -k "not perf" + {[core]commands} +allowlist_externals=codacy [testenv:py{27,py2}{,-tf}{,-keras}] commands= pytest --cov=tqdm --cov-report=xml --cov-report=term -k "not perf" -o addopts= -v --tb=short -rxs -W=error --durations=10 - {[coverage]commands} + {[core]commands} # no cython/numpy/pandas [testenv:py{34,py2,py3}] -deps={[extra]deps} +deps={[core]deps} [testenv:perf] deps= diff --git a/tqdm/_utils.py b/tqdm/_utils.py index 5bf54bb8c..2228691e2 100644 --- a/tqdm/_utils.py +++ b/tqdm/_utils.py @@ -1,7 +1,7 @@ from warnings import warn from .std import TqdmDeprecationWarning -from .utils import ( # NOQA +from .utils import ( # NOQA, pylint: disable=unused-import CUR_OS, IS_NIX, IS_WIN, RE_ANSI, Comparable, FormatReplace, SimpleTextIOWrapper, _basestring, _environ_cols_wrapper, _is_ascii, _is_utf, _range, _screen_shape_linux, _screen_shape_tput, _screen_shape_windows, _screen_shape_wrapper, _supports_unicode, diff --git a/tqdm/notebook.py b/tqdm/notebook.py index a1f6f8e1c..1e1431d89 100644 --- a/tqdm/notebook.py +++ b/tqdm/notebook.py @@ -248,9 +248,9 @@ def __init__(self, *args, **kwargs): if not self.disable: self.display() - def __iter__(self, *args, **kwargs): + def __iter__(self): try: - for obj in super(tqdm_notebook, self).__iter__(*args, **kwargs): + for obj in super(tqdm_notebook, self).__iter__(): # return super(tqdm...) will not catch exception yield obj # NB: except ... [ as ...] breaks IPython async KeyboardInterrupt @@ -260,9 +260,9 @@ def __iter__(self, *args, **kwargs): # NB: don't `finally: close()` # since this could be a shared bar which the user will `reset()` - def update(self, *args, **kwargs): + def update(self, n=1): try: - return super(tqdm_notebook, self).update(*args, **kwargs) + return super(tqdm_notebook, self).update(n=n) # NB: except ... [ as ...] breaks IPython async KeyboardInterrupt except: # NOQA # cannot catch KeyboardInterrupt when using manual tqdm @@ -272,8 +272,8 @@ def update(self, *args, **kwargs): # NB: don't `finally: close()` # since this could be a shared bar which the user will `reset()` - def close(self, *args, **kwargs): - super(tqdm_notebook, self).close(*args, **kwargs) + def close(self): + super(tqdm_notebook, self).close() # Try to detect if there was an error or KeyboardInterrupt # in manual mode: if n < total, things probably got wrong if self.total and self.n < self.total: diff --git a/tqdm/std.py b/tqdm/std.py index e73f4ab67..d25ab281d 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -844,7 +844,8 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, ascii=None, disable=False, unit='it', unit_scale=False, dynamic_ncols=False, smoothing=0.3, bar_format=None, initial=0, position=None, postfix=None, unit_divisor=1000, write_bytes=None, - lock_args=None, nrows=None, colour=None, gui=False, **kwargs): + lock_args=None, nrows=None, colour=None, delay=0, gui=False, + **kwargs): """ Parameters ---------- @@ -951,6 +952,8 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, The fallback is 20. colour : str, optional Bar colour (e.g. 'green', '#00ff00'). + delay : float, optional + Don't display until [default: 0] seconds have elapsed. gui : bool, optional WARNING: internal parameter - do not use. Use tqdm.gui.tqdm(...) instead. If set, will attempt to use @@ -1068,6 +1071,7 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, self.unit_divisor = unit_divisor self.initial = initial self.lock_args = lock_args + self.delay = delay self.gui = gui self.dynamic_ncols = dynamic_ncols self.smoothing = smoothing @@ -1099,7 +1103,8 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, if not gui: # Initialize the screen printer self.sp = self.status_printer(self.fp) - self.refresh(lock_args=self.lock_args) + if delay <= 0: + self.refresh(lock_args=self.lock_args) # Init the time counter self.last_print_t = self._time() @@ -1163,6 +1168,7 @@ def __iter__(self): mininterval = self.mininterval last_print_t = self.last_print_t last_print_n = self.last_print_n + min_start_t = self.start_t + self.delay n = self.n time = self._time @@ -1174,8 +1180,9 @@ def __iter__(self): n += 1 if n - last_print_n >= self.miniters: - dt = time() - last_print_t - if dt >= mininterval: + cur_t = time() + dt = cur_t - last_print_t + if dt >= mininterval and cur_t >= min_start_t: self.update(n - last_print_n) last_print_n = self.last_print_n last_print_t = self.last_print_t @@ -1218,8 +1225,9 @@ def update(self, n=1): # check counter first to reduce calls to time() if self.n - self.last_print_n >= self.miniters: - dt = self._time() - self.last_print_t - if dt >= self.mininterval: + cur_t = self._time() + dt = cur_t - self.last_print_t + if dt >= self.mininterval and cur_t >= self.start_t + self.delay: cur_t = self._time() dn = self.n - self.last_print_n # >= n if self.smoothing and dt and dn: @@ -1261,6 +1269,10 @@ def close(self): pos = abs(self.pos) self._decr_instances(self) + if self.last_print_t < self.start_t + self.delay: + # haven't ever displayed; nothing to clear + return + # GUI mode if getattr(self, 'sp', None) is None: return