Skip to content

PyPy3 support #2146

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

Merged
merged 15 commits into from
Jul 7, 2020
Merged
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
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ matrix:
make pytest -j 2"
set +ex
allow_failures:
- name: PyPy 7.3, Python 2.7, c++11, gcc 4.8
- name: PyPy 7.3, Python 3.6, c++11, gcc 5
- name: Python 3.9 beta, c++17, gcc 7 (w/o numpy/scipy)
- name: PyPy 7.3, Python 2.7, c++11, gcc 4.8
cache:
directories:
- $HOME/.local/bin
Expand Down Expand Up @@ -278,15 +277,17 @@ install:
fi

export NPY_NUM_BUILD_JOBS=2
echo "Installing pytest, numpy, scipy..."
local PIP_CMD=""
if [ -n "$PYPY" ]; then
# For expediency, install only versions that are available on the extra index.
echo "Not installing numpy, scipy as working wheels are not available"
# travis_wait 30 $PY_CMD -m pip install --user --upgrade --extra-index-url https://antocuni.github.io/pypy-wheels/manylinux2010 \
# numpy scipy
echo "Installing pytest"
travis_wait 30 \
$PY_CMD -m pip install --user --upgrade --extra-index-url https://antocuni.github.io/pypy-wheels/manylinux2010 \
numpy scipy
$PY_CMD -m pip install --user --upgrade pytest
else
echo "Installing pytest, numpy, scipy..."
$PY_CMD -m pip install --user --upgrade pytest numpy scipy
fi
echo "done."
Expand Down
4 changes: 2 additions & 2 deletions include/pybind11/detail/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail)

#if PY_VERSION_HEX >= 0x03030000
#if PY_VERSION_HEX >= 0x03030000 && !defined(PYPY_VERSION)
# define PYBIND11_BUILTIN_QUALNAME
# define PYBIND11_SET_OLDPY_QUALNAME(obj, nameobj)
#else
Expand Down Expand Up @@ -448,7 +448,7 @@ extern "C" inline int pybind11_clear(PyObject *self) {
/// Give instances of this type a `__dict__` and opt into garbage collection.
inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) {
auto type = &heap_type->ht_type;
#if defined(PYPY_VERSION)
#if defined(PYPY_VERSION) && (PYPY_VERSION_NUM < 0x06000000)
pybind11_fail(std::string(type->tp_name) + ": dynamic attributes are "
"currently not supported in "
"conjunction with PyPy!");
Expand Down
15 changes: 15 additions & 0 deletions include/pybind11/eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ void exec(const char (&s)[N], object global = globals(), object local = object()
eval<eval_statements>(s, global, local);
}

#if defined(PYPY_VERSION) && PY_VERSION_HEX >= 0x3000000
template <eval_mode mode = eval_statements>
object eval_file(str, object, object) {
pybind11_fail("eval_file not supported in PyPy3. Use eval");
}
template <eval_mode mode = eval_statements>
object eval_file(str, object) {
pybind11_fail("eval_file not supported in PyPy3. Use eval");
}
template <eval_mode mode = eval_statements>
object eval_file(str) {
pybind11_fail("eval_file not supported in PyPy3. Use eval");
}
#else
template <eval_mode mode = eval_statements>
object eval_file(str fname, object global = globals(), object local = object()) {
if (!local)
Expand Down Expand Up @@ -113,5 +127,6 @@ object eval_file(str fname, object global = globals(), object local = object())
throw error_already_set();
return reinterpret_steal<object>(result);
}
#endif

NAMESPACE_END(PYBIND11_NAMESPACE)
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ def pytest_configure():
pytest.requires_eigen_and_scipy = skipif(
not have_eigen or not scipy, reason="eigen and/or scipy are not installed")
pytest.unsupported_on_pypy = skipif(pypy, reason="unsupported on PyPy")
pytest.bug_in_pypy = pytest.mark.xfail(pypy, reason="bug in PyPy")
pytest.unsupported_on_pypy3 = skipif(pypy and sys.version_info.major >= 3,
reason="unsupported on PyPy3")
pytest.unsupported_on_pypy_lt_6 = skipif(pypy and sys.pypy_version_info[0] < 6,
reason="unsupported on PyPy<6")
pytest.unsupported_on_py2 = skipif(sys.version_info.major < 3,
reason="unsupported on Python 2.x")
pytest.gc_collect = gc_collect
Expand Down
7 changes: 6 additions & 1 deletion tests/test_eval.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pytest
from pybind11_tests import eval_ as m


Expand All @@ -10,8 +11,12 @@ def test_evals(capture):
assert m.test_eval()
assert m.test_eval_single_statement()

assert m.test_eval_failure()


@pytest.unsupported_on_pypy3
def test_eval_file():
filename = os.path.join(os.path.dirname(__file__), "test_eval_call.py")
assert m.test_eval_file(filename)

assert m.test_eval_failure()
assert m.test_eval_file_failure()
1 change: 1 addition & 0 deletions tests/test_local_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def test_internal_locals_differ():
assert m.local_cpp_types_addr() != cm.local_cpp_types_addr()


@pytest.bug_in_pypy
def test_stl_caster_vs_stl_bind(msg):
"""One module uses a generic vector caster from `<pybind11/stl.h>` while the other
exports `std::vector<int>` via `py:bind_vector` and `py::module_local`"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_multiple_inheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ TEST_SUBMODULE(multiple_inheritance, m) {
.def_readwrite_static("static_value", &VanillaStaticMix2::static_value);


#if !defined(PYPY_VERSION)
#if !(defined(PYPY_VERSION) && (PYPY_VERSION_NUM < 0x06000000))
struct WithDict { };
struct VanillaDictMix1 : Vanilla, WithDict { };
struct VanillaDictMix2 : WithDict, Vanilla { };
Expand Down
4 changes: 3 additions & 1 deletion tests/test_multiple_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def test_multiple_inheritance_cpp():
assert mt.bar() == 4


@pytest.bug_in_pypy
def test_multiple_inheritance_mix1():
class Base1:
def __init__(self, i):
Expand Down Expand Up @@ -49,6 +50,7 @@ def __init__(self, i, j):
assert mt.bar() == 4


@pytest.bug_in_pypy
def test_multiple_inheritance_python():

class MI1(m.Base1, m.Base2):
Expand Down Expand Up @@ -253,7 +255,7 @@ def test_mi_static_properties():
assert d.static_value == 0


@pytest.unsupported_on_pypy
@pytest.unsupported_on_pypy_lt_6
def test_mi_dynamic_attributes():
"""Mixing bases with and without dynamic attribute support"""

Expand Down