Skip to content

Commit f464cc1

Browse files
authored
Merge pull request scipy#22177 from rgommers/nogil-pythran-fix
MAINT: fix extension module not declaring free-threading support, and wheel build changes
2 parents 319ee60 + c9308e2 commit f464cc1

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

scipy/interpolate/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ py3.extension_module('_bspl',
144144
py3.extension_module('_dierckx',
145145
['src/_dierckxmodule.cc'],
146146
include_directories: 'src/',
147-
dependencies: [py3_dep, np_dep, __fitpack_dep],
147+
dependencies: [np_dep, __fitpack_dep],
148148
link_args: version_link_args,
149149
install: true,
150150
subdir: 'scipy/interpolate'

scipy/interpolate/src/_dierckxmodule.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,18 @@ static struct PyModuleDef dierckxmodule = {
754754
PyMODINIT_FUNC
755755
PyInit__dierckx(void)
756756
{
757+
PyObject *module;
758+
757759
import_array();
758760

759-
return PyModule_Create(&dierckxmodule);
761+
module = PyModule_Create(&dierckxmodule);
762+
if (module == NULL) {
763+
return NULL;
764+
}
765+
766+
#if Py_GIL_DISABLED
767+
PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);
768+
#endif
769+
770+
return module;
760771
}

tools/wheels/cibw_before_build_linux.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ FREE_THREADED_BUILD="$(python -c"import sysconfig; print(bool(sysconfig.get_conf
2424
if [[ $FREE_THREADED_BUILD == "True" ]]; then
2525
python -m pip install -U --pre pip
2626
python -m pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy cython
27-
# python -m pip install git+https://github.com/serge-sans-paille/pythran
28-
python -m pip install ninja meson-python pybind11 pythran
27+
python -m pip install git+https://github.com/serge-sans-paille/pythran
28+
python -m pip install ninja meson-python pybind11
2929
fi
3030

3131
# Install Openblas

tools/wheels/cibw_before_build_macos.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ FREE_THREADED_BUILD="$(python -c"import sysconfig; print(bool(sysconfig.get_conf
6666
if [[ $FREE_THREADED_BUILD == "True" ]]; then
6767
python -m pip install -U --pre pip
6868
python -m pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy cython
69-
# python -m pip install git+https://github.com/serge-sans-paille/pythran
70-
python -m pip install ninja meson-python pybind11 pythran
69+
python -m pip install git+https://github.com/serge-sans-paille/pythran
70+
python -m pip install ninja meson-python pybind11
7171
fi
7272

7373
# Install Openblas

tools/wheels/cibw_before_build_win.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ FREE_THREADED_BUILD="$(python -c"import sysconfig; print(bool(sysconfig.get_conf
1717
if [[ $FREE_THREADED_BUILD == "True" ]]; then
1818
python -m pip install -U --pre pip
1919
python -m pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy cython
20-
# TODO: Remove meson installation from source once a new release
21-
# that includes https://github.com/mesonbuild/meson/pull/13851 is available
22-
python -m pip install git+https://github.com/mesonbuild/meson
23-
python -m pip install ninja meson-python pybind11 pythran
20+
python -m pip install git+https://github.com/serge-sans-paille/pythran
21+
python -m pip install ninja meson-python pybind11
2422
fi
2523

2624
# delvewheel is the equivalent of delocate/auditwheel for windows.

tools/wheels/cibw_test_command.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ set -xe
22

33
FREE_THREADED_BUILD="$(python -c"import sysconfig; print(bool(sysconfig.get_config_var('Py_GIL_DISABLED')))")"
44
if [[ $FREE_THREADED_BUILD == "True" ]]; then
5-
# TODO: delete when importing numpy no longer enables the GIL
6-
# setting to zero ensures the GIL is disabled while running the
7-
# tests under free-threaded python
8-
export PYTHON_GIL=0
5+
# Manually check that importing SciPy does not re-enable the GIL.
6+
# In principle the tests should catch this but it seems harmless to leave it
7+
# here as a final sanity check before uploading broken wheels
8+
if [[ $(python -c "import scipy.stats" 2>&1) == *"The global interpreter lock (GIL) has been enabled"* ]]; then
9+
echo "Error: Importing SciPy re-enables the GIL in the free-threaded build"
10+
exit 1
11+
fi
12+
913
fi
1014

1115
python -c "import sys; import scipy; sys.exit(not scipy.test())"

0 commit comments

Comments
 (0)