Skip to content
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

next release v4.60.0 #1143

Merged
merged 23 commits into from Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions .meta/.readme.rst
Expand Up @@ -1102,6 +1102,33 @@ A reusable canonical example is given below:
# After the `with`, printing is restored
print("Done!")

Redirecting ``logging``
~~~~~~~~~~~~~~~~~~~~~~~

Similar to ``sys.stdout``/``sys.stderr`` as detailed above, console ``logging``
may also be redirected to ``tqdm.write()``.

Warning: if also redirecting ``sys.stdout``/``sys.stderr``, make sure to
redirect ``logging`` first if needed.

Helper methods are available in ``tqdm.contrib.logging``. For example:

.. code:: python

import logging
from tqdm import trange
from tqdm.contrib.logging import logging_redirect_tqdm

LOG = logging.getLogger(__name__)

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
with logging_redirect_tqdm():
for i in trange(9):
if i == 4:
LOG.info("console logging redirected to `tqdm.write()`")
# logging restored

Monitoring thread, intervals and miniters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 2 additions & 0 deletions .meta/requirements-test.txt
Expand Up @@ -2,4 +2,6 @@ flake8
pytest
pytest-cov
pytest-timeout
nbval
ipywidgets
# py>=37: pytest-asyncio
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -52,3 +52,8 @@ repos:
rev: 5.7.0
hooks:
- id: isort
- repo: https://github.com/kynan/nbstripout
rev: 0.3.9
hooks:
- id: nbstripout
args: ['--keep-count', '--keep-output']
7 changes: 2 additions & 5 deletions DEMO.ipynb
Expand Up @@ -1714,15 +1714,12 @@
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"name": "ipython"
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.8"
"nbconvert_exporter": "python"
}
},
"nbformat": 4,
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Expand Up @@ -10,6 +10,7 @@
test
pytest
testsetup
testnb
testcoverage
testperf
testtimer
Expand Down Expand Up @@ -59,9 +60,13 @@ testsetup:
python setup.py check --metadata --restructuredtext --strict
python setup.py make none

testnb:
pytest tests_notebook.ipynb --nbval --current-env -W=ignore --sanitize-with=setup.cfg --cov=tqdm.notebook --cov-report=term

testcoverage:
@make coverclean
pytest -k "not perf" --cov=tqdm --cov-report=xml --cov-report=term --cov-fail-under=80
pytest tests_notebook.ipynb --cov=tqdm --cov-report= --nbval --current-env --sanitize-with=setup.cfg -W=ignore
pytest -k "not perf" --cov=tqdm --cov-report=xml --cov-report=term --cov-append --cov-fail-under=80

testperf:
# do not use coverage (which is extremely slow)
Expand Down
27 changes: 27 additions & 0 deletions README.rst
Expand Up @@ -1321,6 +1321,33 @@ A reusable canonical example is given below:
# After the `with`, printing is restored
print("Done!")

Redirecting ``logging``
~~~~~~~~~~~~~~~~~~~~~~~

Similar to ``sys.stdout``/``sys.stderr`` as detailed above, console ``logging``
may also be redirected to ``tqdm.write()``.

Warning: if also redirecting ``sys.stdout``/``sys.stderr``, make sure to
redirect ``logging`` first if needed.

Helper methods are available in ``tqdm.contrib.logging``. For example:

.. code:: python

import logging
from tqdm import trange
from tqdm.contrib.logging import logging_redirect_tqdm

LOG = logging.getLogger(__name__)

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
with logging_redirect_tqdm():
for i in trange(9):
if i == 4:
LOG.info("console logging redirected to `tqdm.write()`")
# logging restored

