From c141e84ea2f2e8602e0534b5407b20c2fbc37bed Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Wed, 22 May 2024 21:32:34 +0200 Subject: [PATCH 1/5] Deprecate `python-telegram-bot-raw` --- README.rst | 10 ---------- README_RAW.rst | 13 ++++++++++--- telegram/__init__.py | 29 ++++++++++++++++++++++++++++- telegram/_utils/datetime.py | 2 +- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/README.rst b/README.rst index 76743bf0250..d9a61b5c95c 100644 --- a/README.rst +++ b/README.rst @@ -1,6 +1,3 @@ -.. - Make sure to apply any changes to this file to README_RAW.rst as well! - .. image:: https://raw.githubusercontent.com/python-telegram-bot/logos/master/logo-text/png/ptb-logo-text_768.png :align: center :target: https://python-telegram-bot.org @@ -79,13 +76,6 @@ In addition to the pure API implementation, this library features a number of hi make the development of bots easy and straightforward. These classes are contained in the ``telegram.ext`` submodule. -A pure API implementation *without* ``telegram.ext`` is available as the standalone package ``python-telegram-bot-raw``. `See here for details. `_ - -Note ----- - -Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conjunction will result in undesired side-effects, so only install *one* of both. - Telegram API support ==================== diff --git a/README_RAW.rst b/README_RAW.rst index 45f636bc2f7..073a44906b2 100644 --- a/README_RAW.rst +++ b/README_RAW.rst @@ -1,6 +1,3 @@ -.. - Make sure to apply any changes to this file to README.rst as well! - .. image:: https://github.com/python-telegram-bot/logos/blob/master/logo-text/png/ptb-raw-logo-text_768.png?raw=true :align: center :target: https://python-telegram-bot.org @@ -62,6 +59,16 @@ :target: https://telegram.me/pythontelegrambotgroup :alt: Telegram Group +⚠️ Deprecation Notice +===================== + +The ``python-telegram-bot-raw`` library will no longer be updated after NEXT.VERSION. +Please instead use the ``python-telegram-bot`` `library `_. +The change requires no changes in your code and requires no additional dependencies. +For additional information, please see this `channel post `_. + +--- + We have made you a wrapper you can't refuse We have a vibrant community of developers helping each other in our `Telegram group `_. Join us! diff --git a/telegram/__init__.py b/telegram/__init__.py index 5e0f3eaac3b..bc9bd4e4dc0 100644 --- a/telegram/__init__.py +++ b/telegram/__init__.py @@ -242,6 +242,7 @@ "warnings", ) +from pathlib import Path from . import _version, constants, error, helpers, request, warnings from ._birthdate import Birthdate @@ -384,7 +385,7 @@ from ._linkpreviewoptions import LinkPreviewOptions from ._loginurl import LoginUrl from ._menubutton import MenuButton, MenuButtonCommands, MenuButtonDefault, MenuButtonWebApp -from ._message import InaccessibleMessage, MaybeInaccessibleMessage, Message +from ._MESSAGE import InaccessibleMessage, MaybeInaccessibleMessage, Message from ._messageautodeletetimerchanged import MessageAutoDeleteTimerChanged from ._messageentity import MessageEntity from ._messageid import MessageId @@ -442,6 +443,7 @@ from ._update import Update from ._user import User from ._userprofilephotos import UserProfilePhotos +from ._utils.warnings import warn from ._videochat import ( VideoChatEnded, VideoChatParticipantsInvited, @@ -475,3 +477,28 @@ #: #: .. versionadded:: 20.0 __bot_api_version_info__: constants._BotAPIVersion = _version.__bot_api_version_info__ + + +if not (Path(__file__).resolve().absolute() / "ext").exists(): + _MESSAGE = ( + "Hey. You seem to be using the `python-telegram-bot-raw` library. " + "Please note that this libray has been deprecated and will no longer be updated. " + "Please instead use the `python-telegram-bot` library. The change requires no " + "changes in your code and requires no additional dependencies. For additional " + "information, please see the channel post at " + "https://t.me/pythontelegrambotchannel/1." + ) + + # DeprecationWarning is ignored by default in Python 3.7 and later by default outside + # __main__ modules. We use both warning categories to increase the chance of the user + # seeing the warning. + + warn( + warnings.PTBDeprecationWarning(version="NEXT.VERSION", message=_MESSAGE), + stacklevel=2, + ) + warn( + message=_MESSAGE, + category=warnings.PTBUserWarning, + stacklevel=2, + ) diff --git a/telegram/_utils/datetime.py b/telegram/_utils/datetime.py index 9790e27857d..1c0da085434 100644 --- a/telegram/_utils/datetime.py +++ b/telegram/_utils/datetime.py @@ -194,7 +194,7 @@ def extract_tzinfo_from_defaults(bot: "Bot") -> Union[dtm.tzinfo, None]: If the bot has no default values, :obj:`None` is returned. """ # We don't use `ininstance(bot, ExtBot)` here so that this works - # in `python-telegram-bot-raw` as well + # without the job-queue extra dependencies as well if hasattr(bot, "defaults") and bot.defaults: return bot.defaults.tzinfo return None From 3a0b324ee83548e4fca27fa812892172b12db85c Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Wed, 22 May 2024 21:59:44 +0200 Subject: [PATCH 2/5] Fix tests --- pyproject.toml | 1 + telegram/__init__.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b02870776ca..f262a7aef3e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,6 +56,7 @@ filterwarnings = [ "ignore::DeprecationWarning", 'ignore:Tasks created via `Application\.create_task` while the application is not running', "ignore::ResourceWarning", + "ignore:Hey. You seem to be using the `python-telegram-bot-raw` library:UserWarning", # TODO: Write so good code that we don't need to ignore ResourceWarnings anymore # Unfortunately due to https://github.com/pytest-dev/pytest/issues/8343 we can't have this here # and instead do a trick directly in tests/conftest.py diff --git a/telegram/__init__.py b/telegram/__init__.py index bc9bd4e4dc0..461801a4987 100644 --- a/telegram/__init__.py +++ b/telegram/__init__.py @@ -385,7 +385,7 @@ from ._linkpreviewoptions import LinkPreviewOptions from ._loginurl import LoginUrl from ._menubutton import MenuButton, MenuButtonCommands, MenuButtonDefault, MenuButtonWebApp -from ._MESSAGE import InaccessibleMessage, MaybeInaccessibleMessage, Message +from ._message import InaccessibleMessage, MaybeInaccessibleMessage, Message from ._messageautodeletetimerchanged import MessageAutoDeleteTimerChanged from ._messageentity import MessageEntity from ._messageid import MessageId From 7a434c0240ea6dd7e8238a22ffb227cfb4e12cc5 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Thu, 23 May 2024 22:27:29 +0200 Subject: [PATCH 3/5] Don't warn on ptb --- pyproject.toml | 1 - telegram/__init__.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f262a7aef3e..b02870776ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,7 +56,6 @@ filterwarnings = [ "ignore::DeprecationWarning", 'ignore:Tasks created via `Application\.create_task` while the application is not running', "ignore::ResourceWarning", - "ignore:Hey. You seem to be using the `python-telegram-bot-raw` library:UserWarning", # TODO: Write so good code that we don't need to ignore ResourceWarnings anymore # Unfortunately due to https://github.com/pytest-dev/pytest/issues/8343 we can't have this here # and instead do a trick directly in tests/conftest.py diff --git a/telegram/__init__.py b/telegram/__init__.py index 461801a4987..bc5c8e43b7b 100644 --- a/telegram/__init__.py +++ b/telegram/__init__.py @@ -479,7 +479,7 @@ __bot_api_version_info__: constants._BotAPIVersion = _version.__bot_api_version_info__ -if not (Path(__file__).resolve().absolute() / "ext").exists(): +if not (Path(__file__).parent.resolve().absolute() / "ext").exists(): _MESSAGE = ( "Hey. You seem to be using the `python-telegram-bot-raw` library. " "Please note that this libray has been deprecated and will no longer be updated. " From 6f95776d81baa31901fce1e7476d39f6ee205b05 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Thu, 23 May 2024 22:28:26 +0200 Subject: [PATCH 4/5] rendering fix --- README_RAW.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_RAW.rst b/README_RAW.rst index 073a44906b2..78c61d7030a 100644 --- a/README_RAW.rst +++ b/README_RAW.rst @@ -67,7 +67,7 @@ Please instead use the ``python-telegram-bot`` `library `_. ---- +---- We have made you a wrapper you can't refuse From 2e76829230c7949071a8f837c7613eda0cdbb005 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sat, 1 Jun 2024 20:55:48 +0200 Subject: [PATCH 5/5] Update Channel Post Link --- README_RAW.rst | 2 +- telegram/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README_RAW.rst b/README_RAW.rst index 78c61d7030a..64f83121e21 100644 --- a/README_RAW.rst +++ b/README_RAW.rst @@ -65,7 +65,7 @@ The ``python-telegram-bot-raw`` library will no longer be updated after NEXT.VERSION. Please instead use the ``python-telegram-bot`` `library `_. The change requires no changes in your code and requires no additional dependencies. -For additional information, please see this `channel post `_. +For additional information, please see this `channel post `_. ---- diff --git a/telegram/__init__.py b/telegram/__init__.py index bc5c8e43b7b..1230716e785 100644 --- a/telegram/__init__.py +++ b/telegram/__init__.py @@ -486,7 +486,7 @@ "Please instead use the `python-telegram-bot` library. The change requires no " "changes in your code and requires no additional dependencies. For additional " "information, please see the channel post at " - "https://t.me/pythontelegrambotchannel/1." + "https://t.me/pythontelegrambotchannel/145." ) # DeprecationWarning is ignored by default in Python 3.7 and later by default outside