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

Add free-threading support #462

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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: 2 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ jobs:
CIBW_ARCHS_LINUX: auto aarch64
CIBW_ARCHS_MACOS: auto universal2
CIBW_BUILD_FRONTEND: build
CIBW_PRERELEASE_PYTHONS: true
CIBW_FREE_THREADED_SUPPORT: true
- uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
with:
name: build-wheels-${{ matrix.os }}
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
fail-fast: false
matrix:
include:
- {name: '3.13 free-threading', nogil: true, tox: py313}
- {name: Windows free-threading, nogil: true, os: windows-latest, tox: py313}
- {python: '3.13'}
- {python: '3.12'}
- {name: Windows, python: '3.12', os: windows-latest}
Expand All @@ -33,13 +35,34 @@ jobs:
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
if: ${{ ! matrix.nogil }}
with:
python-version: ${{ matrix.python }}
allow-prereleases: true
cache: pip
cache-dependency-path: requirements*/*.txt

# Free-threading versions of python
# https://py-free-threading.github.io/ci/
- if: ${{ matrix.nogil && ! matrix.os }}
uses: deadsnakes/action@6c8b9b82fe0b4344f4b98f2775fcc395df45e494 # v3.1.0
with:
python-version: 3.13-dev
nogil: true
- if: ${{ matrix.nogil && matrix.os == 'windows-latest' }}
shell: pwsh
run: |
$pythonInstallerUrl = "https://www.python.org/ftp/python/3.13.0/python-3.13.0rc1-amd64.exe"
Invoke-WebRequest $pythonInstallerUrl -OutFile setup-python.exe
Start-Process "setup-python.exe" -argumentlist "/quiet PrependPath=1 TargetDir=C:\Python313 Include_freethreaded=1" -wait
C:\Python313\python3.13t.exe -m pip install -U pip
C:\Python313\python3.13t.exe -c "import sys; print(f'{sys._is_gil_enabled()=}')"
echo "C:\Python313\Scripts" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "C:\Python313" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- run: pip install tox
- run: tox run -e ${{ matrix.tox || format('py{0}', matrix.python) }}
--discover C:\Python313\python3.13t.exe
typing:
runs-on: ubuntu-latest
steps:
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;
}
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ envlist =
typing
docs
skip_missing_interpreters = true
requires = virtualenv>=20.26.3

[testenv]
package = wheel
constrain_package_deps = true
use_frozen_constraints = true
deps = -r requirements/tests.txt
commands_pre =
-python -c 'import sys; sys.version_info >= (3, 13) and print(f"{sys._is_gil_enabled()=}")'
commands = pytest -v --tb=short --basetemp={envtmpdir} {posargs}

[testenv:style]
Expand Down
Loading