Monitoring thread, intervals and miniters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
3 changes: 3 additions & 0 deletions environment.yml
Expand Up @@ -8,6 +8,7 @@ dependencies:
- python=3
- pip
- ipykernel
- ipywidgets
- setuptools
- setuptools_scm
- toml
Expand All @@ -20,13 +21,15 @@ dependencies:
- pytest-cov
- pytest-timeout
- pytest-asyncio # [py>=3.7]
- nbval
- flake8
- flake8-bugbear
- flake8-comprehensions
- coverage
# extras
- dask # dask
- matplotlib # gui
- nbstripout # notebook editing
- numpy # pandas, keras, contrib.tenumerate
- pandas
- tensorflow # keras
Expand Down
8 changes: 7 additions & 1 deletion setup.cfg
Expand Up @@ -119,9 +119,15 @@ log_level=INFO
markers=
asyncio
slow
python_files=tests_*.py
python_files=tests_*.py tests_*.ipynb
testpaths=tests
addopts=-v --tb=short -rxs -W=error --durations=0 --durations-min=0.1
[regex1]
regex: (?<= )[\s\d.]+(it/s|s/it)
replace: ??.??it/s
[regex2]
regex: 00:0[01]<00:0[01]
replace: 00:00<00:00

[coverage:run]
branch=True
Expand Down
34 changes: 22 additions & 12 deletions tests/tests_contrib.py
Expand Up @@ -3,6 +3,9 @@
"""
import sys

import pytest

from tqdm import tqdm
from tqdm.contrib import tenumerate, tmap, tzip

from .tests_tqdm import StringIO, closing, importorskip
Expand All @@ -13,49 +16,56 @@ def incr(x):
return x + 1


def test_enumerate():
@pytest.mark.parametrize("tqdm_kwargs", [{}, {"tqdm_class": tqdm}])
def test_enumerate(tqdm_kwargs):
"""Test contrib.tenumerate"""
with closing(StringIO()) as our_file:
a = range(9)
assert list(tenumerate(a, file=our_file)) == list(enumerate(a))
assert list(tenumerate(a, 42, file=our_file)) == list(enumerate(a, 42))
assert list(tenumerate(a, file=our_file, **tqdm_kwargs)) == list(enumerate(a))
assert list(tenumerate(a, 42, file=our_file, **tqdm_kwargs)) == list(
enumerate(a, 42)
)
with closing(StringIO()) as our_file:
_ = list(tenumerate((i for i in a), file=our_file))
_ = list(tenumerate((i for i in a), file=our_file, **tqdm_kwargs))
assert "100%" not in our_file.getvalue()
with closing(StringIO()) as our_file:
_ = list(tenumerate((i for i in a), file=our_file, total=len(a)))
_ = list(tenumerate((i for i in a), file=our_file, total=len(a), **tqdm_kwargs))
assert "100%" in our_file.getvalue()


def test_enumerate_numpy():
"""Test contrib.tenumerate(numpy.ndarray)"""
np = importorskip('numpy')
np = importorskip("numpy")
with closing(StringIO()) as our_file:
a = np.random.random((42, 7))
assert list(tenumerate(a, file=our_file)) == list(np.ndenumerate(a))


def test_zip():
@pytest.mark.parametrize("tqdm_kwargs", [{}, {"tqdm_class": tqdm}])
def test_zip(tqdm_kwargs):
"""Test contrib.tzip"""
with closing(StringIO()) as our_file:
a = range(9)
b = [i + 1 for i in a]
if sys.version_info[:1] < (3,):
assert tzip(a, b, file=our_file) == zip(a, b)
assert tzip(a, b, file=our_file, **tqdm_kwargs) == zip(a, b)
else:
gen = tzip(a, b, file=our_file)
gen = tzip(a, b, file=our_file, **tqdm_kwargs)
assert gen != list(zip(a, b))
assert list(gen) == list(zip(a, b))


def test_map():
@pytest.mark.parametrize("tqdm_kwargs", [{}, {"tqdm_class": tqdm}])
def test_map(tqdm_kwargs):
"""Test contrib.tmap"""
with closing(StringIO()) as our_file:
a = range(9)
b = [i + 1 for i in a]
if sys.version_info[:1] < (3,):
assert tmap(lambda x: x + 1, a, file=our_file) == map(incr, a)
assert tmap(lambda x: x + 1, a, file=our_file, **tqdm_kwargs) == map(
incr, a
)
else:
gen = tmap(lambda x: x + 1, a, file=our_file)
gen = tmap(lambda x: x + 1, a, file=our_file, **tqdm_kwargs)
assert gen != b
assert list(gen) == b