From 81ed2210ab12f8bece3506800ce0ff01bd7ca2c5 Mon Sep 17 00:00:00 2001 From: benoit74 Date: Thu, 22 Oct 2026 12:50:30 +0000 Subject: [PATCH] Drop Python 3.10 support, add Python 3.15 support Bump requires-python to >=3.11,<3.16, update CI matrices, and align black/ruff/pyright target versions to py315. Modernize libzim.pyx annotations to PEP 604/585 syntax (str | bytes, dict[...], etc.) now that the minimum supported version makes them unconditionally available. Also bump the docs build (Read the Docs config and CI job) to Python 3.14 and ubuntu-26.04, aligning it with the rest of the CI matrix and with the highest versions currently supported by Read the Docs. --- .github/workflows/QA.yaml | 2 +- .github/workflows/Tests.yaml | 8 ++++---- .readthedocs.yaml | 4 ++-- CHANGELOG.md | 3 +++ libzim/libzim.pyx | 25 +++++++++++++------------ pyproject.toml | 12 ++++++------ 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/.github/workflows/QA.yaml b/.github/workflows/QA.yaml index 9f25c467..3624908a 100644 --- a/.github/workflows/QA.yaml +++ b/.github/workflows/QA.yaml @@ -18,7 +18,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v7 with: - python-version: "3.14" + python-version: "3.15" architecture: x64 - name: Install dependencies (and project) diff --git a/.github/workflows/Tests.yaml b/.github/workflows/Tests.yaml index 9807a33f..68287cc4 100644 --- a/.github/workflows/Tests.yaml +++ b/.github/workflows/Tests.yaml @@ -17,7 +17,7 @@ jobs: strategy: matrix: os: [macos-15, macos-26, macos-15-intel, macos-26-intel, windows-2022, windows-2025, ubuntu-22.04, ubuntu-24.04, ubuntu-26.04] - python: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"] + python: ["3.11", "3.12", "3.13", "3.14", "3.14t", "3.15", "3.15t"] steps: - uses: actions/checkout@v7 @@ -43,14 +43,14 @@ jobs: run: inv coverage --args "-vvv" - name: Upload coverage report to codecov - if: matrix.os == 'ubuntu-26.04' && matrix.python == '3.14' + if: matrix.os == 'ubuntu-26.04' && matrix.python == '3.15' uses: codecov/codecov-action@v7 with: fail_ci_if_error: true token: ${{ secrets.CODECOV_TOKEN }} build-docs: # validate that doc can be built - runs-on: ubuntu-24.04 + runs-on: ubuntu-26.04 steps: - uses: actions/checkout@v7 @@ -58,7 +58,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v7 with: - python-version: "3.13" + python-version: "3.14" - name: Install dependencies run: | diff --git a/.readthedocs.yaml b/.readthedocs.yaml index c4022601..ae5a249b 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -4,9 +4,9 @@ version: 2 build: - os: ubuntu-24.04 + os: ubuntu-26.04 tools: - python: '3.13' + python: '3.14' # custom commands to run mkdocs build within hatch, as suggested by maintainer in # https://github.com/readthedocs/readthedocs.org/issues/10706 diff --git a/CHANGELOG.md b/CHANGELOG.md index e09aff9e..d9621761 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,10 +18,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Breaking**: `Search.getResults()` renamed `Search.get_results()` (#200) - **Breaking**: `SuggestionSearch.getEstimatedMatches()` renamed `SuggestionSearch.get_estimated_matches()` (#200) - **Breaking**: `SuggestionSearch.getResults()` renamed `SuggestionSearch.get_results()` (#200) +- Modernize type hints in `libzim.pyx` to use PEP 604/585 syntax (e.g. `str | bytes`, `dict[...]`) instead of `typing.Union`/`typing.Dict`/etc. (#281) ### Removed - **Breaking**: `Creator.add_metadata` no longer auto-converts a `Date` metadata value passed as `datetime.date`/`datetime.datetime`; pass pre-formatted `str`/`bytes` instead (#188) +- **Breaking**: Drop support for Python 3.10 (#281) ### Fixed @@ -30,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add a CI job building the documentation on every PR/push so this kind of breakage is caught automatically (#279) +- Add support for Python 3.15 (#281) ## [3.13.1] - 2026-10-05 diff --git a/libzim/libzim.pyx b/libzim/libzim.pyx index 9ef86baa..a194ae6d 100644 --- a/libzim/libzim.pyx +++ b/libzim/libzim.pyx @@ -42,8 +42,9 @@ import sys import traceback import warnings from collections import OrderedDict +from collections.abc import Generator, Iterator from types import ModuleType -from typing import Dict, Generator, Iterator, List, Optional, Set, TextIO, Tuple, Union +from typing import TextIO from uuid import UUID from cpython.buffer cimport PyBUF_WRITABLE @@ -223,7 +224,7 @@ cdef class WritingBlob: cdef zim.Blob c_blob cdef bytes ref_content - def __cinit__(self, content: Union[str, bytes]): + def __cinit__(self, content: str | bytes): if isinstance(content, str): self.ref_content = content.encode('UTF-8') else: @@ -346,7 +347,7 @@ class BaseWritingItem: """ raise NotImplementedError("get_contentprovider must be implemented.") - def get_hints(self) -> Dict[Hint, pyint]: + def get_hints(self) -> dict[Hint, pyint]: """Get the Hints that help the Creator decide how to handle this item. Hints affects compression, presence in suggestion, random and search. @@ -540,7 +541,7 @@ cdef class _Creator: with nogil: self.c_creator.addMetadata(_name, _content, _mimetype) - def add_redirection(self, str path: str, str title: str, str target_path: str, dict hints: Dict[Hint, pyint]): + def add_redirection(self, str path: str, str title: str, str target_path: str, dict hints: dict[Hint, pyint]): """Add redirection entry to the archive. Refer to https://wiki.openzim.org/wiki/ZIM_file_format#Redirect_Entry for more details. @@ -565,7 +566,7 @@ cdef class _Creator: with nogil: self.c_creator.addRedirection(_path, _title, _targetPath, _hints) - def add_alias(self, str path: str, str title: str, str target_path: str, dict hints: Dict[Hint, pyint]): + def add_alias(self, str path: str, str title: str, str target_path: str, dict hints: dict[Hint, pyint]): """Alias the (existing) entry `target_path` as a new entry `path`. Args: @@ -615,7 +616,7 @@ class StringProvider(ContentProvider): """ContentProvider for a single encoded-or-not UTF-8 string.""" __module__ = writer_module_name - def __init__(self, content: Union[str, bytes]): + def __init__(self, content: str | bytes): super().__init__() self.content = content.encode("UTF-8") if isinstance(content, str) else content @@ -630,7 +631,7 @@ class FileProvider(ContentProvider): """ContentProvider for a file using its local path.""" __module__ = writer_module_name - def __init__(self, filepath: Union[pathlib.Path, str]): + def __init__(self, filepath: pathlib.Path | str): super().__init__() self.filepath = filepath self.size = os.path.getsize(self.filepath) @@ -698,7 +699,7 @@ class IndexData: raise NotImplementedError("get_wordcount must be implemented.") - def get_geoposition(self) -> Optional[Tuple[float, float]]: + def get_geoposition(self) -> tuple[float, float] | None: """GeoPosition used to index the item. Returns: @@ -711,13 +712,13 @@ class IndexData: class Creator(_Creator): """Creator to create ZIM files.""" __module__ = writer_module_name - def config_compression(self, compression: Union[Compression, str]): + def config_compression(self, compression: Compression | str): if not isinstance(compression, Compression): compression = getattr(Compression, compression.lower()) return super().config_compression(compression) def add_metadata( - self, name: str, content: Union[str, bytes], + self, name: str, content: str | bytes, mimetype: str = "text/plain;charset=UTF-8" ): if isinstance(content, str): @@ -1116,7 +1117,7 @@ cdef class Archive: return Entry.from_entry(move(entry)) @property - def metadata_keys(self) -> List[str]: + def metadata_keys(self) -> list[str]: """List of Metadata keys present in this archive. Returns: @@ -1301,7 +1302,7 @@ cdef class Archive: """ return self.c_archive.getMediaCount() - def get_illustration_sizes(self) -> Set[pyint]: + def get_illustration_sizes(self) -> set[pyint]: """Sizes for which an illustration is available (@1 scale only). .. deprecated:: 3.8.0 diff --git a/pyproject.toml b/pyproject.toml index d631172f..49de6f57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta" [project] name = "libzim" version = "4.0.0-dev0" -requires-python = ">=3.10,<3.15" +requires-python = ">=3.11,<3.16" description = "A python-facing API for creating and interacting with ZIM files" authors = [ {name = "openZIM", email = "dev@kiwix.org"}, @@ -30,11 +30,11 @@ classifiers = [ "Intended Audience :: Developers", "Programming Language :: Cython", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", + "Programming Language :: Python :: 3.15", "Typing :: Stubs Only", "Operating System :: MacOS", "Operating System :: POSIX", @@ -165,7 +165,7 @@ features = ["scripts", "test"] PROFILE = "1" [[tool.hatch.envs.test.matrix]] -python = ["3.10", "3.11", "3.12", "3.13", "3.14"] +python = ["3.11", "3.12", "3.13", "3.14", "3.15"] [tool.hatch.envs.test.scripts] run = "inv test --args '{args}'" @@ -203,10 +203,10 @@ all = "inv checkall --args '{args}'" [tool.black] line-length = 88 -target-version = ['py314'] +target-version = ['py315'] [tool.ruff] -target-version = "py314" +target-version = "py315" line-length = 88 src = ["src"] @@ -333,6 +333,6 @@ exclude_lines = [ [tool.pyright] include = ["libzim", "tests", "tasks.py"] exclude = [".env/**", ".venv/**"] -pythonVersion = "3.14" +pythonVersion = "3.15" typeCheckingMode="basic" disableBytesTypePromotions = true