Skip to content

Commit 72282f7

Browse files
henryiiiSkylion007pre-commit-ci[bot]rwgk
authored
ci: support development releases of Python (#3419)
* ci: support development releases of Python * fix: better PyPy support * fix: patch over a few more pypy issues * Try to patch * Properly follow pep667 * Fix typo * Whoops, 667 not in yet * For testing * More testing * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Try to backport * Try to simplify fix * Nail down the fix * Try pypy workaround * Typo * one last typo * Replacing 0x03110000 with 0x030B0000 * Add TODO. Drop PyPy * Fix typo * Revert catch upgrade * fix: minor cleanup, try pypy again Co-authored-by: Aaron Gokaslan <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve <[email protected]>
1 parent 1eb5996 commit 72282f7

File tree

9 files changed

+137
-17
lines changed

9 files changed

+137
-17
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ jobs:
3030
- '3.6'
3131
- '3.9'
3232
- '3.10'
33-
# - '3.11-dev'
34-
- 'pypy-3.7-v7.3.5'
35-
# - 'pypy-3.8'
33+
- 'pypy-3.7-v7.3.7'
34+
- 'pypy-3.8-v7.3.7'
3635

3736
# Items in here will either be added to the build matrix (if not
3837
# present), or add new keys to an existing matrix element if all the
3938
# existing keys match.
4039
#
41-
# We support three optional keys: args (both build), args1 (first
42-
# build), and args2 (second build).
40+
# We support an optional keys: args, for cmake args
4341
include:
4442
# Just add a key
4543
- runs-on: ubuntu-latest
@@ -122,15 +120,14 @@ jobs:
122120
run: git clean -fdx
123121

124122
# Second build - C++17 mode and in a build directory
125-
- name: Configure ${{ matrix.args2 }}
123+
- name: Configure C++17
126124
run: >
127125
cmake -S . -B build2
128126
-DPYBIND11_WERROR=ON
129127
-DDOWNLOAD_CATCH=ON
130128
-DDOWNLOAD_EIGEN=ON
131129
-DCMAKE_CXX_STANDARD=17
132130
${{ matrix.args }}
133-
${{ matrix.args2 }}
134131
135132
- name: Build
136133
run: cmake --build build2 -j 2

.github/workflows/upstream.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
2+
name: Upstream
3+
4+
on:
5+
workflow_dispatch:
6+
pull_request:
7+
8+
concurrency:
9+
group: upstream-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
env:
13+
PIP_ONLY_BINARY: numpy
14+
15+
jobs:
16+
standard:
17+
name: "🐍 3.11 dev • ubuntu-latest • x64"
18+
runs-on: ubuntu-latest
19+
if: "contains(github.event.pull_request.labels.*.name, 'python dev')"
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- name: Setup Python 3.11
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: "3.11-dev"
28+
29+
- name: Setup Boost (Linux)
30+
if: runner.os == 'Linux'
31+
run: sudo apt-get install libboost-dev
32+
33+
- name: Update CMake
34+
uses: jwlawson/[email protected]
35+
36+
- name: Prepare env
37+
run: |
38+
python -m pip install -r tests/requirements.txt
39+
40+
- name: Setup annotations on Linux
41+
if: runner.os == 'Linux'
42+
run: python -m pip install pytest-github-actions-annotate-failures
43+
44+
# First build - C++11 mode and inplace
45+
- name: Configure C++11
46+
run: >
47+
cmake -S . -B .
48+
-DPYBIND11_WERROR=ON
49+
-DDOWNLOAD_CATCH=ON
50+
-DDOWNLOAD_EIGEN=ON
51+
-DCMAKE_CXX_STANDARD=11
52+
53+
- name: Build C++11
54+
run: cmake --build . -j 2
55+
56+
- name: Python tests C++11
57+
run: cmake --build . --target pytest -j 2
58+
59+
- name: C++11 tests
60+
run: cmake --build . --target cpptest -j 2
61+
62+
- name: Interface test C++11
63+
run: cmake --build . --target test_cmake_build
64+
65+
- name: Clean directory
66+
run: git clean -fdx
67+
68+
# Second build - C++17 mode and in a build directory
69+
- name: Configure C++17
70+
run: >
71+
cmake -S . -B build2
72+
-DPYBIND11_WERROR=ON
73+
-DDOWNLOAD_CATCH=ON
74+
-DDOWNLOAD_EIGEN=ON
75+
-DCMAKE_CXX_STANDARD=17
76+
${{ matrix.args }}
77+
${{ matrix.args2 }}
78+
79+
- name: Build
80+
run: cmake --build build2 -j 2
81+
82+
- name: Python tests
83+
run: cmake --build build2 --target pytest
84+
85+
- name: C++ tests
86+
run: cmake --build build2 --target cpptest
87+
88+
# Third build - C++17 mode with unstable ABI
89+
- name: Configure (unstable ABI)
90+
run: >
91+
cmake -S . -B build3
92+
-DPYBIND11_WERROR=ON
93+
-DDOWNLOAD_CATCH=ON
94+
-DDOWNLOAD_EIGEN=ON
95+
-DCMAKE_CXX_STANDARD=17
96+
-DPYBIND11_INTERNALS_VERSION=10000000
97+
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
98+
${{ matrix.args }}
99+
100+
- name: Build (unstable ABI)
101+
run: cmake --build build3 -j 2
102+
103+
- name: Python tests (unstable ABI)
104+
run: cmake --build build3 --target pytest
105+
106+
- name: Interface test
107+
run: cmake --build build2 --target test_cmake_build
108+
109+
# This makes sure the setup_helpers module can build packages using
110+
# setuptools
111+
- name: Setuptools helpers test
112+
run: pytest tests/extra_setuptools

include/pybind11/cast.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ struct type_caster<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_t
150150
return false;
151151
} else {
152152
handle src_or_index = src;
153-
#if PY_VERSION_HEX < 0x03080000
153+
// PyPy: 7.3.7's 3.8 does not implement PyLong_*'s __index__ calls.
154+
#if PY_VERSION_HEX < 0x03080000 || defined(PYPY_VERSION)
154155
object index;
155156
if (!PYBIND11_LONG_CHECK(src.ptr())) { // So: index_check(src.ptr())
156157
index = reinterpret_steal<object>(PyNumber_Index(src.ptr()));

include/pybind11/eval.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
1919
PYBIND11_NAMESPACE_BEGIN(detail)
2020

2121
inline void ensure_builtins_in_globals(object &global) {
22-
#if PY_VERSION_HEX < 0x03080000
22+
#if defined(PYPY_VERSION) || PY_VERSION_HEX < 0x03080000
2323
// Running exec and eval on Python 2 and 3 adds `builtins` module under
2424
// `__builtins__` key to globals if not yet present.
2525
// Python 3.8 made PyRun_String behave similarly. Let's also do that for
26-
// older versions, for consistency.
26+
// older versions, for consistency. This was missing from PyPy3.8 7.3.7.
2727
if (!global.contains("__builtins__"))
2828
global["__builtins__"] = module_::import(PYBIND11_BUILTINS_MODULE);
2929
#else

include/pybind11/pybind11.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,16 +2365,17 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty
23652365

23662366
/* Don't call dispatch code if invoked from overridden function.
23672367
Unfortunately this doesn't work on PyPy. */
2368-
#if !defined(PYPY_VERSION)
2369-
2368+
#if !defined(PYPY_VERSION) && PY_VERSION_HEX < 0x030B0000
2369+
// TODO: Remove PyPy workaround for Python 3.11.
2370+
// Current API fails on 3.11 since co_varnames can be null.
23702371
#if PY_VERSION_HEX >= 0x03090000
23712372
PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get());
23722373
if (frame != nullptr) {
23732374
PyCodeObject *f_code = PyFrame_GetCode(frame);
23742375
// f_code is guaranteed to not be NULL
23752376
if ((std::string) str(f_code->co_name) == name && f_code->co_argcount > 0) {
23762377
PyObject* locals = PyEval_GetLocals();
2377-
if (locals != nullptr) {
2378+
if (locals != nullptr && f_code->co_varnames != nullptr) {
23782379
PyObject *self_caller = dict_getitem(
23792380
locals, PyTuple_GET_ITEM(f_code->co_varnames, 0)
23802381
);

tests/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ numpy==1.16.6; python_version<"3.6" and sys_platform!="win32" and platform_pytho
22
numpy==1.19.0; platform_python_implementation=="PyPy" and sys_platform=="linux" and python_version=="3.6"
33
numpy==1.20.0; platform_python_implementation=="PyPy" and sys_platform=="linux" and python_version=="3.7"
44
numpy==1.19.3; platform_python_implementation!="PyPy" and python_version=="3.6"
5-
numpy==1.21.3; platform_python_implementation!="PyPy" and python_version>="3.7"
5+
numpy==1.21.3; platform_python_implementation!="PyPy" and python_version>="3.7" and python_version<"3.11"
66
py @ git+https://github.com/pytest-dev/py; python_version>="3.11"
77
pytest==4.6.9; python_version<"3.5"
88
pytest==6.1.2; python_version=="3.5"

tests/test_buffers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def test_from_python():
3636

3737

3838
# https://foss.heptapod.net/pypy/pypy/-/issues/2444
39+
# TODO: fix on recent PyPy
40+
@pytest.mark.xfail(
41+
env.PYPY, reason="PyPy 7.3.7 doesn't clear this anymore", stict=False
42+
)
3943
def test_to_python():
4044
mat = m.Matrix(5, 4)
4145
assert memoryview(mat).shape == (5, 4)

tests/test_builtin_casters.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ def cant_convert(v):
299299
assert noconvert(7) == 7
300300
cant_convert(3.14159)
301301
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
302-
if (3, 8) <= env.PY < (3, 10):
302+
# TODO: PyPy 3.8 does not behave like CPython 3.8 here yet (7.3.7)
303+
if (3, 8) <= env.PY < (3, 10) and env.CPYTHON:
303304
with env.deprecated_call():
304305
assert convert(Int()) == 42
305306
else:
@@ -334,7 +335,9 @@ def require_implicit(v):
334335

335336
# The implicit conversion from np.float32 is undesirable but currently accepted.
336337
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
337-
if (3, 8) <= env.PY < (3, 10):
338+
# TODO: PyPy 3.8 does not behave like CPython 3.8 here yet (7.3.7)
339+
# https://github.com/pybind/pybind11/issues/3408
340+
if (3, 8) <= env.PY < (3, 10) and env.CPYTHON:
338341
with env.deprecated_call():
339342
assert convert(np.float32(3.14159)) == 3
340343
else:

tests/test_exceptions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
import env # noqa: F401
6+
import env
77
import pybind11_cross_module_tests as cm
88
from pybind11_tests import exceptions as m
99

@@ -97,6 +97,8 @@ def ignore_pytest_unraisable_warning(f):
9797
return f
9898

9999

100+
# TODO: find out why this fails on PyPy, https://foss.heptapod.net/pypy/pypy/-/issues/3583
101+
@pytest.mark.xfail(env.PYPY, reason="Failure on PyPy 3.8 (7.3.7)", strict=False)
100102
@ignore_pytest_unraisable_warning
101103
def test_python_alreadyset_in_destructor(monkeypatch, capsys):
102104
hooked = False

0 commit comments

Comments
 (0)