From 3e21c84f59ed81308e42545a439ce8f432c096ac Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Fri, 6 Jan 2023 15:42:38 +0100 Subject: [PATCH] v2.1 --- .pre-commit-config.yaml | 15 +++++++++++---- CHANGES.rst | 10 +++++++++- README.rst | 4 ++-- docs/requirements-docs.txt | 6 +++--- docs/source/conf.py | 8 ++++---- ptbstats/_basestats.py | 4 ++-- ptbstats/_register.py | 6 +++--- ptbstats/_simplestats.py | 15 ++++++++++----- pyproject.toml | 7 ++++++- requirements-dev.txt | 2 +- requirements.txt | 4 ++-- setup.py | 2 +- 12 files changed, 54 insertions(+), 29 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bd12608..8210028 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: @@ -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 diff --git a/CHANGES.rst b/CHANGES.rst index d4fb893..4fa8c2d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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* diff --git a/README.rst b/README.rst index eae3bf6..e9fcee8 100644 --- a/README.rst +++ b/README.rst @@ -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 @@ -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 … diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index e84a534..a362999 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -1,3 +1,3 @@ -sphinx==5.3.0 -furo==2022.9.29 -sphinx_autodoc_typehints==1.19.5 \ No newline at end of file +sphinx==6.1.1 +furo==2022.12.7 +sphinx_autodoc_typehints==1.20.0 \ No newline at end of file diff --git a/docs/source/conf.py b/docs/source/conf.py index c472a0d..5584b5b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -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 --------------------------------------------------- @@ -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, } diff --git a/ptbstats/_basestats.py b/ptbstats/_basestats.py index 44daa87..026ed9b 100644 --- a/ptbstats/_basestats.py +++ b/ptbstats/_basestats.py @@ -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: diff --git a/ptbstats/_register.py b/ptbstats/_register.py index a05779a..d783ffb 100644 --- a/ptbstats/_register.py +++ b/ptbstats/_register.py @@ -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 @@ -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: @@ -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 diff --git a/ptbstats/_simplestats.py b/ptbstats/_simplestats.py index 7002661..8b14c1d 100644 --- a/ptbstats/_simplestats.py +++ b/ptbstats/_simplestats.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 701c856..ad628ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,4 +12,9 @@ disallow_untyped_defs = true disallow_incomplete_defs = true disallow_untyped_decorators = true show_error_codes = true -implicit_optional = true \ No newline at end of file +implicit_optional = true + +[tool.ruff] +fix = false +format = "grouped" +line-length = 99 diff --git a/requirements-dev.txt b/requirements-dev.txt index 609a4cd..6fab016 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1 +1 @@ -pre-commit~=2.20.0 \ No newline at end of file +pre-commit~=2.21.0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index e9934b3..72fd7bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -python-telegram-bot==20.0a0 -plotly==5.8.0 +python-telegram-bot~=20.0 +plotly~=5.11 diff --git a/setup.py b/setup.py index fd007be..d64e021 100644 --- a/setup.py +++ b/setup.py @@ -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/",