Skip to content
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

Build Python 3.13 wheels #461

Merged
merged 9 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ jobs:
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
with:
platforms: arm64
- uses: pypa/cibuildwheel@bd033a44476646b606efccdd5eed92d5ea1d77ad # v2.20.0
- uses: pypa/cibuildwheel@d4a2945fcc8d13f20a1b99d461b8e844d5fc6e23 # v2.21.1
env:
# For workflow_dispatch, only build the new Python version.
CIBW_BUILD: ${{ inputs.python && format('{0}-*', inputs.python) || null }}
CIBW_SKIP: pp*
CIBW_ARCHS_LINUX: auto aarch64
CIBW_ARCHS_MACOS: auto universal2
CIBW_BUILD_FRONTEND: build
CIBW_FREE_THREADED_SUPPORT: 1
- uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6
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 @@ -33,13 +34,21 @@ jobs:
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
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 @@ -20,6 +20,7 @@ Unreleased
``importlib.metadata.version("markupsafe")``, instead. :pr:`402`
- Speed up escaping plain strings by 40%. :pr:`434`
- Simplify speedups implementation. :pr:`437`
- Publish wheels for Python 3.13. :pr:`461`


Version 2.1.5
Expand Down
9 changes: 8 additions & 1 deletion src/markupsafe/_speedups.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,12 @@ 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;
}
6 changes: 6 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 sysconfig
import typing as t
from types import ModuleType

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


def pytest_report_header() -> list[str]:
"""Return a list of strings to be displayed in the header of the report."""
return [f"Free-threaded: {bool(sysconfig.get_config_var('Py_GIL_DISABLED'))}"]
Copy link
Contributor

@dairiki dairiki Sep 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could sys._is_gil_disabled() be of more interest here?

As I understand it Py_GIL_DISABLED tells whether --disable-gil was set at python build time.
Even for --disable-gil builds, the PYTHONGIL environment variable or loading of extension modules without a valid Py_mod_gil slot can cause the GIL to be enabled. _is_gil_disabled() tells whether the GIL is actually in use or not. (This seems more of interest when interpreting test results.)



@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