Skip to content

Commit

Permalink
Drop support for python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akhmetov committed Jun 22, 2024
1 parent e30f7dc commit 1c7b5c4
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 1 addition & 15 deletions telegram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)

Expand Down
5 changes: 2 additions & 3 deletions telegram/tdjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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:
Expand Down
51 changes: 21 additions & 30 deletions tests/test_tdjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 1c7b5c4

Please sign in to comment.