Skip to content

Commit

Permalink
Add support for Python 3.13 (#640)
Browse files Browse the repository at this point in the history
* fix: rename deprecated typing._collect_parameters (Python 3.13)

* chore: update ci actions

* chore: add Python 3.13 classifier

* chore: update cython to 3.0.11

* fix: make scripts/cythonize.sh executable

* fix: add setuptools as build dependency for 3.12+

* chore: update build-system

* chore: update pycln to v2.4.0

* chore: update test requirements to avoid DeprecationWarnings

* chore: update pydantic test requirements to avoid DeprecationWarning

* chore: update codecov-action to v4
  • Loading branch information
cdce8p authored Sep 29, 2024
1 parent d48cc01 commit f3de16a
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 43 deletions.
24 changes: 15 additions & 9 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ jobs:
- uses: actions/checkout@v4
- run: scripts/cythonize.sh
- run: pipx run build --sdist
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: dist
name: dist-sdist
path: dist/*.tar.gz
build_pure_wheel:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: scripts/cythonize.sh
- run: NO_EXTENSION=1 pipx run build
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: dist
name: dist-wheel
path: dist/*.whl
build_wheels:
name: Wheel on ${{ matrix.os }}
Expand All @@ -34,9 +34,14 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12 (MacOS)
if: matrix.os == 'macos-latest'
uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: scripts/cythonize.sh
- run: scripts/generate_tests_from_examples.py
- uses: pypa/cibuildwheel@v2.16.2
- uses: pypa/cibuildwheel@v2.21.1
env:
CIBW_SKIP: pp*
CIBW_TEST_COMMAND: pytest {project}/tests
Expand All @@ -45,19 +50,20 @@ jobs:
CIBW_BEFORE_TEST: pip install -r tests/requirements.txt
# TODO is skipping still necessary?
CIBW_TEST_SKIP: "*universal2:arm64"
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: dist
name: dist-${{ matrix.os }}
path: wheelhouse/*.whl
publish:
needs: [build_sdist, build_wheels]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: dist
path: dist
pattern: dist-*
merge-multiple: true
- uses: pypa/[email protected]
with:
password: ${{ secrets.PYPI_TOKEN }}
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', 'pypy-3.9', 'pypy-3.10']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13-dev', 'pypy-3.9', 'pypy-3.10']
include:
- python-version: '3.12'
pytest-args: --cov=apischema --cov-branch --cov-report=xml --cov-report=html
steps:
- uses: actions/cache@v3.3.2
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('tests/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install requirements
Expand All @@ -46,10 +46,10 @@ jobs:
run: scripts/generate_tests_from_examples.py
- name: Run tests
run: pytest tests ${{ matrix.pytest-args }}
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
# https://github.community/t/run-step-if-file-exists/16445/3
if: hashFiles('coverage.xml') != ''
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: hashFiles('coverage.xml') != ''
with:
name: coverage
Expand Down
33 changes: 16 additions & 17 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ jobs:
run_benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/cache@v3.3.2
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('tests/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Cythonize
Expand All @@ -44,49 +44,49 @@ jobs:
run: pip install -r benchmark/requirements.txt
- name: Run benchmark
run: python benchmark/main.py
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: benchmark_table
path: examples/benchmark_table.md
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: benchmark_chart_light
path: docs/benchmark_chart_light.svg
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: benchmark_chart_dark
path: docs/benchmark_chart_dark.svg
upload_doc:
needs: [run_benchmark]
runs-on: ubuntu-latest
steps:
- uses: actions/cache@v3.3.2
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('tests/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: benchmark_table
path: examples
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: benchmark_chart_light
path: docs
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: benchmark_chart_dark
path: docs
- name: Install requirements
run: pip install -r docs/requirements.txt
- name: Build documentation
run: mkdocs build
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: documentation
path: site/**
Expand All @@ -95,26 +95,26 @@ jobs:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'release'
steps:
- uses: actions/cache@v3.3.2
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('tests/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
# TODO bump to 3.12 when mike will support it
python-version: '3.11'
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: benchmark_table
path: examples
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: benchmark_chart_light
path: docs
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: benchmark_chart_dark
path: docs
Expand Down Expand Up @@ -149,4 +149,3 @@ jobs:
git add versions.json
git commit -m "sort versions.json"
git push origin gh-pages
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
language: system
types: [python]
- repo: https://github.com/hadialqattan/pycln
rev: v2.3.0
rev: v2.4.0
hooks:
- id: pycln
- repo: https://github.com/pycqa/isort
Expand Down
10 changes: 6 additions & 4 deletions apischema/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ def get_args(tp):
return res


if sys.version_info >= (3, 11):
from typing import _collect_parameters # type: ignore
if sys.version_info >= (3, 13):
from typing import _collect_type_parameters
elif sys.version_info >= (3, 11):
from typing import _collect_parameters as _collect_type_parameters # type: ignore
else:
from typing import _collect_type_vars as _collect_parameters
from typing import _collect_type_vars as _collect_type_parameters


def _generic_mro(result, tp):
Expand All @@ -68,7 +70,7 @@ def _generic_mro(result, tp):
origin = tp
result[origin] = tp
if hasattr(origin, "__orig_bases__"):
parameters = _collect_parameters(origin.__orig_bases__)
parameters = _collect_type_parameters(origin.__orig_bases__)
substitution = dict(zip(parameters, get_args(tp)))
for base in origin.__orig_bases__:
if get_origin(base) in result:
Expand Down
4 changes: 2 additions & 2 deletions apischema/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from apischema.types import COLLECTION_TYPES, MAPPING_TYPES, PRIMITIVE_TYPES, AnyType
from apischema.typing import (
_collect_parameters,
_collect_type_parameters,
generic_mro,
get_args,
get_origin,
Expand Down Expand Up @@ -125,7 +125,7 @@ def get_parameters(tp: AnyType) -> Iterable[TV]:
if hasattr(tp, "__parameters__"):
return tp.__parameters__
elif hasattr(tp, "__orig_bases__"):
return _collect_parameters(tp.__orig_bases__)
return _collect_type_parameters(tp.__orig_bases__)
elif is_type_var(tp):
return (tp,)
else:
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools==68.2.2", "wheel==0.41.2"]
requires = ["setuptools==75.1.0", "wheel~=0.44.0"]
build-backend = "setuptools.build_meta"

[project]
Expand All @@ -20,6 +20,7 @@ classifiers = [
"Programming Language == Python == 3.10",
"Programming Language == Python == 3.11",
"Programming Language == Python == 3.12",
"Programming Language == Python == 3.13",
"Topic == Software Development == Libraries == Python Modules",
]

Expand All @@ -40,6 +41,9 @@ examples = [
"sqlalchemy",
]

[tool.setuptools.packages.find]
include = ["apischema*"]

[tool.setuptools.package-data]
apischema = ["py.typed"]
"apischema.deserialization" = ["methods.c"]
Expand Down
Empty file modified scripts/cythonize.sh
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Cython==3.0.4
Cython==3.0.11
setuptools==75.1.0;python_version>="3.12"
6 changes: 3 additions & 3 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
graphql-core==3.2.3
graphql-core==3.2.4
attrs==22.1.0
bson==0.5.10
docstring-parser==0.15
pydantic==1.10.2
docstring-parser==0.16
pydantic==1.10.18
pytest==7.4.2
pytest-cov==4.0.0
pytest-asyncio==0.20.3
Expand Down

0 comments on commit f3de16a

Please sign in to comment.