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 Jun 28, 2020
2 parents 0cd9448 + 9e4305e commit 15c5c51
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
branch = True
omit =
tqdm/tests/*
tqdm/contrib/bells.py
tqdm/contrib/discord.py
tqdm/contrib/telegram.py
tqdm/contrib/utils_worker.py
[report]
show_missing = True
10 changes: 7 additions & 3 deletions .meta/.readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ Changelog

The list of all changes is available either on GitHub's Releases:
|GitHub-Status|, on the
`wiki <https://github.com/tqdm/tqdm/wiki/Releases>`__, on the
`website <https://tqdm.github.io/releases/>`__, or on crawlers such as
`allmychanges.com <https://allmychanges.com/p/python/tqdm/>`_.
`wiki <https://github.com/tqdm/tqdm/wiki/Releases>`__, or on the
`website <https://tqdm.github.io/releases/>`__.


Usage
Expand Down Expand Up @@ -429,6 +428,11 @@ The ``tqdm.contrib`` package also contains experimental modules:

- ``tqdm.contrib.itertools``: Thin wrappers around ``itertools``
- ``tqdm.contrib.concurrent``: Thin wrappers around ``concurrent.futures``
- ``tqdm.contrib.bells``: Automagically enables all optional features

* ``auto``, ``pandas``, ``discord``, ``telegram``

- ``tqdm.contrib.discord``: Posts to `Discord <https://discord.com/>`__ bots
- ``tqdm.contrib.telegram``: Posts to `Telegram <https://telegram.org/>`__ bots

Examples and Advanced Usage
Expand Down
17 changes: 13 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ jobs:
- name: py3.7
python: 3.7
env: TOXENV=py37
- name: py3.8
python: 3.8
env: TOXENV=py38
- name: tf-no-keras
python: 3.7
env: TOXENV=tf-no-keras
- name: pypy2.7
python: pypy2.7-5.10.0
python: pypy2.7-7.1.1
env: TOXENV=pypy
- name: pypy3.5
python: pypy3.5-5.10.0
python: pypy3.6-7.1.1
env: TOXENV=pypy3
- stage: development
name: py2.7-win
Expand Down Expand Up @@ -184,18 +187,24 @@ jobs:
- name: snapcraft
channel: stable
confinement: classic
- name: review-tools
channel: stable
- name: lxd
channel: stable
env:
- SNAPCRAFT_IMAGE_INFO: '{"build_url": "$TRAVIS_BUILD_URL"}'
- SNAPCRAFT_IMAGE_INFO: |
'{"build_url": "$TRAVIS_JOB_WEB_URL"}'
- SNAPCRAFT_BUILD_ENVIRONMENT: lxd
- SNAPCRAFT_BUILD_INFO: 1 # https://snapcraft.io/blog/introducing-developer-notifications-for-snap-security-updates
before_install:
- sudo usermod --append --groups lxd $USER
- sudo /snap/bin/lxd.migrate -yes
- sudo /snap/bin/lxd waitready
- sudo /snap/bin/lxd init --auto
install:
- make snapcraft.yaml
script:
- sudo snapcraft --use-lxd
- sg lxd -c snapcraft
after_failure:
- sudo journalctl -u snapd
deploy:
Expand Down
10 changes: 7 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ Changelog

The list of all changes is available either on GitHub's Releases:
|GitHub-Status|, on the
`wiki <https://github.com/tqdm/tqdm/wiki/Releases>`__, on the
`website <https://tqdm.github.io/releases/>`__, or on crawlers such as
`allmychanges.com <https://allmychanges.com/p/python/tqdm/>`_.
`wiki <https://github.com/tqdm/tqdm/wiki/Releases>`__, or on the
`website <https://tqdm.github.io/releases/>`__.


Usage
Expand Down Expand Up @@ -617,6 +616,11 @@ The ``tqdm.contrib`` package also contains experimental modules:

- ``tqdm.contrib.itertools``: Thin wrappers around ``itertools``
- ``tqdm.contrib.concurrent``: Thin wrappers around ``concurrent.futures``
- ``tqdm.contrib.bells``: Automagically enables all optional features

* ``auto``, ``pandas``, ``discord``, ``telegram``

- ``tqdm.contrib.discord``: Posts to `Discord <https://discord.com/>`__ bots
- ``tqdm.contrib.telegram``: Posts to `Telegram <https://telegram.org/>`__ bots

Examples and Advanced Usage
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def find_packages(where='.'):
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: Implementation',
'Programming Language :: Python :: Implementation :: IronPython',
'Programming Language :: Python :: Implementation :: PyPy',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[tox]
# deprecation warning: py{26,32,33,34}
envlist = py{26,27,33,34,35,36,37,py,py3}, tf-no-keras, perf, flake8, setup.py
envlist = py{26,27,33,34,35,36,37,38,py,py3}, tf-no-keras, perf, flake8, setup.py

[coverage]
deps =
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, 46, 1
version_info = 4, 47, 0

# Nice string for the version
__version__ = '.'.join(map(str, version_info))
Expand Down
3 changes: 2 additions & 1 deletion tqdm/autonotebook.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import sys

try:
from IPython import get_ipython
get_ipython = sys.modules['IPython'].get_ipython
if 'IPKernelApp' not in get_ipython().config: # pragma: no cover
raise ImportError("console")
if 'VSCODE_PID' in os.environ: # pragma: no cover
Expand Down
3 changes: 3 additions & 0 deletions tqdm/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Module version for monitoring CLI pipes (`... | python -m tqdm | ...`).
"""
from .std import tqdm, TqdmTypeError, TqdmKeyError
from ._version import __version__ # NOQA
import sys
Expand Down
25 changes: 25 additions & 0 deletions tqdm/contrib/bells.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
All the bells & whistles:
- tqdm.auto
- tqdm.tqdm.pandas
- tqdm.contrib.telegram
+ uses ${TQDM_TELEGRAM_TOKEN} and ${TQDM_TELEGRAM_CHAT_ID}
- tqdm.contrib.discord
+ uses ${TQDM_DISCORD_TOKEN} and ${TQDM_DISCORD_CHANNEL_ID}
"""
__all__ = ['tqdm', 'trange']
from os import getenv
import warnings


if getenv("TQDM_TELEGRAM_TOKEN") and getenv("TQDM_TELEGRAM_CHAT_ID"):
from tqdm.contrib.telegram import tqdm, trange
elif getenv("TQDM_DISCORD_TOKEN") and getenv("TQDM_DISCORD_CHANNEL_ID"):
from tqdm.contrib.discord import tqdm, trange
else:
from tqdm.auto import tqdm, trange

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=FutureWarning)
tqdm.pandas()
127 changes: 127 additions & 0 deletions tqdm/contrib/discord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""
Sends updates to a Discord bot.
"""
from __future__ import absolute_import
from copy import deepcopy
from os import getenv

try:
from disco.client import Client, ClientConfig
except ImportError:
raise ImportError("Please `pip install disco-py`")

from tqdm.auto import tqdm as tqdm_auto
from tqdm.utils import _range
from .utils_worker import MonoWorker
__author__ = {"github.com/": ["casperdcl"]}
__all__ = ['DiscordIO', 'tqdm_discord', 'tdrange', 'tqdm', 'trange']


class DiscordIO(MonoWorker):
"""Non-blocking file-like IO using a Discord Bot."""
def __init__(self, token, channel_id):
"""Creates a new message in the given `channel_id`."""
super(DiscordIO, self).__init__()
config = ClientConfig()
config.token = token
client = Client(config)
self.text = self.__class__.__name__
try:
self.message = client.api.channels_messages_create(
channel_id, self.text)
except Exception as e:
tqdm_auto.write(str(e))

def write(self, s):
"""Replaces internal `message`'s text with `s`."""
if not s:
return
s = s.replace('\r', '').strip()
if s == self.text:
return # skip duplicate message
self.text = s
try:
future = self.submit(self.message.edit, '`' + s + '`')
except Exception as e:
tqdm_auto.write(str(e))
else:
return future


class tqdm_discord(tqdm_auto):
"""
Standard `tqdm.auto.tqdm` but also sends updates to a Discord Bot.
May take a few seconds to create (`__init__`).
- create a discord bot (not public, no requirement of OAuth2 code
grant, only send message permissions) & invite it to a channel:
https://discordpy.readthedocs.io/en/latest/discord.html
- copy the bot `{token}` & `{channel_id}` and paste below
>>> from tqdm.contrib.discord import tqdm, trange
>>> for i in tqdm(iterable, token='{token}', channel_id='{channel_id}'):
... ...
"""
def __init__(self, *args, **kwargs):
"""
Parameters
----------
token : str, required. Discord token
[default: ${TQDM_DISCORD_TOKEN}].
channel_id : int, required. Discord channel ID
[default: ${TQDM_DISCORD_CHANNEL_ID}].
mininterval : float, optional.
Minimum of [default: 1.5] to avoid rate limit.
See `tqdm.auto.tqdm.__init__` for other parameters.
"""
kwargs = deepcopy(kwargs)
self.dio = DiscordIO(
kwargs.pop('token', getenv("TQDM_DISCORD_TOKEN")),
kwargs.pop('channel_id', getenv("TQDM_DISCORD_CHANNEL_ID")))

kwargs['mininterval'] = max(1.5, kwargs.get('mininterval', 1.5))
super(tqdm_discord, self).__init__(*args, **kwargs)

def display(self, **kwargs):
super(tqdm_discord, self).display(**kwargs)
fmt = self.format_dict
if 'bar_format' in fmt and fmt['bar_format']:
fmt['bar_format'] = fmt['bar_format'].replace('<bar/>', '{bar}')
else:
fmt['bar_format'] = '{l_bar}{bar}{r_bar}'
fmt['bar_format'] = fmt['bar_format'].replace('{bar}', '{bar:10u}')
self.dio.write(self.format_meter(**fmt))

def __new__(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 = tqdm_auto._instances
except AttributeError:
pass
instance = super(tqdm_discord, cls).__new__(cls, *args, **kwargs)
with cls.get_lock():
try:
# `tqdm_auto` may have been changed so update
cls._instances.update(tqdm_auto._instances)
except AttributeError:
pass
tqdm_auto._instances = cls._instances
return instance


def tdrange(*args, **kwargs):
"""
A shortcut for `tqdm.contrib.discord.tqdm(xrange(*args), **kwargs)`.
On Python3+, `range` is used instead of `xrange`.
"""
return tqdm_discord(_range(*args), **kwargs)


# Aliases
tqdm = tqdm_discord
trange = tdrange
Loading

0 comments on commit 15c5c51

Please sign in to comment.