Skip to content

Commit

Permalink
bump version, merge pull request #1130 from tqdm/devel
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Feb 25, 2021
2 parents b9507b3 + 47e303c commit 0ed778e
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 41 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
@@ -1,2 +1,3 @@
github: casperdcl
custom: https://caspersci.uk.to/donate
tidelift: pypi/tqdm
4 changes: 2 additions & 2 deletions .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"
14 changes: 14 additions & 0 deletions .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.
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -462,6 +462,8 @@ Parameters
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.

Extra CLI Options
~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmarks.py
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/7zx.py
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions examples/include_no_requirements.py
Expand Up @@ -7,3 +7,5 @@ def tqdm(*args, **kwargs):
if args:
return args[0]
return kwargs.get('iterable', None)

__all__ = ['tqdm']
6 changes: 3 additions & 3 deletions tests/tests_main.py
Expand Up @@ -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

Expand All @@ -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

Expand Down
15 changes: 15 additions & 0 deletions tests/tests_tqdm.py
Expand Up @@ -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:
Expand Down
30 changes: 13 additions & 17 deletions tox.ini
Expand Up @@ -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
Expand All @@ -24,32 +18,34 @@ 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
pandas
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=
Expand Down
2 changes: 1 addition & 1 deletion 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,
Expand Down
12 changes: 6 additions & 6 deletions tqdm/notebook.py
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
24 changes: 18 additions & 6 deletions tqdm/std.py
Expand Up @@ -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
----------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0ed778e

Please sign in to comment.