From 267cf8795981b460cf7bf3f888e16c947b9703f7 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 15 Oct 2021 12:27:48 -0400 Subject: [PATCH 01/12] ci: support Python 3.11-dev Also update 3.10 to final, better PyPy usage --- .github/workflows/ci.yml | 35 ++++++++++++----------------------- tools/pybind11Tools.cmake | 2 +- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09b4000562..140e6ff9cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,13 +22,14 @@ jobs: matrix: runs-on: [ubuntu-latest, windows-latest, macos-latest] python: - - 2.7 - - 3.5 - - 3.6 - - 3.9 - - 3.10-dev - - pypy2 - - pypy3 + - '2.7' + - '3.5' + - '3.6' + - '3.9' + - '3.10' + - '3.11-dev' + - pypy-3.6 + - pypy-3.7 # Items in here will either be added to the build matrix (if not # present), or add new keys to an existing matrix element if all the @@ -47,18 +48,6 @@ jobs: args: > -DPYBIND11_FINDPYTHON=ON - # These items will be removed from the build matrix, keys must match. - exclude: - # Currently 32bit only, and we build 64bit - - runs-on: windows-latest - python: pypy2 - - runs-on: windows-latest - python: pypy3 - - # TODO: PyPy2 7.3.3 segfaults, while 7.3.2 was fine. - - runs-on: ubuntu-latest - python: pypy2 - name: "🐍 ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}" runs-on: ${{ matrix.runs-on }} @@ -117,7 +106,7 @@ jobs: - name: C++11 tests # TODO: Figure out how to load the DLL on Python 3.8+ - if: "!(runner.os == 'Windows' && (matrix.python == 3.8 || matrix.python == 3.9 || matrix.python == '3.10-dev'))" + if: "!(runner.os == 'Windows' && (matrix.python == 3.8 || matrix.python == 3.9 || matrix.python == '3.10' || matrix.python == '3.11-dev'))" run: cmake --build . --target cpptest -j 2 - name: Interface test C++11 @@ -145,7 +134,7 @@ jobs: - name: C++ tests # TODO: Figure out how to load the DLL on Python 3.8+ - if: "!(runner.os == 'Windows' && (matrix.python == 3.8 || matrix.python == 3.9 || matrix.python == '3.10-dev'))" + if: "!(runner.os == 'Windows' && (matrix.python == 3.8 || matrix.python == 3.9 || matrix.python == '3.10' || matrix.python == '3.11-dev'))" run: cmake --build build2 --target cpptest # Third build - C++17 mode with unstable ABI @@ -199,7 +188,7 @@ jobs: - python-version: 3.9 python-debug: true valgrind: true - - python-version: 3.10-dev + - python-version: 3.11-dev python-debug: false name: "🐍 ${{ matrix.python-version }}${{ matrix.python-debug && '-dbg' || '' }} (deadsnakes)${{ matrix.valgrind && ' • Valgrind' || '' }} • x64" @@ -739,7 +728,7 @@ jobs: - 3.7 - 3.8 - 3.9 - - pypy3 + - pypy-3.7 # TODO: fix hang on pypy2 include: diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake index cc5ca21ca3..026069c73d 100644 --- a/tools/pybind11Tools.cmake +++ b/tools/pybind11Tools.cmake @@ -38,7 +38,7 @@ endif() # A user can set versions manually too set(Python_ADDITIONAL_VERSIONS - "3.10;3.9;3.8;3.7;3.6;3.5;3.4" + "3.11;3.10;3.9;3.8;3.7;3.6;3.5;3.4" CACHE INTERNAL "") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") From 497439df6027c658f631b41f83613ef44c23cfe4 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 15 Oct 2021 17:34:05 -0400 Subject: [PATCH 02/12] fix: use PyFrame_GetCode on Python 3.9+ --- include/pybind11/detail/type_caster_base.h | 12 +++++++++-- include/pybind11/pybind11.h | 24 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index f804d9d10c..2424fb00e1 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -468,12 +468,20 @@ PYBIND11_NOINLINE std::string error_string() { PyFrameObject *frame = trace->tb_frame; errorString += "\n\nAt:\n"; while (frame) { +#if PY_VERSION_HEX >= 0x03090000 + PyCodeObject *code = PyFrame_GetCode(frame); +#else + PyCodeObject *code = frame->f_code; +#endif int lineno = PyFrame_GetLineNumber(frame); errorString += - " " + handle(frame->f_code->co_filename).cast() + + " " + handle(code->co_filename).cast() + "(" + std::to_string(lineno) + "): " + - handle(frame->f_code->co_name).cast() + "\n"; + handle(code->co_name).cast() + "\n"; frame = frame->f_back; +#if PY_VERSION_HEX >= 0x03090000 + Py_DECREF(code); +#endif } } #endif diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 095efd9c31..32b1bd6afa 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -2335,6 +2335,28 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty /* Don't call dispatch code if invoked from overridden function. Unfortunately this doesn't work on PyPy. */ #if !defined(PYPY_VERSION) + +#if PY_VERSION_HEX >= 0x03090000 + PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get()); + if (frame != nullptr) { + PyCodeObject *code = PyFrame_GetCode(frame); + if ((std::string) str(code->co_name) == name && code->co_argcount > 0) { + PyObject* locals = PyEval_GetLocals(); + if (locals != nullptr) { + PyObject *self_caller = dict_getitem( + locals, PyTuple_GET_ITEM(code->co_varnames, 0) + ); + if (self_caller == self.ptr()) { + Py_DECREF(code); + Py_DECREF(frame); + return function(); + } + } + } + Py_DECREF(code); + Py_DECREF(frame); + } +#else PyFrameObject *frame = PyThreadState_Get()->frame; if (frame != nullptr && (std::string) str(frame->f_code->co_name) == name && frame->f_code->co_argcount > 0) { @@ -2344,6 +2366,8 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty if (self_caller == self.ptr()) return function(); } +#endif + #else /* PyPy currently doesn't provide a detailed cpyext emulation of frame objects, so we have to emulate this using Python. This From 719ce9729730a2fe610dda68b8f47fbc7c51bf1e Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 15 Oct 2021 22:53:43 -0400 Subject: [PATCH 03/12] ci: some bitiness of pypy not supported on win --- .github/workflows/ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 140e6ff9cf..e2b770d97a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,6 @@ jobs: - '3.9' - '3.10' - '3.11-dev' - - pypy-3.6 - pypy-3.7 # Items in here will either be added to the build matrix (if not @@ -728,8 +727,7 @@ jobs: - 3.7 - 3.8 - 3.9 - - pypy-3.7 - # TODO: fix hang on pypy2 + - pypy-3.6 include: - python: 3.9 From 4ce372545aadea9e02be0aa06a56693f188cb96a Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 15 Oct 2021 22:57:30 -0400 Subject: [PATCH 04/12] chore: update CMake support to 3.22rc1 to quiet warning --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25cfcec2f6..2e81869c3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,13 +7,13 @@ cmake_minimum_required(VERSION 3.4) -# The `cmake_minimum_required(VERSION 3.4...3.21)` syntax does not work with +# The `cmake_minimum_required(VERSION 3.4...3.22)` syntax does not work with # some versions of VS that have a patched CMake 3.11. This forces us to emulate # the behavior using the following workaround: -if(${CMAKE_VERSION} VERSION_LESS 3.21) +if(${CMAKE_VERSION} VERSION_LESS 3.22) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() - cmake_policy(VERSION 3.21) + cmake_policy(VERSION 3.22) endif() # Extract project version from source From 0925f0eeb21b465b98d0c4da63b0a1e41eb2394b Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sat, 16 Oct 2021 23:47:25 -0400 Subject: [PATCH 05/12] fix: use dev version of py to fix Py 3.11 --- tests/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/requirements.txt b/tests/requirements.txt index 069122b884..86465a13ba 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -4,6 +4,7 @@ numpy==1.18.0; platform_python_implementation=="PyPy" and sys_platform=="darwin" numpy==1.19.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version=="3.6" numpy==1.21.2; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.7" and python_version<"3.10" numpy==1.21.2; platform_python_implementation!="PyPy" and sys_platform=="linux" and python_version=="3.10" +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" pytest==6.2.4; python_version>="3.6" From b517ab80fd86f520a754fb51f8c74ce623f633e5 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sat, 16 Oct 2021 23:47:46 -0400 Subject: [PATCH 06/12] tests: print proper Eigen version --- noxfile.py | 5 +++-- tests/CMakeLists.txt | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index 234179821d..757a53843a 100644 --- a/noxfile.py +++ b/noxfile.py @@ -2,7 +2,7 @@ nox.options.sessions = ["lint", "tests", "tests_packaging"] -PYTHON_VERISONS = ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10"] +PYTHON_VERISONS = ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] @nox.session(reuse_venv=True) @@ -20,7 +20,8 @@ def tests(session: nox.Session) -> None: Run the tests (requires a compiler). """ tmpdir = session.create_tmp() - session.install("pytest", "cmake") + session.install("cmake") + session.install("-r", "tests/requirements.txt") session.run( "cmake", "-S", diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d4e7b71e1d..b0ba077522 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -174,10 +174,14 @@ set(PYBIND11_CROSS_MODULE_GIL_TESTS test_gil_scoped.py) set(PYBIND11_EIGEN_REPO "https://gitlab.com/libeigen/eigen.git" CACHE STRING "Eigen repository to use for tests") -# This hash is for 3.4.0, using a hash for security reasons +# Always use a hash for reconfigure speed and security reasons set(PYBIND11_EIGEN_VERSION "929bc0e191d0927b1735b9a1ddc0e8b77e3a25ec" CACHE STRING "Eigen version to use for tests") +# Pretty print the version (keep in sync) +set(PYBIND11_EIGEN_VERSION_STRING + "3.4.0" + CACHE STRING "Eigen version string to use for tests") # Check if Eigen is available; if not, remove from PYBIND11_TEST_FILES (but # keep it in PYBIND11_PYTEST_FILES, so that we get the "eigen is not installed" @@ -206,6 +210,9 @@ if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1) set(EIGEN3_INCLUDE_DIR ${eigen_SOURCE_DIR}) set(EIGEN3_FOUND TRUE) + # When getting locally, the version is not visible from a superprojet, + # so just force it. + set(EIGEN3_VERSION "${PYBIND11_EIGEN_VERSION_STRING}") else() find_package(Eigen3 3.2.7 QUIET CONFIG) From 4a1f3b204e0b824b9279493f12c91791b2e10012 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 21 Oct 2021 16:27:52 -0400 Subject: [PATCH 07/12] ci: include pypy2, not sure why --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2b770d97a..89ad8e3281 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,6 +46,8 @@ jobs: python: 3.6 args: > -DPYBIND11_FINDPYTHON=ON + - runs-on: macos-latest + python: pypy-2.7 name: "🐍 ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}" runs-on: ${{ matrix.runs-on }} From 4c5c4cc5f9f239e9c29e671ca60ab8e6d88ba268 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 25 Oct 2021 12:02:41 -0400 Subject: [PATCH 08/12] ci: avoid running on Python 3.11 for now --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89ad8e3281..94397d94bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: - '3.6' - '3.9' - '3.10' - - '3.11-dev' + # - '3.11-dev' - pypy-3.7 # Items in here will either be added to the build matrix (if not @@ -186,11 +186,11 @@ jobs: fail-fast: false matrix: include: - - python-version: 3.9 + - python-version: "3.10" python-debug: true valgrind: true - - python-version: 3.11-dev - python-debug: false + # - python-version: "3.11-dev" + # python-debug: false name: "🐍 ${{ matrix.python-version }}${{ matrix.python-debug && '-dbg' || '' }} (deadsnakes)${{ matrix.valgrind && ' • Valgrind' || '' }} • x64" runs-on: ubuntu-latest From abe454f93f236f2058038dccf6cc00dda00a7d63 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 25 Oct 2021 13:01:35 -0400 Subject: [PATCH 09/12] ci: fix runs --- .github/workflows/ci.yml | 6 ++++-- tests/requirements.txt | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94397d94bd..5e5a149701 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,8 @@ jobs: - '3.9' - '3.10' # - '3.11-dev' - - pypy-3.7 + - 'pypy-3.7-v7.3.5' + - 'pypy-3.8' # Items in here will either be added to the build matrix (if not # present), or add new keys to an existing matrix element if all the @@ -186,7 +187,8 @@ jobs: fail-fast: false matrix: include: - - python-version: "3.10" + # TODO: Fails on 3.10, investigate + - python-version: "3.9" python-debug: true valgrind: true # - python-version: "3.11-dev" diff --git a/tests/requirements.txt b/tests/requirements.txt index 86465a13ba..ec32bf1dae 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,6 +1,7 @@ --extra-index-url https://antocuni.github.io/pypy-wheels/manylinux2010/ numpy==1.16.6; python_version<"3.6" and sys_platform!="win32" -numpy==1.18.0; platform_python_implementation=="PyPy" and sys_platform=="darwin" and python_version>="3.6" +numpy==1.19.0; platform_python_implementation=="PyPy" and sys_platform=="darwin" and python_version=="3.6" +numpy==1.20.0; platform_python_implementation=="PyPy" and sys_platform=="darwin" and python_version=="3.7" numpy==1.19.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version=="3.6" numpy==1.21.2; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.7" and python_version<"3.10" numpy==1.21.2; platform_python_implementation!="PyPy" and sys_platform=="linux" and python_version=="3.10" From 4866433e4e894c1f7d76ecfe17e76c6951b51851 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 25 Oct 2021 16:28:11 -0400 Subject: [PATCH 10/12] ci: simpler PyPy usage, drop unmaintained scipy + pypy index --- .github/workflows/ci.yml | 24 +++++++++++++++--------- .github/workflows/pip.yml | 6 ++++-- tests/requirements.txt | 16 +++++++--------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e5a149701..987b62e98b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,7 +84,8 @@ jobs: key: ${{ runner.os }}-pip-${{ matrix.python }}-x64-${{ hashFiles('tests/requirements.txt') }} - name: Prepare env - run: python -m pip install -r tests/requirements.txt --prefer-binary + run: | + python -m pip install -r tests/requirements.txt --only-binary=:all: - name: Setup annotations on Linux if: runner.os == 'Linux' @@ -108,7 +109,7 @@ jobs: - name: C++11 tests # TODO: Figure out how to load the DLL on Python 3.8+ - if: "!(runner.os == 'Windows' && (matrix.python == 3.8 || matrix.python == 3.9 || matrix.python == '3.10' || matrix.python == '3.11-dev'))" + if: "!(runner.os == 'Windows' && (matrix.python == 3.8 || matrix.python == 3.9 || matrix.python == '3.10' || matrix.python == '3.11-dev' || matrix.python == 'pypy-3.8'))" run: cmake --build . --target cpptest -j 2 - name: Interface test C++11 @@ -136,7 +137,7 @@ jobs: - name: C++ tests # TODO: Figure out how to load the DLL on Python 3.8+ - if: "!(runner.os == 'Windows' && (matrix.python == 3.8 || matrix.python == 3.9 || matrix.python == '3.10' || matrix.python == '3.11-dev'))" + if: "!(runner.os == 'Windows' && (matrix.python == 3.8 || matrix.python == 3.9 || matrix.python == '3.10' || matrix.python == '3.11-dev' || matrix.python == 'pypy-3.8'))" run: cmake --build build2 --target cpptest # Third build - C++17 mode with unstable ABI @@ -236,7 +237,8 @@ jobs: sudo apt-get install libc6-dbg # Needed by Valgrind - name: Prepare env - run: python -m pip install -r tests/requirements.txt --prefer-binary + run: | + python -m pip install -r tests/requirements.txt --only-binary=:all: - name: Configure run: > @@ -513,7 +515,7 @@ jobs: - name: Install dependencies run: | set +e; source /opt/intel/oneapi/setvars.sh; set -e - python3 -m pip install -r tests/requirements.txt --prefer-binary + python3 -m pip install -r tests/requirements.txt --only-binary=:all: - name: Configure C++11 run: | @@ -604,7 +606,8 @@ jobs: run: python3 -m pip install --upgrade pip - name: Install dependencies - run: python3 -m pip install cmake -r tests/requirements.txt --prefer-binary + run: | + python3 -m pip install cmake -r tests/requirements.txt --only-binary=:all: - name: VAR_BUILD_TYPE 7 if: matrix.centos == 7 @@ -760,7 +763,8 @@ jobs: arch: x86 - name: Prepare env - run: python -m pip install -r tests/requirements.txt --prefer-binary + run: | + python -m pip install -r tests/requirements.txt --only-binary=:all: # First build - C++11 mode and inplace - name: Configure ${{ matrix.args }} @@ -806,7 +810,8 @@ jobs: toolset: 14.0 - name: Prepare env - run: python -m pip install -r tests/requirements.txt --prefer-binary + run: | + python -m pip install -r tests/requirements.txt --only-binary=:all: # First build - C++11 mode and inplace - name: Configure @@ -855,7 +860,8 @@ jobs: uses: jwlawson/actions-setup-cmake@v1.11 - name: Prepare env - run: python -m pip install -r tests/requirements.txt --prefer-binary + run: | + python -m pip install -r tests/requirements.txt --only-binary=:all: # First build - C++11 mode and inplace - name: Configure diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index 5547a5e285..cafb5c1589 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -29,7 +29,8 @@ jobs: python-version: 2.7 - name: Prepare env - run: python -m pip install -r tests/requirements.txt --prefer-binary + run: | + python -m pip install -r tests/requirements.txt --only-binary=:all: - name: Python Packaging tests run: pytest tests/extra_python_package/ @@ -50,7 +51,8 @@ jobs: python-version: 3.8 - name: Prepare env - run: python -m pip install -r tests/requirements.txt build twine --prefer-binary + run: | + python -m pip install -r tests/requirements.txt build twine --only-binary=:all: - name: Python Packaging tests run: pytest tests/extra_python_package/ diff --git a/tests/requirements.txt b/tests/requirements.txt index ec32bf1dae..8d2742a71c 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,14 +1,12 @@ ---extra-index-url https://antocuni.github.io/pypy-wheels/manylinux2010/ -numpy==1.16.6; python_version<"3.6" and sys_platform!="win32" -numpy==1.19.0; platform_python_implementation=="PyPy" and sys_platform=="darwin" and python_version=="3.6" -numpy==1.20.0; platform_python_implementation=="PyPy" and sys_platform=="darwin" and python_version=="3.7" -numpy==1.19.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version=="3.6" -numpy==1.21.2; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.7" and python_version<"3.10" -numpy==1.21.2; platform_python_implementation!="PyPy" and sys_platform=="linux" and python_version=="3.10" +numpy==1.16.6; python_version<"3.6" and sys_platform!="win32" and platform_python_implementation!="PyPy" +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" 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" pytest==6.2.4; python_version>="3.6" pytest-timeout -scipy==1.2.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version<"3.6" -scipy==1.5.4; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.6" and python_version<"3.10" +scipy==1.2.3; platform_python_implementation!="PyPy" and python_version<"3.6" +scipy==1.5.4; platform_python_implementation!="PyPy" and python_version>="3.6" and python_version<"3.10" From b04f4cd930bcf696e1ae2f667c8f936aebfda839 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 25 Oct 2021 16:53:58 -0400 Subject: [PATCH 11/12] ci: only binary numpy, wait on pypy 3.8 --- .github/workflows/ci.yml | 19 +++++++++++-------- .github/workflows/pip.yml | 7 +++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 987b62e98b..f217ea8dac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,9 @@ concurrency: group: test-${{ github.ref }} cancel-in-progress: true +env: + PIP_ONLY_BINARY: numpy + jobs: # This is the "main" test suite, which tests a large number of different # versions of default compilers and Python versions in GitHub Actions. @@ -29,7 +32,7 @@ jobs: - '3.10' # - '3.11-dev' - 'pypy-3.7-v7.3.5' - - 'pypy-3.8' + # - 'pypy-3.8' # Items in here will either be added to the build matrix (if not # present), or add new keys to an existing matrix element if all the @@ -85,7 +88,7 @@ jobs: - name: Prepare env run: | - python -m pip install -r tests/requirements.txt --only-binary=:all: + python -m pip install -r tests/requirements.txt - name: Setup annotations on Linux if: runner.os == 'Linux' @@ -238,7 +241,7 @@ jobs: - name: Prepare env run: | - python -m pip install -r tests/requirements.txt --only-binary=:all: + python -m pip install -r tests/requirements.txt - name: Configure run: > @@ -515,7 +518,7 @@ jobs: - name: Install dependencies run: | set +e; source /opt/intel/oneapi/setvars.sh; set -e - python3 -m pip install -r tests/requirements.txt --only-binary=:all: + python3 -m pip install -r tests/requirements.txt - name: Configure C++11 run: | @@ -607,7 +610,7 @@ jobs: - name: Install dependencies run: | - python3 -m pip install cmake -r tests/requirements.txt --only-binary=:all: + python3 -m pip install cmake -r tests/requirements.txt - name: VAR_BUILD_TYPE 7 if: matrix.centos == 7 @@ -764,7 +767,7 @@ jobs: - name: Prepare env run: | - python -m pip install -r tests/requirements.txt --only-binary=:all: + python -m pip install -r tests/requirements.txt # First build - C++11 mode and inplace - name: Configure ${{ matrix.args }} @@ -811,7 +814,7 @@ jobs: - name: Prepare env run: | - python -m pip install -r tests/requirements.txt --only-binary=:all: + python -m pip install -r tests/requirements.txt # First build - C++11 mode and inplace - name: Configure @@ -861,7 +864,7 @@ jobs: - name: Prepare env run: | - python -m pip install -r tests/requirements.txt --only-binary=:all: + python -m pip install -r tests/requirements.txt # First build - C++11 mode and inplace - name: Configure diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index cafb5c1589..203f350bb1 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -12,6 +12,9 @@ on: types: - published +env: + PIP_ONLY_BINARY: numpy + jobs: # This builds the sdists and wheels and makes sure the files are exactly as # expected. Using Windows and Python 2.7, since that is often the most @@ -30,7 +33,7 @@ jobs: - name: Prepare env run: | - python -m pip install -r tests/requirements.txt --only-binary=:all: + python -m pip install -r tests/requirements.txt - name: Python Packaging tests run: pytest tests/extra_python_package/ @@ -52,7 +55,7 @@ jobs: - name: Prepare env run: | - python -m pip install -r tests/requirements.txt build twine --only-binary=:all: + python -m pip install -r tests/requirements.txt build twine - name: Python Packaging tests run: pytest tests/extra_python_package/ From 7f1fa8c9b5c8428ec9c2c89da7cb4657182d3555 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 26 Oct 2021 12:56:11 -0400 Subject: [PATCH 12/12] refactor: address review --- include/pybind11/detail/type_caster_base.h | 13 ++++++------- include/pybind11/pybind11.h | 11 ++++++----- tests/CMakeLists.txt | 21 ++++++++++++--------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 2424fb00e1..00ce1a7a1e 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -469,19 +469,18 @@ PYBIND11_NOINLINE std::string error_string() { errorString += "\n\nAt:\n"; while (frame) { #if PY_VERSION_HEX >= 0x03090000 - PyCodeObject *code = PyFrame_GetCode(frame); + PyCodeObject *f_code = PyFrame_GetCode(frame); #else - PyCodeObject *code = frame->f_code; + PyCodeObject *f_code = frame->f_code; + Py_INCREF(f_code); #endif int lineno = PyFrame_GetLineNumber(frame); errorString += - " " + handle(code->co_filename).cast() + + " " + handle(f_code->co_filename).cast() + "(" + std::to_string(lineno) + "): " + - handle(code->co_name).cast() + "\n"; + handle(f_code->co_name).cast() + "\n"; frame = frame->f_back; -#if PY_VERSION_HEX >= 0x03090000 - Py_DECREF(code); -#endif + Py_DECREF(f_code); } } #endif diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 32b1bd6afa..bfc1c368c0 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -2339,21 +2339,22 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty #if PY_VERSION_HEX >= 0x03090000 PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get()); if (frame != nullptr) { - PyCodeObject *code = PyFrame_GetCode(frame); - if ((std::string) str(code->co_name) == name && code->co_argcount > 0) { + PyCodeObject *f_code = PyFrame_GetCode(frame); + // f_code is guaranteed to not be NULL + if ((std::string) str(f_code->co_name) == name && f_code->co_argcount > 0) { PyObject* locals = PyEval_GetLocals(); if (locals != nullptr) { PyObject *self_caller = dict_getitem( - locals, PyTuple_GET_ITEM(code->co_varnames, 0) + locals, PyTuple_GET_ITEM(f_code->co_varnames, 0) ); if (self_caller == self.ptr()) { - Py_DECREF(code); + Py_DECREF(f_code); Py_DECREF(frame); return function(); } } } - Py_DECREF(code); + Py_DECREF(f_code); Py_DECREF(frame); } #else diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b0ba077522..09f83bc0de 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -175,13 +175,13 @@ set(PYBIND11_EIGEN_REPO "https://gitlab.com/libeigen/eigen.git" CACHE STRING "Eigen repository to use for tests") # Always use a hash for reconfigure speed and security reasons -set(PYBIND11_EIGEN_VERSION - "929bc0e191d0927b1735b9a1ddc0e8b77e3a25ec" - CACHE STRING "Eigen version to use for tests") -# Pretty print the version (keep in sync) -set(PYBIND11_EIGEN_VERSION_STRING - "3.4.0" - CACHE STRING "Eigen version string to use for tests") +# Include the version number for pretty printing (keep in sync) +set(PYBIND11_EIGEN_VERSION_AND_HASH + "3.4.0;929bc0e191d0927b1735b9a1ddc0e8b77e3a25ec" + CACHE STRING "Eigen version to use for tests, format: VERSION;HASH") + +list(GET PYBIND11_EIGEN_VERSION_AND_HASH 0 PYBIND11_EIGEN_VERSION_STRING) +list(GET PYBIND11_EIGEN_VERSION_AND_HASH 1 PYBIND11_EIGEN_VERSION_HASH) # Check if Eigen is available; if not, remove from PYBIND11_TEST_FILES (but # keep it in PYBIND11_PYTEST_FILES, so that we get the "eigen is not installed" @@ -200,11 +200,14 @@ if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1) FetchContent_Declare( eigen GIT_REPOSITORY "${PYBIND11_EIGEN_REPO}" - GIT_TAG "${PYBIND11_EIGEN_VERSION}") + GIT_TAG "${PYBIND11_EIGEN_VERSION_HASH}") FetchContent_GetProperties(eigen) if(NOT eigen_POPULATED) - message(STATUS "Downloading Eigen") + message( + STATUS + "Downloading Eigen ${PYBIND11_EIGEN_VERSION_STRING} (${PYBIND11_EIGEN_VERSION_HASH}) from ${PYBIND11_EIGEN_REPO}" + ) FetchContent_Populate(eigen) endif()