Skip to content

Commit

Permalink
bump version, merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Aug 2, 2020
2 parents faaa81d + e602bb5 commit 84923d7
Show file tree
Hide file tree
Showing 21 changed files with 160 additions and 103 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
GIT_AUTHOR_NAME: ${{ github.actor }}
GIT_AUTHOR_EMAIL: ${{ github.actor }}@users.noreply.github.com
testasv:
if: github.event_name == 'push' && ! startsWith(github.event.ref, 'refs/tags')
if: github.event_name == 'push' && ! startsWith(github.event.ref, 'refs/tags') && github.event.ref != 'refs/heads/master'
name: Branch
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -70,3 +70,7 @@ jobs:
CHANGES="$(asv compare --only-changed -f 1.25 master HEAD)"
echo "$CHANGES"
[ -z "$CHANGES" ] || exit 1
always:
runs-on: ubuntu-latest
steps:
- run: echo prevent failure when other jobs are skipped
2 changes: 2 additions & 0 deletions .meta/.readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ of a neat one-line progress bar.
- `Hanging pipes in python2 <https://github.com/tqdm/tqdm/issues/359>`__:
when using ``tqdm`` on the CLI, you may need to use Python 3.5+ for correct
buffering.
- `No intermediate output in docker-compose <https://github.com/tqdm/tqdm/issues/771>`__:
use ``docker-compose run`` instead of ``docker-compose up`` and ``tty: true``.

If you come across any other difficulties, browse and file |GitHub-Issues|.

Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ of a neat one-line progress bar.
- `Hanging pipes in python2 <https://github.com/tqdm/tqdm/issues/359>`__:
when using ``tqdm`` on the CLI, you may need to use Python 3.5+ for correct
buffering.
- `No intermediate output in docker-compose <https://github.com/tqdm/tqdm/issues/771>`__:
use ``docker-compose run`` instead of ``docker-compose up`` and ``tty: true``.

If you come across any other difficulties, browse and file |GitHub-Issues|.

