Skip to content

Commit

Permalink
fix: better PyPy support
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Oct 27, 2021
1 parent c82bbaa commit ee1fb1b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/pybind11/eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail)

inline void ensure_builtins_in_globals(object &global) {
#if PY_VERSION_HEX < 0x03080000
#if defined(PYPY_VERSION) || PY_VERSION_HEX < 0x03080000
// Running exec and eval on Python 2 and 3 adds `builtins` module under
// `__builtins__` key to globals if not yet present.
// Python 3.8 made PyRun_String behave similarly. Let's also do that for
// older versions, for consistency.
// older versions, for consistency. This was missing from PyPy3.8 7.3.7.
if (!global.contains("__builtins__"))
global["__builtins__"] = module_::import(PYBIND11_BUILTINS_MODULE);
#else
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ numpy==1.16.6; python_version<"3.6" and sys_platform!="win32" and platform_pytho
numpy==1.19.0; platform_python_implementation=="PyPy" and sys_platform=="linux" and python_version=="3.6"
numpy==1.20.0; platform_python_implementation=="PyPy" and sys_platform=="linux" and python_version=="3.7"
numpy==1.19.3; platform_python_implementation!="PyPy" and python_version=="3.6"
numpy==1.21.3; platform_python_implementation!="PyPy" and python_version>="3.7"
numpy==1.21.3; platform_python_implementation!="PyPy" and python_version>="3.7" and python_version<"3.11"
py @ git+https://github.com/pytest-dev/py; python_version>="3.11"
pytest==4.6.9; python_version<"3.5"
pytest==6.1.2; python_version=="3.5"
Expand Down
1 change: 1 addition & 0 deletions tests/test_buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_to_python():
assert cstats.alive() == 1
del mat2 # holds a mat reference
pytest.gc_collect()
pytest.gc_collect() # Needed for PyPy
assert cstats.alive() == 0
assert cstats.values() == ["5x4 matrix"]
assert cstats.copy_constructions == 0
Expand Down
4 changes: 2 additions & 2 deletions tests/test_builtin_casters.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def cant_convert(v):
assert noconvert(7) == 7
cant_convert(3.14159)
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
if (3, 8) <= env.PY < (3, 10):
if (3, 8) <= env.PY < (3, 10) and env.CPYTHON:
with env.deprecated_call():
assert convert(Int()) == 42
else:
Expand Down Expand Up @@ -334,7 +334,7 @@ def require_implicit(v):

# The implicit conversion from np.float32 is undesirable but currently accepted.
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
if (3, 8) <= env.PY < (3, 10):
if (3, 8) <= env.PY < (3, 10) and env.CPYTHON:
with env.deprecated_call():
assert convert(np.float32(3.14159)) == 3
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_embed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STR
return()
endif()

find_package(Catch 2.13.2)
find_package(Catch 2.13.7)

if(CATCH_FOUND)
message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}")
Expand Down

0 comments on commit ee1fb1b

Please sign in to comment.