Skip to content

Commit

Permalink
Build Python 3.13 wheels (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Oct 7, 2024
2 parents 402311d + 0a00cfe commit 44a54cd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
CIBW_ARCHS_LINUX: auto aarch64
CIBW_ARCHS_MACOS: auto universal2
CIBW_BUILD_FRONTEND: build
CIBW_FREE_THREADED_SUPPORT: 1
- uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: build-wheels-${{ matrix.os }}
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
matrix:
include:
- {python: '3.13'}
- {name: 'Free-threaded', python: '3.13', free-threaded: true}
- {python: '3.12'}
- {name: Windows, python: '3.12', os: windows-latest}
- {name: Mac, python: '3.12', os: macos-latest}
Expand All @@ -32,13 +33,21 @@ jobs:
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
if: ${{ !matrix.free-threaded }}
with:
python-version: ${{ matrix.python }}
allow-prereleases: true
cache: pip
cache-dependency-path: requirements*/*.txt
- uses: deadsnakes/action@e640ac8743173a67cca4d7d77cd837e514bf98e8 # v3.2.0
if: ${{ matrix.free-threaded }}
with:
python-version: ${{ matrix.python }}
nogil: true
- run: pip install tox
- run: tox run -e ${{ matrix.tox || format('py{0}', matrix.python) }}
- env:
PYTHON_GIL: ${{ matrix.free-threaded && '0' || '1' }}
run: tox run -e ${{ matrix.tox || format('py{0}', matrix.python) }}
typing:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version 3.0.0

Unreleased

- Support Python 3.13 and its experimental free-threaded build. :pr:`461`
- Drop support for Python 3.7 and 3.8.
- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.
:pr:`348`
Expand Down
12 changes: 11 additions & 1 deletion src/markupsafe/_speedups.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,15 @@ static struct PyModuleDef module_definition = {
PyMODINIT_FUNC
PyInit__speedups(void)
{
return PyModule_Create(&module_definition);
PyObject *m = PyModule_Create(&module_definition);

if (m == NULL) {
return NULL;
}

#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif

return m;
}
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import sys
import typing as t
from types import ModuleType

Expand All @@ -14,6 +15,14 @@
_speedups = None # type: ignore


def pytest_report_header() -> list[str]:
"""Return a list of strings to be displayed in the header of the report."""
if sys.version_info >= (3, 13):
return [f"Free-threaded: {not sys._is_gil_enabled()}"]

return []


@pytest.fixture(
scope="session",
autouse=True,
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ skip_missing_interpreters = true

[testenv]
package = wheel
pass_env = PYTHON_GIL
constrain_package_deps = true
use_frozen_constraints = true
deps = -r requirements/tests.txt
Expand Down

0 comments on commit 44a54cd

Please sign in to comment.