Skip to content

Commit

Permalink
v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibo-Joshi committed Jan 6, 2023
1 parent 3ffc01f commit 3e21c84
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 29 deletions.
15 changes: 11 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ repos:
# run pylint across multiple cpu cores to speed it up-
- --jobs=0 # See https://pylint.pycqa.org/en/latest/user_guide/run.html?#parallel-execution to know more
additional_dependencies:
- python-telegram-bot==20.0a0
- plotly==5.8.0
- python-telegram-bot~=20.0
- plotly~=5.11
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
files: ^ptbstats/.*\.py$
additional_dependencies:
- python-telegram-bot==20.0a0
- plotly==5.8.0
- python-telegram-bot~=20.0
- plotly~=5.11
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
Expand All @@ -47,3 +47,10 @@ repos:
args:
- --diff
- --check
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.210
hooks:
- id: ruff
additional_dependencies:
- python-telegram-bot~=20.0
- plotly~=5.11
10 changes: 9 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
Changelog
=========

Version 2.1
===========
*Released 2013-01-06*

* Upgrades ``python-telegram-bot`` to ``~=20.0``
* Upgrades ``plotly`` to ``~=5.11``
* Fix a bug where all ``SimpleStats`` instances would override each other's stored data

Version 2.0.2
=============
*Released 2022-05-22*

* Fix a bug in ``SimpleStats``

Version 2.0.2
Version 2.0.1
=============
*Released 2022-05-22*

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PTB Stats
:target: https://www.python.org/doc/versions/
:alt: Supported Python versions

.. image:: https://img.shields.io/badge/python--telegram--bot-20.0a0-blue
.. image:: https://img.shields.io/badge/python--telegram--bot-20.0-blue
:target: https://python-telegram-bot.org/
:alt: Supported PTB versions

Expand All @@ -24,7 +24,7 @@ Installation

Install via::

pip install git+https://github.com/Bibo-Joshi/ptbstats.git@v2.0.2
pip install git+https://github.com/Bibo-Joshi/ptbstats.git@v2.1

``ptbstats`` does not have a proper package (yet), because the author is too lazy for unittests and stuff …

Expand Down
6 changes: 3 additions & 3 deletions docs/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sphinx==5.3.0
furo==2022.9.29
sphinx_autodoc_typehints==1.19.5
sphinx==6.1.1
furo==2022.12.7
sphinx_autodoc_typehints==1.20.0
8 changes: 4 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
# -- Project information -----------------------------------------------------

project = "PTB Stats"
copyright = "2020, Hinrich Mahler"
copyright = "2020-2023, Hinrich Mahler"
author = "Hinrich Mahler"
master_doc = "index"
version = "2.0.2"
release = "2.0.2"
version = "2.1"
release = "2.1"


# -- General configuration ---------------------------------------------------
Expand All @@ -41,7 +41,7 @@

# Use intersphinx to reference the python-telegram-bot docs
intersphinx_mapping = {
"telegram": ("https://python-telegram-bot.readthedocs.io/en/v20.0a0/", None),
"telegram": ("https://python-telegram-bot.readthedocs.io/en/stable/", None),
"https://docs.python.org/": None,
}

Expand Down
4 changes: 2 additions & 2 deletions ptbstats/_basestats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from typing import Any, Optional, TypeVar

from telegram import Update
from telegram.ext import Application, CallbackContext, Handler
from telegram.ext import Application, BaseHandler, CallbackContext

_CCT = TypeVar("_CCT", bound=CallbackContext)


class BaseStats(Handler[Update, _CCT], ABC):
class BaseStats(BaseHandler[Update, _CCT], ABC):
"""Base class for storing and displaying statistics.
Warning:
Expand Down
6 changes: 3 additions & 3 deletions ptbstats/_register.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
"""Module providing the :meth:`register_stats` method."""
from typing import List, Union
from typing import Sequence, Union

from telegram.ext import Application, CommandHandler, filters

Expand All @@ -19,7 +19,7 @@ def set_application(application: Application) -> None:

def register_stats(
stats: BaseStats,
admin_id: Union[int, List[int]] = None,
admin_id: Union[int, Sequence[int]] = None,
stats_group: int = None,
command_group: int = None,
) -> None:
Expand All @@ -28,7 +28,7 @@ def register_stats(
:meth:`set_application`:
1. The ``stats`` handler. By default, each of those handlers will get it's own group,
starting with -10e10. That should be enough to not interfere with your other handlers.
starting with -10e10. That should be enough to not interfere with your other handlers.
2. A :class:`telegram.ext.CommandHandler` that will listen for ``command`` and call
``stats.reply_statistics`` to report the current statistics. By default, all those
command handlers will be added to group 0. If you register the statistics before your other
Expand Down
15 changes: 10 additions & 5 deletions ptbstats/_simplestats.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,25 @@ async def _reply_statistics(self, update: Update) -> None:
stream.seek(0)

await update.effective_message.reply_document( # type: ignore[union-attr]
stream.read().encode("utf-8"), filename=f"{self.command}.html"
stream.read().encode("utf-8"),
filename=f"{self.command}.html",
read_timeout=60,
write_timeout=60,
)

def store_data(self, context: _CCT) -> None:
"""Persists :attr:`records`.
Assumes that ``context.bot_data`` is a dict and stores the data in
``context.bot_data['SimpleStats']``. Override to customize the behavior.
``context.bot_data['SimpleStats'][self.command]``. Override to customize the behavior.
"""
context.bot_data["SimpleStats"] = self.records
context.bot_data["SimpleStats"][self.command] = self.records

def load_data(self, application: Application[Any, _CCT, Any, Any, Any, Any]) -> None:
"""Loads the data stored by :meth:`store_data`.
Assumes that ``context.bot_data`` is a dict and loads the data from
``application.bot_data['SimpleStats']``. Override to customize the behavior.
"""
if "SimpleStats" in application.bot_data:
self.records = application.bot_data["SimpleStats"]
try:
self.records = application.bot_data["SimpleStats"][self.command]
except KeyError:
pass
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ disallow_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_decorators = true
show_error_codes = true
implicit_optional = true
implicit_optional = true

[tool.ruff]
fix = false
format = "grouped"
line-length = 99
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pre-commit~=2.20.0
pre-commit~=2.21.0
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
python-telegram-bot==20.0a0
plotly==5.8.0
python-telegram-bot~=20.0
plotly~=5.11
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def requirements() -> List[str]:

setup(
name="ptbstats",
version="2.0.2",
version="2.1",
author="Hinrich Mahler",
author_email="ptbstats@mahlerhome.de",
url="https://Bibo-Joshi.github.io/ptbstats/",
Expand Down

0 comments on commit 3e21c84

Please sign in to comment.