Expand Down
5 changes: 3 additions & 2 deletions examples/async_coroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ async def main():
elif row < 0:
assert row == -9
break
# should be under 10 seconds
for i in tqdm.as_completed(list(map(asyncio.sleep, [1] * 10)),
# should be ~1sec rather than ~50s due to async scheduling
for i in tqdm.as_completed([asyncio.sleep(0.01 * i)
for i in range(100, 0, -1)],
desc="as_completed"):
await i

Expand Down
4 changes: 4 additions & 0 deletions tqdm/_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ def run(self):
instance.miniters = 1
# Refresh now! (works only for manual tqdm)
instance.refresh(nolock=True)
# Remove accidental long-lived strong reference
del instance
if instances != self.get_instances(): # pragma: nocover
warn("Set changed size during iteration" +
" (see https://github.com/tqdm/tqdm/issues/481)",
TqdmSynchronisationWarning, stacklevel=2)
# Remove accidental long-lived strong references
del instances

def report(self):
return not self.was_killed.is_set()
79 changes: 41 additions & 38 deletions tqdm/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__all__ = ["__version__"]

# major, minor, patch, -extra
version_info = 4, 48, 0
version_info = 4, 48, 1

# Nice string for the version
__version__ = '.'.join(map(str, version_info))
Expand All @@ -15,45 +15,48 @@
scriptdir = os.path.dirname(__file__)
gitdir = os.path.abspath(os.path.join(scriptdir, "..", ".git"))
if os.path.isdir(gitdir): # pragma: nocover
extra = None
# Open config file to check if we are in tqdm project
with io_open(os.path.join(gitdir, "config"), 'r') as fh_config:
if 'tqdm' in fh_config.read():
# Open the HEAD file
with io_open(os.path.join(gitdir, "HEAD"), 'r') as fh_head:
extra = fh_head.readline().strip()
# in a branch => HEAD points to file containing last commit
if 'ref:' in extra:
# reference file path
ref_file = extra[5:]
branch_name = ref_file.rsplit('/', 1)[-1]

ref_file_path = os.path.abspath(os.path.join(gitdir, ref_file))
# check that we are in git folder
# (by stripping the git folder from the ref file path)
if os.path.relpath(
ref_file_path, gitdir).replace('\\', '/') != ref_file:
# out of git folder
extra = None
try:
extra = None
# Open config file to check if we are in tqdm project
with io_open(os.path.join(gitdir, "config"), 'r') as fh_config:
if 'tqdm' in fh_config.read():
# Open the HEAD file
with io_open(os.path.join(gitdir, "HEAD"), 'r') as fh_head:
extra = fh_head.readline().strip()
# in a branch => HEAD points to file containing last commit
if 'ref:' in extra:
# reference file path
ref_file = extra[5:]
branch_name = ref_file.rsplit('/', 1)[-1]

ref_file_path = os.path.abspath(os.path.join(
gitdir, ref_file))
# check that we are in git folder
# (by stripping the git folder from the ref file path)
if os.path.relpath(ref_file_path, gitdir).replace(
'\\', '/') != ref_file:
# out of git folder
extra = None
else:
# open the ref file
with io_open(ref_file_path, 'r') as fh_branch:
commit_hash = fh_branch.readline().strip()
extra = commit_hash[:8]
if branch_name != "master":
extra += '.' + branch_name

# detached HEAD mode, already have commit hash
else:
# open the ref file
with io_open(ref_file_path, 'r') as fh_branch:
commit_hash = fh_branch.readline().strip()
extra = commit_hash[:8]
if branch_name != "master":
extra += '.' + branch_name

# detached HEAD mode, already have commit hash
else:
extra = extra[:8]

# Append commit hash (and branch) to version string if not tagged
if extra is not None:
try:
extra = extra[:8]

# Append commit hash (and branch) to version string if not tagged
if extra is not None:
with io_open(os.path.join(gitdir, "refs", "tags",
'v' + __version__)) as fdv:
if fdv.readline().strip()[:8] != extra[:8]:
__version__ += '-' + extra
except Exception as e:
if "No such file" not in str(e):
raise
except Exception as e:
if "No such file" in str(e):
__version__ += "-git.UNKNOWN"
else:
raise
7 changes: 5 additions & 2 deletions tqdm/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
>>> async for i in trange(10):
... ...
"""
from .auto import tqdm as tqdm_auto
from .std import tqdm as std_tqdm
import asyncio
__author__ = {"github.com/": ["casperdcl"]}
__all__ = ['tqdm_asyncio', 'tarange', 'tqdm', 'trange']


class tqdm_asyncio(tqdm_auto):
class tqdm_asyncio(std_tqdm):
"""
Asynchronous-friendly version of tqdm (Python 3.5+).
"""
def __init__(self, iterable=None, *args, **kwargs):
super(tqdm_asyncio, self).__init__(iterable, *args, **kwargs)
self.iterable_awaitable = False
Expand Down
32 changes: 30 additions & 2 deletions tqdm/auto.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
"""
`tqdm.autonotebook` but without import warnings.
Enables multiple commonly used features.
Method resolution order:
- `tqdm.autonotebook` without import warnings
- `tqdm.asyncio` on Python3.5+
- `tqdm.std` base class
Usage:
>>> from tqdm.auto import trange, tqdm
>>> for i in trange(10):
... ...
"""
import sys
import warnings
from .std import TqdmExperimentalWarning
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=TqdmExperimentalWarning)
from .autonotebook import tqdm, trange
from .autonotebook import tqdm as notebook_tqdm
from .autonotebook import trange as notebook_trange

if sys.version_info[:1] < (3, 4):
tqdm = notebook_tqdm
trange = notebook_trange
else: # Python3.5+
from .asyncio import tqdm as asyncio_tqdm
from .std import tqdm as std_tqdm

if notebook_tqdm != std_tqdm:
class tqdm(notebook_tqdm, asyncio_tqdm):
pass
else:
tqdm = asyncio_tqdm

def trange(*args, **kwargs):
"""
A shortcut for `tqdm.auto.tqdm(range(*args), **kwargs)`.
"""
return tqdm(range(*args), **kwargs)

__all__ = ["tqdm", "trange"]
38 changes: 18 additions & 20 deletions tqdm/contrib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from tqdm import tqdm
from tqdm.auto import tqdm as tqdm_auto
from tqdm.utils import ObjectWrapper
from copy import deepcopy
import functools
from functools import wraps
import sys
__author__ = {"github.com/": ["casperdcl"]}
__all__ = ['tenumerate', 'tzip', 'tmap']
Expand All @@ -21,6 +20,16 @@ def write(self, x, nolock=False):
tqdm.write(x, file=self._wrapped, nolock=nolock)


def builtin_iterable(func):
"""Wraps `func()` output in a `list()` in py2"""
if sys.version_info[:1] < (3,):
@wraps(func)
def inner(*args, **kwargs):
return list(func(*args, **kwargs))
return inner
return func


def tenumerate(iterable, start=0, total=None, tqdm_class=tqdm_auto,
**tqdm_kwargs):
"""
Expand All @@ -38,43 +47,32 @@ def tenumerate(iterable, start=0, total=None, tqdm_class=tqdm_auto,
if isinstance(iterable, np.ndarray):
return tqdm_class(np.ndenumerate(iterable),
total=total or iterable.size, **tqdm_kwargs)
return enumerate(tqdm_class(iterable, **tqdm_kwargs), start)
return enumerate(tqdm_class(iterable, total=total, **tqdm_kwargs), start)


def _tzip(iter1, *iter2plus, **tqdm_kwargs):
@builtin_iterable
def tzip(iter1, *iter2plus, **tqdm_kwargs):
"""
Equivalent of builtin `zip`.
Parameters
----------
tqdm_class : [default: tqdm.auto.tqdm].
"""
kwargs = deepcopy(tqdm_kwargs)
kwargs = tqdm_kwargs.copy()
tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
for i in zip(tqdm_class(iter1, **tqdm_kwargs), *iter2plus):
yield i


def _tmap(function, *sequences, **tqdm_kwargs):
@builtin_iterable
def tmap(function, *sequences, **tqdm_kwargs):
"""
Equivalent of builtin `map`.
Parameters
----------
tqdm_class : [default: tqdm.auto.tqdm].
"""
for i in _tzip(*sequences, **tqdm_kwargs):
for i in tzip(*sequences, **tqdm_kwargs):
yield function(*i)


if sys.version_info[:1] < (3,):
@functools.wraps(_tzip)
def tzip(*args, **kwargs):
return list(_tzip(*args, **kwargs))

@functools.wraps(_tmap)
def tmap(*args, **kwargs):
return list(_tmap(*args, **kwargs))
else:
tzip = _tzip
tmap = _tmap
2 changes: 1 addition & 1 deletion tqdm/contrib/bells.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
All the bells & whistles:
Even more features than `tqdm.auto` (all the bells & whistles):
- `tqdm.auto`
- `tqdm.tqdm.pandas`
Expand Down
3 changes: 1 addition & 2 deletions tqdm/contrib/concurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import absolute_import
from tqdm import TqdmWarning
from tqdm.auto import tqdm as tqdm_auto
from copy import deepcopy
try:
from operator import length_hint
except ImportError:
Expand Down Expand Up @@ -37,7 +36,7 @@ def _executor_map(PoolExecutor, fn, *iterables, **tqdm_kwargs):
max_workers : [default: min(32, cpu_count() + 4)].
chunksize : [default: 1].
"""
kwargs = deepcopy(tqdm_kwargs)
kwargs = tqdm_kwargs.copy()
if "total" not in kwargs:
kwargs["total"] = len(iterables[0])
tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
Expand Down
3 changes: 1 addition & 2 deletions tqdm/contrib/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
https://raw.githubusercontent.com/tqdm/img/src/screenshot-discord.png)
"""
from __future__ import absolute_import
from copy import deepcopy
import logging
from os import getenv

Expand Down Expand Up @@ -84,7 +83,7 @@ def __init__(self, *args, **kwargs):
See `tqdm.auto.tqdm.__init__` for other parameters.
"""
kwargs = deepcopy(kwargs)
kwargs = kwargs.copy()
logging.getLogger("HTTPClient").setLevel(logging.WARNING)
self.dio = DiscordIO(
kwargs.pop('token', getenv("TQDM_DISCORD_TOKEN")),
Expand Down
3 changes: 1 addition & 2 deletions tqdm/contrib/itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
from __future__ import absolute_import
from tqdm.auto import tqdm as tqdm_auto
from copy import deepcopy
import itertools
__author__ = {"github.com/": ["casperdcl"]}
__all__ = ['product']
Expand All @@ -17,7 +16,7 @@ def product(*iterables, **tqdm_kwargs):
----------
tqdm_class : [default: tqdm.auto.tqdm].
"""
kwargs = deepcopy(tqdm_kwargs)
kwargs = tqdm_kwargs.copy()
tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
try:
lens = list(map(len, iterables))
Expand Down
3 changes: 1 addition & 2 deletions tqdm/contrib/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
https://raw.githubusercontent.com/tqdm/img/src/screenshot-telegram.gif)
"""
from __future__ import absolute_import
from copy import deepcopy
from os import getenv

from requests import Session
Expand Down Expand Up @@ -91,7 +90,7 @@ def __init__(self, *args, **kwargs):
See `tqdm.auto.tqdm.__init__` for other parameters.
"""
kwargs = deepcopy(kwargs)
kwargs = kwargs.copy()
self.tgio = TelegramIO(
kwargs.pop('token', getenv('TQDM_TELEGRAM_TOKEN')),
kwargs.pop('chat_id', getenv('TQDM_TELEGRAM_CHAT_ID')))
Expand Down
4 changes: 2 additions & 2 deletions tqdm/keras.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, division
from .auto import tqdm as tqdm_auto
from copy import deepcopy
from copy import copy
try:
import keras
except ImportError as e:
Expand All @@ -20,7 +20,7 @@ def callback(_, logs=None):
n = delta(logs)
if logs:
if pop:
logs = deepcopy(logs)
logs = copy(logs)
[logs.pop(i, 0) for i in pop]
bar.set_postfix(logs, refresh=False)
bar.update(n)
Expand Down

0 comments on commit 84923d7

Please sign in to comment.