Skip to content

Updated to Python 3.12 #8539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
if: matrix.architecture != 'aarch64'
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'
architecture: ${{ matrix.architecture }}
cache: 'pip'
cache-dependency-path: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Setup Python 3.9
- name: Setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.12
cache: 'pip'
- run: python -m pip install -r requirements.txt
- name: Install mypy
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/periodic_unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
submodules: 'true'
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.12'
cache: 'pip'
- uses: actions/cache/restore@v4
id: restore_cache
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/pr-comment-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
needs: set_pending_status
strategy:
matrix:
os: [ubuntu-latest, windows-latest] # macos-latest not tested due to crashing.
version: ["3.9", "3.10"]
os: [ubuntu-latest, windows-latest, macos-latest]
version: ["3.12"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -29,6 +29,10 @@ jobs:
with:
path: src/libsodium.dll
key: cache_libsodium_dll
- shell: bash
if: matrix.os == 'macos-latest'
run: |
cp /opt/homebrew/opt/libsodium/lib/libsodium.dylib /Library/Frameworks/Python.framework/Versions/3.12/lib/libsodium.dylib
- run: python -m pip install -r requirements.txt
- run: |
cd src
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Setup Python 3.8
- name: Setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.12
- name: Install ruff
run: pip install ruff
- name: Get changed Python files
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
submodules: 'true'
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.12'
cache: 'pip'
- run: python -m pip install -r requirements.txt
- name: Run unit tests
Expand All @@ -24,7 +24,7 @@ jobs:
submodules: 'true'
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.12'
cache: 'pip'
- uses: actions/cache/restore@v4
id: restore_cache
Expand All @@ -45,12 +45,11 @@ jobs:
submodules: 'true'
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.12'
cache: 'pip'
- shell: bash
run: |
cp /opt/homebrew/opt/libsodium/lib/libsodium.dylib /Library/Frameworks/Python.framework/Versions/3.9/lib/libsodium.dylib
sed -i".backup" 's|libtorrent==2.0.9|https://tribler.org/libtorrent-2.0.11-cp39-cp39-macosx_14_0_arm64.whl|' requirements.txt
cp /opt/homebrew/opt/libsodium/lib/libsodium.dylib /Library/Frameworks/Python.framework/Versions/3.12/lib/libsodium.dylib
- run: python -m pip install -r requirements.txt
- name: Run unit tests
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/weekly_mutation_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
run: |
cd tribler
echo "NUM_COMMITS=$(git log --oneline --since '7 days ago' | wc -l)" >> $GITHUB_ENV
- name: Setup Python 3.10
- name: Setup Python 3.12
uses: actions/setup-python@v5
if: ${{ env.NUM_COMMITS > 0 }}
with:
python-version: '3.10'
python-version: '3.12'
cache: 'pip'
- name: Install dependencies
if: ${{ env.NUM_COMMITS > 0 }}
Expand Down
3 changes: 1 addition & 2 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ lint.ignore = [
"TRY300",
"TRY301",
"TRY401",
"UP006", # Backward compatibility, remove after Python >= 3.9
]

exclude = [
Expand Down Expand Up @@ -92,7 +91,7 @@ line-length = 120
# Allow unused variables when underscore-prefixed.
lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

target-version = "py39"
target-version = "py312"

[lint.pylint]
max-args = 6
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ This file is part of Tribler, Copyright 2004-2024. Tribler is licensed under the
:target: https://discord.gg/UpPUcVGESe
:alt: Join Discord chat

.. |python_3_10| image:: https://img.shields.io/badge/python-3.10-blue.svg
.. |python_3_12| image:: https://img.shields.io/badge/python-3.12-blue.svg
:target: https://www.python.org/

.. |flathub| image:: https://img.shields.io/flathub/downloads/org.tribler.Tribler
Expand Down
3 changes: 1 addition & 2 deletions build/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def read_requirements(file_name: str, directory: str = ".") -> list[str]:
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.12",
"Topic :: Communications :: File Sharing",
"Topic :: Security :: Cryptography",
"Operating System :: OS Independent",
Expand Down
2 changes: 1 addition & 1 deletion doc/.readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build:
os: ubuntu-22.04
tools:
# Check https://docs.readthedocs.io/en/stable/config-file/v2.html#build-tools-python
python: "3.10"
python: "3.12"
apt_packages:
- graphviz
jobs:
Expand Down
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[mypy]
ignore_missing_imports = True
python_version = 3.12
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
bitarray
configobj
ipv8-rust-tunnels
libtorrent==2.0.9
libtorrent==2.0.11
lz4
pillow
pony
Expand Down
3 changes: 0 additions & 3 deletions src/run_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"""
The unit tests on Mac lock up on multiprocess getaddrinfo calls. We establish the lan addresses once here before
spawning any children.

File "/Users/runner/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/socket.py", line 966, in getaddrinfo
| for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
"""
from ipv8.messaging.interfaces.lan_addresses.interfaces import get_lan_addresses
get_lan_addresses()
Expand Down
5 changes: 3 additions & 2 deletions src/tribler/core/content_discovery/cache.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import annotations

from binascii import hexlify
from typing import TYPE_CHECKING, Callable
from typing import TYPE_CHECKING, Self

from ipv8.requestcache import RandomNumberCache, RequestCache
from typing_extensions import Self

if TYPE_CHECKING:
from collections.abc import Callable

from ipv8.types import Peer

from tribler.core.database.store import ProcessingResult
Expand Down
6 changes: 3 additions & 3 deletions src/tribler/core/content_discovery/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from binascii import hexlify, unhexlify
from importlib.metadata import PackageNotFoundError, version
from itertools import count
from typing import TYPE_CHECKING, Any, Callable
from typing import TYPE_CHECKING, Any

from ipv8.community import Community, CommunitySettings
from ipv8.lazy_community import lazy_wrapper
Expand All @@ -27,10 +27,10 @@
from tribler.core.database.orm_bindings.torrent_metadata import LZ4_EMPTY_ARCHIVE, entries_to_chunk
from tribler.core.database.store import MetadataStore, ObjState, ProcessingResult
from tribler.core.notifier import Notification, Notifier
from tribler.core.torrent_checker.dataclasses import HealthInfo
from tribler.core.torrent_checker.healthdataclasses import HealthInfo

if TYPE_CHECKING:
from collections.abc import Sequence
from collections.abc import Callable, Sequence

from ipv8.types import Peer

Expand Down
5 changes: 2 additions & 3 deletions src/tribler/core/content_discovery/payload.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Self

from ipv8.messaging.lazy_payload import VariablePayload, vp_compile
from ipv8.messaging.serialization import default_serializer
from typing_extensions import Self

if TYPE_CHECKING:
from tribler.core.torrent_checker.dataclasses import HealthInfo
from tribler.core.torrent_checker.healthdataclasses import HealthInfo


@vp_compile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from aiohttp_apispec import docs, querystring_schema
from ipv8.REST.schema import schema
from marshmallow.fields import Integer, List, String
from typing_extensions import TypeAlias

from tribler.core.database.queries import to_fts_query
from tribler.core.database.restapi.database_endpoint import DatabaseEndpoint
Expand All @@ -18,7 +17,7 @@
from tribler.core.content_discovery.community import ContentDiscoveryCommunity
from tribler.core.restapi.rest_manager import TriblerRequest

RequestType: TypeAlias = TriblerRequest[tuple[ContentDiscoveryCommunity]]
type RequestType = TriblerRequest[tuple[ContentDiscoveryCommunity]]


class RemoteQueryParameters(MetadataParameters):
Expand Down
3 changes: 1 addition & 2 deletions src/tribler/core/database/orm_bindings/torrent_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
from binascii import hexlify, unhexlify
from datetime import datetime
from struct import unpack
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Self

from lz4.frame import LZ4FrameCompressor
from pony import orm
from pony.orm import Database, db_session
from typing_extensions import Self

from tribler.core.database.serialization import (
EPOCH,
Expand Down
5 changes: 2 additions & 3 deletions src/tribler/core/database/orm_bindings/torrent_state.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Self

from pony import orm
from typing_extensions import Self

from tribler.core.torrent_checker.dataclasses import HealthInfo
from tribler.core.torrent_checker.healthdataclasses import HealthInfo

if TYPE_CHECKING:
from dataclasses import dataclass
Expand Down
4 changes: 2 additions & 2 deletions src/tribler/core/database/restapi/database_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import json
import typing
from binascii import unhexlify
from typing import Self

from aiohttp import web
from aiohttp_apispec import docs, querystring_schema
from ipv8.REST.schema import schema
from marshmallow.fields import Boolean, Integer, String
from pony.orm import db_session
from typing_extensions import Self, TypeAlias

from tribler.core.database.queries import to_fts_query
from tribler.core.database.restapi.schema import MetadataSchema, SearchMetadataParameters, TorrentSchema
Expand All @@ -31,7 +31,7 @@
from tribler.core.restapi.rest_manager import TriblerRequest
from tribler.core.torrent_checker.torrent_checker import TorrentChecker

RequestType: TypeAlias = TriblerRequest[tuple[MetadataStore]]
type RequestType = TriblerRequest[tuple[MetadataStore]]

TORRENT_CHECK_TIMEOUT = 20

Expand Down
3 changes: 1 addition & 2 deletions src/tribler/core/database/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import struct
from binascii import hexlify
from datetime import datetime, timedelta
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Self

from ipv8.keyvault.crypto import default_eccrypto
from ipv8.messaging.lazy_payload import VariablePayload, vp_compile
from ipv8.messaging.serialization import VarLenUtf8, default_serializer
from typing_extensions import Self

if TYPE_CHECKING:
from ipv8.types import PrivateKey
Expand Down
7 changes: 4 additions & 3 deletions src/tribler/core/database/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from os.path import getsize
from pathlib import Path
from time import sleep, time
from typing import TYPE_CHECKING, Any, Callable
from typing import TYPE_CHECKING, Any

from lz4.frame import LZ4FrameDecompressor
from pony import orm
Expand All @@ -30,9 +30,10 @@
TorrentMetadataPayload,
read_payload_with_offset,
)
from tribler.core.torrent_checker.dataclasses import HealthInfo
from tribler.core.torrent_checker.healthdataclasses import HealthInfo

if TYPE_CHECKING:
from collections.abc import Callable
from sqlite3 import Connection

from ipv8.types import PrivateKey
Expand Down Expand Up @@ -395,7 +396,7 @@ def process_squashed_mdblob(self, chunk_data: bytes, external_thread: bool = Fal

if health_info and len(health_info) == len(payload_list):
with db_session:
for payload, (seeders, leechers, last_check) in zip(payload_list, health_info):
for payload, (seeders, leechers, last_check) in zip(payload_list, health_info, strict=False):
if hasattr(payload, "infohash"):
health = HealthInfo(payload.infohash, last_check=last_check,
seeders=seeders, leechers=leechers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import math
from asyncio import Future
from binascii import hexlify
from typing import Awaitable
from typing import TYPE_CHECKING

import libtorrent as lt
from ipv8.taskmanager import TaskManager

from tribler.core.torrent_checker.dataclasses import HealthInfo
from tribler.core.torrent_checker.healthdataclasses import HealthInfo

if TYPE_CHECKING:
from collections.abc import Awaitable


class DHTHealthManager(TaskManager):
Expand Down
Loading