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 Oct 7, 2020
2 parents 00dabd6 + 6e47048 commit 03a5d6c
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 202 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Check
on:
- push
jobs:
check:
name: '${{ matrix.TOXENV }}'
strategy:
matrix:
TOXENV: [flake8, setup.py, perf]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install
run: |
pip install -U tox
pip install -U .
- name: Test
run: tox
env:
TOXENV: ${{ matrix.TOXENV }}
4 changes: 2 additions & 2 deletions .meta/.readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1107,8 +1107,8 @@ Citation information: |DOI|
:target: https://coveralls.io/github/tqdm/tqdm
.. |Branch-Coverage-Status| image:: https://codecov.io/gh/tqdm/tqdm/branch/master/graph/badge.svg
: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
.. |Codacy-Grade| image:: https://app.codacy.com/project/badge/Grade/3f965571598f44549c7818f29cdcf177
:target: https://www.codacy.com/gh/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
Expand Down
11 changes: 0 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ notifications:
# - master
# - /^\d\.\d+$/
stages:
- check
- test
- name: deploy
if: repo = tqdm/tqdm AND NOT type = pull_request
Expand Down Expand Up @@ -96,16 +95,6 @@ jobs:
osx_image: xcode11.2 # py3.7
language: shell
env: TOXENV=py37
- stage: check
name: style
python: 3.7
env: TOXENV=flake8
- name: setup
python: 3.7
env: TOXENV=setup.py
- name: perf
python: 3.7
env: TOXENV=perf
- stage: deploy
name: PyPI and GitHub
python: 3.7
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ Parameters
bound. If unspecified, attempts to use environment height.
The fallback is 20.
* colour : str, optional
Bar colour (e.g. ``'green'``, ``'#00ff00'``).
Bar colour (e.g. 'green', '#00ff00').

Extra CLI Options
~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -1322,8 +1322,8 @@ Citation information: |DOI|
:target: https://coveralls.io/github/tqdm/tqdm
.. |Branch-Coverage-Status| image:: https://codecov.io/gh/tqdm/tqdm/branch/master/graph/badge.svg
: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
.. |Codacy-Grade| image:: https://app.codacy.com/project/badge/Grade/3f965571598f44549c7818f29cdcf177
:target: https://www.codacy.com/gh/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
Expand Down
17 changes: 12 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ deps =
commands =
nosetests --with-coverage --cover-package=tqdm --ignore-files="tests_perf\.py" -d -v tqdm/
- coveralls
- coverage xml
- curl -OL https://coverage.codacy.com/get.sh
- bash get.sh report -r coverage.xml
allowlist_externals =
curl
bash

[extra]
deps =
Expand All @@ -25,9 +31,13 @@ commands =
nosetests --with-coverage --with-timer --cover-package=tqdm --ignore-files="tests_perf\.py" -d -v tqdm/
- coveralls
codecov
- coverage xml
- curl -OL https://coverage.codacy.com/get.sh
- bash get.sh report -r coverage.xml
allowlist_externals = {[coverage]allowlist_externals}

[testenv]
passenv = CI TRAVIS TRAVIS_* TOXENV CODECOV_*
passenv = CI TRAVIS TRAVIS_* TOXENV CODECOV_* HOME CODACY_*
deps =
{[extra]deps}
cython
Expand All @@ -36,6 +46,7 @@ deps =
tensorflow
keras
commands = {[extra]commands}
allowlist_externals = {[extra]allowlist_externals}

# no cython/numpy/pandas for py{py,py3,26,33,34}

Expand All @@ -54,20 +65,16 @@ commands =

[testenv:pypy]
deps = {[extra]deps}
commands = {[extra]commands}

[testenv:pypy3]
deps = {[extra]deps}
commands = {[extra]commands}

[testenv:py33]
deps = {[extra]deps}
commands = {[extra]commands}

[testenv:py34]
# py34-compatible pandas
deps = {[extra]deps}
commands = {[extra]commands}

