Skip to content

Commit

Permalink
bump version, merge pull request #1085 from tqdm/devel
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Nov 27, 2020
2 parents 819f6e0 + 9224b7b commit 668fa0e
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 92 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ jobs:
python-version: '3.x'
- uses: reviewdog/action-setup@v1
- run: pip install -U flake8
- name: flake8
- if: github.event_name != 'schedule'
name: flake8
run: |
set -o pipefail
flake8 -j8 --count --statistics . | \
Expand All @@ -57,9 +58,8 @@ jobs:
run: |
pip install -U wheel
pip install -U virtualenv asv
git checkout master && git checkout -
asv machine --machine github-actions --yes
git fetch --tags
git fetch origin master:master
- name: Restore previous results
uses: actions/cache@v2
with:
Expand All @@ -85,16 +85,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install
run: |
pip install -U wheel
pip install -U virtualenv asv
git checkout master && git checkout -
asv machine --machine github-actions --yes
git fetch --tags
git fetch origin master:master
- name: Restore previous results
uses: actions/cache@v2
with:
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/comment-bot.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Comment Bot
on:
issue_comment:
types: [created, edited]
types: [created]
pull_request_review_comment:
types: [created, edited]

types: [created]
jobs:
tag: # /tag <tagname> <commit>
if: startsWith(github.event.comment.body, '/tag ')
Expand All @@ -21,7 +20,6 @@ jobs:
post = (context.eventName == "issue_comment"
? github.reactions.createForIssueComment
: github.reactions.createForPullRequestReviewComment)
if (!["admin", "write"].includes(perm.data.permission)){
post({
owner: context.repo.owner, repo: context.repo.repo,
Expand Down Expand Up @@ -50,7 +48,3 @@ jobs:
post({
owner: context.repo.owner, repo: context.repo.repo,
comment_id: context.payload.comment.id, content: "rocket"})
always:
runs-on: ubuntu-latest
steps:
- run: echo prevent failure when other jobs are skipped
21 changes: 1 addition & 20 deletions .meta/.readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,7 @@ For further customisation,
(e.g. GUIs such as notebook or plotting packages). In the latter case:

1. ``def __init__()`` to call ``super().__init__(..., gui=True)`` to disable
terminal ``status_printer`` creation. Otherwise (if terminal is required),
``def __new__()`` to call ``cls.get_new()`` (see below) to ensure correct
nested positioning.
terminal ``status_printer`` creation.
2. Redefine: ``close()``, ``clear()``, ``display()``.

Consider overloading ``display()`` to use e.g.
Expand All @@ -935,23 +933,6 @@ above recommendation:
- `tqdm/contrib/telegram.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/telegram.py>`__
- `tqdm/contrib/discord.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/discord.py>`__

Note that multiple different ``tqdm`` subclasses which all write to the terminal
(``gui=False``) can cause positioning issues when used simultaneously (in nested
mode). To fix this, custom subclasses which expect to write to the terminal
should define a ``__new__()`` method as follows:

.. code:: python
from tqdm import tqdm as std_tqdm
class TqdmExt(std_tqdm):
def __new__(cls, *args, **kwargs):
return cls.get_new(super(TqdmExt, cls), std_tqdm, *args, **kwargs)
This approach is used ``tqdm.asyncio`` and ``tqdm.contrib.telegram/discord``.
However it is not necessary for ``tqdm.notebook/gui`` since they don't use the
terminal.

Dynamic Monitor/Meter
~~~~~~~~~~~~~~~~~~~~~

Expand Down
21 changes: 1 addition & 20 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1136,9 +1136,7 @@ For further customisation,
(e.g. GUIs such as notebook or plotting packages). In the latter case:

1. ``def __init__()`` to call ``super().__init__(..., gui=True)`` to disable
terminal ``status_printer`` creation. Otherwise (if terminal is required),
``def __new__()`` to call ``cls.get_new()`` (see below) to ensure correct
nested positioning.
terminal ``status_printer`` creation.
2. Redefine: ``close()``, ``clear()``, ``display()``.

Consider overloading ``display()`` to use e.g.
Expand All @@ -1152,23 +1150,6 @@ above recommendation:
- `tqdm/contrib/telegram.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/telegram.py>`__
- `tqdm/contrib/discord.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/discord.py>`__

Note that multiple different ``tqdm`` subclasses which all write to the terminal
(``gui=False``) can cause positioning issues when used simultaneously (in nested
mode). To fix this, custom subclasses which expect to write to the terminal
should define a ``__new__()`` method as follows:

.. code:: python
from tqdm import tqdm as std_tqdm
class TqdmExt(std_tqdm):
def __new__(cls, *args, **kwargs):
return cls.get_new(super(TqdmExt, cls), std_tqdm, *args, **kwargs)
This approach is used ``tqdm.asyncio`` and ``tqdm.contrib.telegram/discord``.
However it is not necessary for ``tqdm.notebook/gui`` since they don't use the
terminal.

Dynamic Monitor/Meter
~~~~~~~~~~~~~~~~~~~~~

Expand Down
3 changes: 0 additions & 3 deletions tqdm/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ def as_completed(cls, fs, *, loop=None, timeout=None, total=None,
yield from cls(asyncio.as_completed(fs, loop=loop, timeout=timeout),
total=total, **tqdm_kwargs)

def __new__(cls, *args, **kwargs):
return cls.get_new(super(tqdm_asyncio, cls), std_tqdm, *args, **kwargs)


def tarange(*args, **kwargs):
"""
Expand Down
3 changes: 0 additions & 3 deletions tqdm/contrib/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ def display(self, **kwargs):
fmt['bar_format'] = '{l_bar}{bar:10u}{r_bar}'
self.dio.write(self.format_meter(**fmt))

def __new__(cls, *args, **kwargs):
return cls.get_new(super(tqdm_discord, cls), tqdm_auto, *args, **kwargs)


def tdrange(*args, **kwargs):
"""
Expand Down
4 changes: 0 additions & 4 deletions tqdm/contrib/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ def display(self, **kwargs):
fmt['bar_format'] = '{l_bar}{bar:10u}{r_bar}'
self.tgio.write(self.format_meter(**fmt))

def __new__(cls, *args, **kwargs):
return cls.get_new(
super(tqdm_telegram, cls), tqdm_auto, *args, **kwargs)


def ttgrange(*args, **kwargs):
"""
Expand Down
32 changes: 3 additions & 29 deletions tqdm/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class tqdm(Comparable):

monitor_interval = 10 # set to 0 to disable the thread
monitor = None
_instances = WeakSet()

@staticmethod
def format_sizeof(num, suffix='', divisor=1000):
Expand Down Expand Up @@ -554,15 +555,10 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False,
n_fmt, unit, elapsed_str, rate_fmt, postfix)

def __new__(cls, *_, **__):
# Create a new instance
instance = object.__new__(cls)
# Construct the lock if it does not exist
with cls.get_lock():
# Add to the list of instances
if not hasattr(cls, '_instances'):
cls._instances = WeakSet()
with cls.get_lock(): # also constructs lock if non-existent
cls._instances.add(instance)
# Create the monitoring thread
# create monitoring thread
if cls.monitor_interval and (cls.monitor is None or not
cls.monitor.report()):
try:
Expand All @@ -572,28 +568,6 @@ def __new__(cls, *_, **__):
" (monitor_interval = 0) due to:\n" + str(e),
TqdmMonitorWarning, stacklevel=2)
cls.monitor_interval = 0
# Return the instance
return instance

@classmethod
def get_new(cls, super_cls, base_cls, *args, **kwargs):
"""
Workaround for mixed-class same-stream nested progressbars.
See [#509](https://github.com/tqdm/tqdm/issues/509)
"""
with cls.get_lock():
try:
cls._instances = base_cls._instances
except AttributeError:
pass
instance = super_cls.__new__(cls, *args, **kwargs)
with cls.get_lock():
try:
# `base_cls` may have been changed so update
cls._instances.update(base_cls._instances)
except AttributeError:
pass
base_cls._instances = cls._instances
return instance

@classmethod
Expand Down

0 comments on commit 668fa0e

Please sign in to comment.