Skip to content

Commit 0d70f0e

Browse files
isurufinducer
andauthored
PyPy3 support (#2146)
* Error out eval_file * Enable dynamic attribute support for Pypy >= 6 * Add a test for dynamic attribute support * Skip test for eval_file on pypy * Workaround for __qualname__ on PyPy3 * Add a PyPy3.6 7.3.0 build * Only disable in PyPy3 * Fix travis testing * No numpy and scipy for pypy * Enable test on pypy2 * Fix logic in eval_file * Skip a few tests due to bugs in PyPy * scipy wheels are broken. make pypy2 a failrue Co-authored-by: Andreas Kloeckner <[email protected]>
1 parent f2226ae commit 0d70f0e

File tree

8 files changed

+39
-10
lines changed

8 files changed

+39
-10
lines changed

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,8 @@ matrix:
192192
make pytest -j 2"
193193
set +ex
194194
allow_failures:
195-
- name: PyPy 7.3, Python 2.7, c++11, gcc 4.8
196-
- name: PyPy 7.3, Python 3.6, c++11, gcc 5
197195
- name: Python 3.9 beta, c++17, gcc 7 (w/o numpy/scipy)
196+
- name: PyPy 7.3, Python 2.7, c++11, gcc 4.8
198197
cache:
199198
directories:
200199
- $HOME/.local/bin
@@ -278,15 +277,17 @@ install:
278277
fi
279278
280279
export NPY_NUM_BUILD_JOBS=2
281-
echo "Installing pytest, numpy, scipy..."
282280
local PIP_CMD=""
283281
if [ -n "$PYPY" ]; then
284282
# For expediency, install only versions that are available on the extra index.
283+
echo "Not installing numpy, scipy as working wheels are not available"
284+
# travis_wait 30 $PY_CMD -m pip install --user --upgrade --extra-index-url https://antocuni.github.io/pypy-wheels/manylinux2010 \
285+
# numpy scipy
286+
echo "Installing pytest"
285287
travis_wait 30 \
286-
$PY_CMD -m pip install --user --upgrade --extra-index-url https://antocuni.github.io/pypy-wheels/manylinux2010 \
287-
numpy scipy
288288
$PY_CMD -m pip install --user --upgrade pytest
289289
else
290+
echo "Installing pytest, numpy, scipy..."
290291
$PY_CMD -m pip install --user --upgrade pytest numpy scipy
291292
fi
292293
echo "done."

include/pybind11/detail/class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
1616
NAMESPACE_BEGIN(detail)
1717

18-
#if PY_VERSION_HEX >= 0x03030000
18+
#if PY_VERSION_HEX >= 0x03030000 && !defined(PYPY_VERSION)
1919
# define PYBIND11_BUILTIN_QUALNAME
2020
# define PYBIND11_SET_OLDPY_QUALNAME(obj, nameobj)
2121
#else
@@ -475,7 +475,7 @@ extern "C" inline int pybind11_clear(PyObject *self) {
475475
/// Give instances of this type a `__dict__` and opt into garbage collection.
476476
inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) {
477477
auto type = &heap_type->ht_type;
478-
#if defined(PYPY_VERSION)
478+
#if defined(PYPY_VERSION) && (PYPY_VERSION_NUM < 0x06000000)
479479
pybind11_fail(std::string(type->tp_name) + ": dynamic attributes are "
480480
"currently not supported in "
481481
"conjunction with PyPy!");

include/pybind11/eval.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ void exec(const char (&s)[N], object global = globals(), object local = object()
6666
eval<eval_statements>(s, global, local);
6767
}
6868

69+
#if defined(PYPY_VERSION) && PY_VERSION_HEX >= 0x3000000
70+
template <eval_mode mode = eval_statements>
71+
object eval_file(str, object, object) {
72+
pybind11_fail("eval_file not supported in PyPy3. Use eval");
73+
}
74+
template <eval_mode mode = eval_statements>
75+
object eval_file(str, object) {
76+
pybind11_fail("eval_file not supported in PyPy3. Use eval");
77+
}
78+
template <eval_mode mode = eval_statements>
79+
object eval_file(str) {
80+
pybind11_fail("eval_file not supported in PyPy3. Use eval");
81+
}
82+
#else
6983
template <eval_mode mode = eval_statements>
7084
object eval_file(str fname, object global = globals(), object local = object()) {
7185
if (!local)
@@ -113,5 +127,6 @@ object eval_file(str fname, object global = globals(), object local = object())
113127
throw error_already_set();
114128
return reinterpret_steal<object>(result);
115129
}
130+
#endif
116131

117132
NAMESPACE_END(PYBIND11_NAMESPACE)

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ def pytest_configure():
215215
pytest.requires_eigen_and_scipy = skipif(
216216
not have_eigen or not scipy, reason="eigen and/or scipy are not installed")
217217
pytest.unsupported_on_pypy = skipif(pypy, reason="unsupported on PyPy")
218+
pytest.bug_in_pypy = pytest.mark.xfail(pypy, reason="bug in PyPy")
219+
pytest.unsupported_on_pypy3 = skipif(pypy and sys.version_info.major >= 3,
220+
reason="unsupported on PyPy3")
221+
pytest.unsupported_on_pypy_lt_6 = skipif(pypy and sys.pypy_version_info[0] < 6,
222+
reason="unsupported on PyPy<6")
218223
pytest.unsupported_on_py2 = skipif(sys.version_info.major < 3,
219224
reason="unsupported on Python 2.x")
220225
pytest.gc_collect = gc_collect

tests/test_eval.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import pytest
23
from pybind11_tests import eval_ as m
34

45

@@ -10,8 +11,12 @@ def test_evals(capture):
1011
assert m.test_eval()
1112
assert m.test_eval_single_statement()
1213

14+
assert m.test_eval_failure()
15+
16+
17+
@pytest.unsupported_on_pypy3
18+
def test_eval_file():
1319
filename = os.path.join(os.path.dirname(__file__), "test_eval_call.py")
1420
assert m.test_eval_file(filename)
1521

16-
assert m.test_eval_failure()
1722
assert m.test_eval_file_failure()

tests/test_local_bindings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def test_internal_locals_differ():
152152
assert m.local_cpp_types_addr() != cm.local_cpp_types_addr()
153153

154154

155+
@pytest.bug_in_pypy
155156
def test_stl_caster_vs_stl_bind(msg):
156157
"""One module uses a generic vector caster from `<pybind11/stl.h>` while the other
157158
exports `std::vector<int>` via `py:bind_vector` and `py::module_local`"""

tests/test_multiple_inheritance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ TEST_SUBMODULE(multiple_inheritance, m) {
193193
.def_readwrite_static("static_value", &VanillaStaticMix2::static_value);
194194

195195

196-
#if !defined(PYPY_VERSION)
196+
#if !(defined(PYPY_VERSION) && (PYPY_VERSION_NUM < 0x06000000))
197197
struct WithDict { };
198198
struct VanillaDictMix1 : Vanilla, WithDict { };
199199
struct VanillaDictMix2 : WithDict, Vanilla { };

tests/test_multiple_inheritance.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def test_multiple_inheritance_cpp():
1010
assert mt.bar() == 4
1111

1212

13+
@pytest.bug_in_pypy
1314
def test_multiple_inheritance_mix1():
1415
class Base1:
1516
def __init__(self, i):
@@ -49,6 +50,7 @@ def __init__(self, i, j):
4950
assert mt.bar() == 4
5051

5152

53+
@pytest.bug_in_pypy
5254
def test_multiple_inheritance_python():
5355

5456
class MI1(m.Base1, m.Base2):
@@ -253,7 +255,7 @@ def test_mi_static_properties():
253255
assert d.static_value == 0
254256

255257

256-
@pytest.unsupported_on_pypy
258+
@pytest.unsupported_on_pypy_lt_6
257259
def test_mi_dynamic_attributes():
258260
"""Mixing bases with and without dynamic attribute support"""
259261

0 commit comments

Comments
 (0)