[testenv:tf-no-keras]
deps =
Expand Down
16 changes: 3 additions & 13 deletions tqdm/_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,16 @@ class TMonitor(Thread):
sleep_interval : fload
Time to sleep between monitoring checks.
"""

# internal vars for unit testing
_time = None
_event = None
_test = {} # internal vars for unit testing

def __init__(self, tqdm_cls, sleep_interval):
Thread.__init__(self)
self.daemon = True # kill thread when main killed (KeyboardInterrupt)
self.was_killed = Event()
self.woken = 0 # last time woken up, to sync with monitor
self.tqdm_cls = tqdm_cls
self.sleep_interval = sleep_interval
if TMonitor._time is not None:
self._time = TMonitor._time
else:
self._time = time
if TMonitor._event is not None:
self._event = TMonitor._event
else:
self._event = Event
self._time = self._test.get("time", time)
self.was_killed = self._test.get("Event", Event)()
atexit.register(self.exit)
self.start()

Expand Down
2 changes: 1 addition & 1 deletion 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, 50, 0
version_info = 4, 50, 1

# Nice string for the version
__version__ = '.'.join(map(str, version_info))
Expand Down
2 changes: 1 addition & 1 deletion tqdm/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def close(self, *args, **kwargs):
else:
self.sp(close=True)

def moveto(self, *args, **kwargs):
def moveto(self, *_, **__):
# void -> avoid extraneous `\n` in IPython output cell
return

Expand Down
77 changes: 34 additions & 43 deletions tqdm/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
from ._monitor import TMonitor
# native libraries
from contextlib import contextmanager
import sys
from numbers import Number
from time import time
# For parallelism safety
import threading as th
from warnings import warn
import sys

__author__ = "https://github.com/tqdm/tqdm#contributions"
__all__ = ['tqdm', 'trange',
Expand Down Expand Up @@ -66,6 +64,15 @@ class TqdmMonitorWarning(TqdmWarning, RuntimeWarning):
pass


def TRLock(*args, **kwargs):
"""threading RLock"""
try:
from threading import RLock
return RLock(*args, **kwargs)
except (ImportError, OSError): # pragma: no cover
pass


class TqdmDefaultWriteLock(object):
"""
Provide a default write lock for thread and multiprocessing safety.
Expand All @@ -75,13 +82,22 @@ class TqdmDefaultWriteLock(object):
On Windows, you need to supply the lock from the parent to the children as
an argument to joblib or the parallelism lib you use.
"""
# global thread lock so no setup required for multithreading.
# NB: Do not create multiprocessing lock as it sets the multiprocessing
# context, disallowing `spawn()`/`forkserver()`
th_lock = TRLock()

def __init__(self):
# Create global parallelism locks to avoid racing issues with parallel
# bars works only if fork available (Linux/MacOSX, but not Windows)
self.create_mp_lock()
self.create_th_lock()
cls = type(self)
root_lock = cls.th_lock
if root_lock is not None:
root_lock.acquire()
cls.create_mp_lock()
self.locks = [lk for lk in [cls.mp_lock, cls.th_lock] if lk is not None]
if root_lock is not None:
root_lock.release()

def acquire(self, *a, **k):
for lock in self.locks:
Expand All @@ -102,26 +118,15 @@ def create_mp_lock(cls):
if not hasattr(cls, 'mp_lock'):
try:
from multiprocessing import RLock
cls.mp_lock = RLock() # multiprocessing lock
except ImportError: # pragma: no cover
cls.mp_lock = None
except OSError: # pragma: no cover
cls.mp_lock = RLock()
except (ImportError, OSError): # pragma: no cover
cls.mp_lock = None

@classmethod
def create_th_lock(cls):
if not hasattr(cls, 'th_lock'):
try:
cls.th_lock = th.RLock() # thread lock
except OSError: # pragma: no cover
cls.th_lock = None


# Create a thread lock before instantiation so that no setup needs to be done
# before running in a multithreaded environment.
# Do not create the multiprocessing lock because it sets the multiprocessing
# context and does not allow the user to use 'spawn' or 'forkserver' methods.
TqdmDefaultWriteLock.create_th_lock()
assert hasattr(cls, 'th_lock')
warn("create_th_lock not needed anymore", TqdmDeprecationWarning,
stacklevel=2)


class Bar(object):
Expand All @@ -147,7 +152,7 @@ class Bar(object):
CYAN='\x1b[36m', WHITE='\x1b[37m')

def __init__(self, frac, default_len=10, charset=UTF, colour=None):
if not (0 <= frac <= 1):
if not 0 <= frac <= 1:
warn("clamping frac to range [0, 1]", TqdmWarning, stacklevel=2)
frac = max(0, min(1, frac))
assert default_len > 0
Expand Down Expand Up @@ -202,16 +207,11 @@ def __format__(self, format_spec):
bar_length, frac_bar_length = divmod(
int(self.frac * N_BARS * nsyms), nsyms)

bar = charset[-1] * bar_length
frac_bar = charset[frac_bar_length]

# whitespace padding
if bar_length < N_BARS:
bar = bar + frac_bar + \
res = charset[-1] * bar_length
if bar_length < N_BARS: # whitespace padding
res = res + charset[frac_bar_length] + \
charset[0] * (N_BARS - bar_length - 1)
if self.colour:
return self.colour + bar + self.COLOUR_RESET
return bar
return self.colour + res + self.COLOUR_RESET if self.colour else res


class tqdm(Comparable):
Expand Down Expand Up @@ -400,7 +400,7 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False,
initial : int or float, optional
The initial counter value [default: 0].
colour : str, optional
Bar colour (e.g. `'green'`, `'#00ff00'`).
Bar colour (e.g. 'green', '#00ff00').
Returns
-------
Expand Down Expand Up @@ -546,7 +546,7 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False,
'{0}{1} [{2}, {3}{4}]'.format(
n_fmt, unit, elapsed_str, rate_fmt, postfix)

def __new__(cls, *args, **kwargs):
def __new__(cls, *_, **__):
# Create a new instance
instance = object.__new__(cls)
# Construct the lock if it does not exist
Expand Down Expand Up @@ -604,15 +604,6 @@ def _decr_instances(cls, instance):
inst = min(instances, key=lambda i: i.pos)
inst.clear(nolock=True)
inst.pos = abs(instance.pos)
# Kill monitor if no instances are left
if not cls._instances and cls.monitor:
try:
cls.monitor.exit()
del cls.monitor
except AttributeError: # pragma: nocover
pass
else:
cls.monitor = None

@classmethod
def write(cls, s, file=None, end="\n", nolock=False):
Expand Down Expand Up @@ -945,7 +936,7 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True,
bound. If unspecified, attempts to use environment height.
The fallback is 20.
colour : str, optional
Bar colour (e.g. `'green'`, `'#00ff00'`).
Bar colour (e.g. 'green', '#00ff00').
gui : bool, optional
WARNING: internal parameter - do not use.
Use tqdm.gui.tqdm(...) instead. If set, will attempt to use
Expand Down

0 comments on commit 03a5d6c

Please sign in to comment.