From 1c7b5c4818a10b4d01ffea22f4b6c9542eca3448 Mon Sep 17 00:00:00 2001 From: Alexander Akhmetov Date: Sun, 23 Jun 2024 00:01:04 +0200 Subject: [PATCH] Drop support for python 3.8 --- .github/workflows/tests.yml | 2 +- CONTRIBUTING.md | 2 +- README.md | 2 +- docs/source/changelog.rst | 2 +- docs/source/index.rst | 2 +- pyproject.toml | 2 +- telegram/client.py | 16 +----------- telegram/tdjson.py | 5 ++-- tests/test_tdjson.py | 51 +++++++++++++++---------------------- tox.ini | 3 +-- 10 files changed, 31 insertions(+), 56 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 873c231c..bebb76c2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,7 +8,7 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 46503bf8..5ce0371b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,5 +38,5 @@ tox Run a specific test using python 3.12: ```shell -tox -e py311 -- -k test_add_message_handler +tox -e py312 -- -k test_add_message_handler ``` diff --git a/README.md b/README.md index 27ce2246..bcbb1722 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ It helps you build your own Telegram clients. ## Installation -This library requires Python 3.8+ and Linux or MacOS. Windows is not supported. +This library requires Python 3.9+ and Linux or MacOS. Windows is not supported. ```shell pip install python-telegram diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index ddcb2ffc..615dd85c 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -4,7 +4,7 @@ Changelog [unreleased] -- Python 3.7 is no longer supported. +- Python versions 3.7 and 3.8 are no longer supported. [0.18.0] - 2023-03-13 diff --git a/docs/source/index.rst b/docs/source/index.rst index edaa9bca..f6dc6aee 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -35,7 +35,7 @@ After building the library, you need to install it: Library installation ~~~~~~~~~~~~~~~~~~~~ -This library requires Python 3.8 or higher. +This library requires Python 3.9 or higher. .. code-block:: bash diff --git a/pyproject.toml b/pyproject.toml index 061e674c..d46f0b78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,5 +4,5 @@ build-backend = "setuptools.build_meta" [tool.black] line-length = 119 -target_version = ['py38', 'py39', 'py310', 'py311', 'py312'] +target_version = ['py39', 'py310', 'py311', 'py312'] skip-string-normalization = true diff --git a/telegram/client.py b/telegram/client.py index 9c8755a5..7d5ca1d6 100644 --- a/telegram/client.py +++ b/telegram/client.py @@ -10,17 +10,7 @@ import threading import tempfile from pathlib import Path -from typing import ( - Any, - Dict, - List, - Type, - Callable, - Optional, - DefaultDict, - Union, - Tuple, -) +from typing import Any, Dict, List, Type, Callable, Optional, DefaultDict, Union, Tuple, Literal from types import FrameType from collections import defaultdict import enum @@ -31,10 +21,6 @@ from telegram.worker import BaseWorker, SimpleWorker from telegram.text import Element -if sys.version_info >= (3, 8): # Backwards compatibility for python < 3.8 - from typing import Literal -else: - from typing_extensions import Literal logger = logging.getLogger(__name__) diff --git a/telegram/tdjson.py b/telegram/tdjson.py index eb5fb22c..33bc5e87 100644 --- a/telegram/tdjson.py +++ b/telegram/tdjson.py @@ -4,8 +4,7 @@ import ctypes.util from ctypes import CDLL, CFUNCTYPE, c_int, c_char_p, c_double, c_void_p, c_longlong from typing import Any, Dict, Optional, Union - -import pkg_resources +import importlib.resources logger = logging.getLogger(__name__) @@ -21,7 +20,7 @@ def _get_tdjson_lib_path() -> str: else: lib_name = 'linux/libtdjson.so' - return pkg_resources.resource_filename('telegram', f'lib/{lib_name}') + return importlib.resources.files('telegram').joinpath(f'lib/{lib_name}') class TDJson: diff --git a/tests/test_tdjson.py b/tests/test_tdjson.py index ec59a219..b71cdea2 100644 --- a/tests/test_tdjson.py +++ b/tests/test_tdjson.py @@ -6,48 +6,39 @@ class TestGetTdjsonTdlibPath: def test_for_darwin(self): mocked_system = Mock(return_value='Darwin') - mocked_resource = Mock() - mocked_find_library = Mock(return_value=None) + mocked_files = Mock() + mocked_joinpath = Mock() with patch('telegram.tdjson.platform.system', mocked_system): - with patch('telegram.tdjson.pkg_resources.resource_filename', mocked_resource): - with patch('telegram.tdjson.ctypes.util.find_library', mocked_find_library): - _get_tdjson_lib_path() + with patch('importlib.resources.files', mocked_files): + mocked_files.return_value.joinpath = mocked_joinpath + _get_tdjson_lib_path() - mocked_resource.assert_called_once_with('telegram', 'lib/darwin/libtdjson.dylib') + mocked_files.assert_called_once_with('telegram') + mocked_joinpath.assert_called_once_with('lib/darwin/libtdjson.dylib') def test_for_linux(self): mocked_system = Mock(return_value='Linux') - mocked_resource = Mock(return_value='/tmp/') - mocked_find_library = Mock(return_value=None) + mocked_files = Mock() + mocked_joinpath = Mock() with patch('telegram.tdjson.platform.system', mocked_system): - with patch('telegram.tdjson.pkg_resources.resource_filename', mocked_resource): - with patch('telegram.tdjson.ctypes.util.find_library', mocked_find_library): - _get_tdjson_lib_path() + with patch('importlib.resources.files', mocked_files): + mocked_files.return_value.joinpath = mocked_joinpath + _get_tdjson_lib_path() - mocked_resource.assert_called_once_with('telegram', 'lib/linux/libtdjson.so') - - def test_for_windows(self): - mocked_system = Mock(return_value='Windows') - mocked_resource = Mock(return_value='/tmp/') - mocked_find_library = Mock(return_value=None) - - with patch('telegram.tdjson.platform.system', mocked_system): - with patch('telegram.tdjson.pkg_resources.resource_filename', mocked_resource): - with patch('telegram.tdjson.ctypes.util.find_library', mocked_find_library): - _get_tdjson_lib_path() - - mocked_resource.assert_called_once_with('telegram', 'lib/linux/libtdjson.so') + mocked_files.assert_called_once_with('telegram') + mocked_joinpath.assert_called_once_with('lib/linux/libtdjson.so') def test_unknown(self): mocked_system = Mock(return_value='Unknown') - mocked_resource = Mock(return_value='/tmp/') - mocked_find_library = Mock(return_value=None) + mocked_files = Mock() + mocked_joinpath = Mock() with patch('telegram.tdjson.platform.system', mocked_system): - with patch('telegram.tdjson.pkg_resources.resource_filename', mocked_resource): - with patch('telegram.tdjson.ctypes.util.find_library', mocked_find_library): - _get_tdjson_lib_path() + with patch('importlib.resources.files', mocked_files): + mocked_files.return_value.joinpath = mocked_joinpath + _get_tdjson_lib_path() - mocked_resource.assert_called_once_with('telegram', 'lib/linux/libtdjson.so') + mocked_files.assert_called_once_with('telegram') + mocked_joinpath.assert_called_once_with('lib/linux/libtdjson.so') diff --git a/tox.ini b/tox.ini index 737e5474..0e7d5c2e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,9 @@ [tox] ignore_basepython_conflict = true -envlist = mypy,flake8,pylint,py38,py39,py310,py311 +envlist = mypy,flake8,pylint,py39,py310,py311,py312 [gh-actions] python = - 3.8: py38 3.9: py39 3.10: py310 3.11: py311