diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index 149a8a3dc9..0000000000 --- a/.appveyor.yml +++ /dev/null @@ -1,37 +0,0 @@ -version: 1.0.{build} -image: -- Visual Studio 2015 -test: off -skip_branch_with_pr: true -build: - parallel: true -platform: -- x86 -environment: - matrix: - - PYTHON: 36 - CONFIG: Debug - - PYTHON: 27 - CONFIG: Debug -install: -- ps: | - $env:CMAKE_GENERATOR = "Visual Studio 14 2015" - if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" } - $env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH" - python -W ignore -m pip install --upgrade pip wheel - python -W ignore -m pip install pytest numpy --no-warn-script-location -- ps: | - Start-FileDownload 'https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip' - 7z x eigen-3.3.7.zip -y > $null - $env:CMAKE_INCLUDE_PATH = "eigen-3.3.7;$env:CMAKE_INCLUDE_PATH" -build_script: -- cmake -G "%CMAKE_GENERATOR%" -A "%CMAKE_ARCH%" - -DCMAKE_CXX_STANDARD=14 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DCMAKE_SUPPRESS_REGENERATION=1 - . -- set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" -- cmake --build . --config %CONFIG% --target pytest -- /m /v:m /logger:%MSBuildLogger% -- cmake --build . --config %CONFIG% --target cpptest -- /m /v:m /logger:%MSBuildLogger% -on_failure: if exist "tests\test_cmake_build" type tests\test_cmake_build\*.log* diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c45adab284..6c6f030929 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,15 +16,12 @@ jobs: strategy: fail-fast: false matrix: - runs-on: [ubuntu-latest, windows-latest, macos-latest] + runs-on: [ubuntu-latest] python: - - 2.7 - 3.5 - 3.6 - 3.9 - 3.10-dev - - pypy2 - - pypy3 # 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 @@ -38,22 +35,6 @@ jobs: python: 3.6 args: > -DPYBIND11_FINDPYTHON=ON - - runs-on: windows-latest - python: 3.6 - 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 }} @@ -163,510 +144,3 @@ jobs: # setuptools - name: Setuptools helpers test run: pytest tests/extra_setuptools - - - # Testing on clang using the excellent silkeh clang docker images - clang: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - clang: - - 3.6 - - 3.7 - - 3.9 - - 7 - - 9 - - dev - std: - - 11 - include: - - clang: 5 - std: 14 - - clang: 10 - std: 20 - - clang: 10 - std: 17 - - name: "🐍 3 • Clang ${{ matrix.clang }} • C++${{ matrix.std }} • x64" - container: "silkeh/clang:${{ matrix.clang }}" - - steps: - - uses: actions/checkout@v2 - - - name: Add wget and python3 - run: apt-get update && apt-get install -y python3-dev python3-numpy python3-pytest libeigen3-dev - - - name: Configure - shell: bash - run: > - cmake -S . -B build - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DCMAKE_CXX_STANDARD=${{ matrix.std }} - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - - - name: Build - run: cmake --build build -j 2 - - - name: Python tests - run: cmake --build build --target pytest - - - name: C++ tests - run: cmake --build build --target cpptest - - - name: Interface test - run: cmake --build build --target test_cmake_build - - - # Testing NVCC; forces sources to behave like .cu files - cuda: - runs-on: ubuntu-latest - name: "🐍 3.8 • CUDA 11 • Ubuntu 20.04" - container: nvidia/cuda:11.0-devel-ubuntu20.04 - - steps: - - uses: actions/checkout@v2 - - # tzdata will try to ask for the timezone, so set the DEBIAN_FRONTEND - - name: Install 🐍 3 - run: apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y cmake git python3-dev python3-pytest python3-numpy - - - name: Configure - run: cmake -S . -B build -DPYBIND11_CUDA_TESTS=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON - - - name: Build - run: cmake --build build -j2 --verbose - - - name: Python tests - run: cmake --build build --target pytest - - -# TODO: Internal compiler error - report to NVidia -# # Testing CentOS 8 + PGI compilers -# centos-nvhpc8: -# runs-on: ubuntu-latest -# name: "🐍 3 • CentOS8 / PGI 20.11 • x64" -# container: centos:8 -# -# steps: -# - uses: actions/checkout@v2 -# -# - name: Add Python 3 and a few requirements -# run: yum update -y && yum install -y git python3-devel python3-numpy python3-pytest make environment-modules -# -# - name: Install CMake with pip -# run: | -# python3 -m pip install --upgrade pip -# python3 -m pip install cmake --prefer-binary -# -# - name: Install NVidia HPC SDK -# run: > -# yum -y install -# https://developer.download.nvidia.com/hpc-sdk/20.11/nvhpc-20-11-20.11-1.x86_64.rpm -# https://developer.download.nvidia.com/hpc-sdk/20.11/nvhpc-2020-20.11-1.x86_64.rpm -# -# - name: Configure -# shell: bash -# run: | -# source /etc/profile.d/modules.sh -# module load /opt/nvidia/hpc_sdk/modulefiles/nvhpc/20.11 -# cmake -S . -B build -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_STANDARD=14 -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") -# -# - name: Build -# run: cmake --build build -j 2 --verbose -# -# - name: Python tests -# run: cmake --build build --target pytest -# -# - name: C++ tests -# run: cmake --build build --target cpptest -# -# - name: Interface test -# run: cmake --build build --target test_cmake_build - - - # Testing on CentOS 7 + PGI compilers, which seems to require more workarounds - centos-nvhpc7: - runs-on: ubuntu-latest - name: "🐍 3 • CentOS7 / PGI 20.9 • x64" - container: centos:7 - - steps: - - uses: actions/checkout@v2 - - - name: Add Python 3 and a few requirements - run: yum update -y && yum install -y epel-release && yum install -y git python3-devel make environment-modules cmake3 - - - name: Install NVidia HPC SDK - run: yum -y install https://developer.download.nvidia.com/hpc-sdk/20.9/nvhpc-20-9-20.9-1.x86_64.rpm https://developer.download.nvidia.com/hpc-sdk/20.9/nvhpc-2020-20.9-1.x86_64.rpm - - # On CentOS 7, we have to filter a few tests (compiler internal error) - # and allow deeper templete recursion (not needed on CentOS 8 with a newer - # standard library). On some systems, you many need further workarounds: - # https://github.com/pybind/pybind11/pull/2475 - - name: Configure - shell: bash - run: | - source /etc/profile.d/modules.sh - module load /opt/nvidia/hpc_sdk/modulefiles/nvhpc/20.9 - cmake3 -S . -B build -DDOWNLOAD_CATCH=ON \ - -DCMAKE_CXX_STANDARD=11 \ - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") \ - -DCMAKE_CXX_FLAGS="-Wc,--pending_instantiations=0" \ - -DPYBIND11_TEST_FILTER="test_smart_ptr.cpp;test_virtual_functions.cpp" - - # Building before installing Pip should produce a warning but not an error - - name: Build - run: cmake3 --build build -j 2 --verbose - - - name: Install CMake with pip - run: | - python3 -m pip install --upgrade pip - python3 -m pip install pytest - - - name: Python tests - run: cmake3 --build build --target pytest - - - name: C++ tests - run: cmake3 --build build --target cpptest - - - name: Interface test - run: cmake3 --build build --target test_cmake_build - - # Testing on GCC using the GCC docker images (only recent images supported) - gcc: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - gcc: - - 7 - - latest - std: - - 11 - include: - - gcc: 10 - std: 20 - - name: "🐍 3 • GCC ${{ matrix.gcc }} • C++${{ matrix.std }}• x64" - container: "gcc:${{ matrix.gcc }}" - - steps: - - uses: actions/checkout@v1 - - - name: Add Python 3 - run: apt-get update; apt-get install -y python3-dev python3-numpy python3-pytest python3-pip libeigen3-dev - - - name: Update pip - run: python3 -m pip install --upgrade pip - - - name: Setup CMake 3.18 - uses: jwlawson/actions-setup-cmake@v1.5 - with: - cmake-version: 3.18 - - - name: Configure - shell: bash - run: > - cmake -S . -B build - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DCMAKE_CXX_STANDARD=${{ matrix.std }} - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - - - name: Build - run: cmake --build build -j 2 - - - name: Python tests - run: cmake --build build --target pytest - - - name: C++ tests - run: cmake --build build --target cpptest - - - name: Interface test - run: cmake --build build --target test_cmake_build - - - # Testing on CentOS (manylinux uses a centos base, and this is an easy way - # to get GCC 4.8, which is the manylinux1 compiler). - centos: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - centos: - - 7 # GCC 4.8 - - 8 - - name: "🐍 3 • CentOS ${{ matrix.centos }} • x64" - container: "centos:${{ matrix.centos }}" - - steps: - - uses: actions/checkout@v2 - - - name: Add Python 3 - run: yum update -y && yum install -y python3-devel gcc-c++ make git - - - name: Update pip - run: python3 -m pip install --upgrade pip - - - name: Install dependencies - run: python3 -m pip install cmake -r tests/requirements.txt --prefer-binary - - - name: Configure - shell: bash - run: > - cmake -S . -B build - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=11 - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - - - name: Build - run: cmake --build build -j 2 - - - name: Python tests - run: cmake --build build --target pytest - - - name: C++ tests - run: cmake --build build --target cpptest - - - name: Interface test - run: cmake --build build --target test_cmake_build - - - # This tests an "install" with the CMake tools - install-classic: - name: "🐍 3.5 • Debian • x86 • Install" - runs-on: ubuntu-latest - container: i386/debian:stretch - - steps: - - uses: actions/checkout@v1 - - - name: Install requirements - run: | - apt-get update - apt-get install -y git make cmake g++ libeigen3-dev python3-dev python3-pip - pip3 install "pytest==3.1.*" - - - name: Configure for install - run: > - cmake . - -DPYBIND11_INSTALL=1 -DPYBIND11_TEST=0 - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - - - name: Make and install - run: make install - - - name: Copy tests to new directory - run: cp -a tests /pybind11-tests - - - name: Make a new test directory - run: mkdir /build-tests - - - name: Configure tests - run: > - cmake ../pybind11-tests - -DDOWNLOAD_CATCH=ON - -DPYBIND11_WERROR=ON - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - working-directory: /build-tests - - - name: Run tests - run: make pytest -j 2 - working-directory: /build-tests - - - # This verifies that the documentation is not horribly broken, and does a - # basic sanity check on the SDist. - doxygen: - name: "Documentation build test" - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - uses: actions/setup-python@v2 - - - name: Install Doxygen - run: sudo apt-get install -y doxygen librsvg2-bin # Changed to rsvg-convert in 20.04 - - - name: Install docs & setup requirements - run: python3 -m pip install -r docs/requirements.txt - - - name: Build docs - run: python3 -m sphinx -W -b html docs docs/.build - - - name: Make SDist - run: python3 setup.py sdist - - - run: git status --ignored - - - name: Check local include dir - run: > - ls pybind11; - python3 -c "import pybind11, pathlib; assert (a := pybind11.get_include()) == (b := str(pathlib.Path('include').resolve())), f'{a} != {b}'" - - - name: Compare Dists (headers only) - working-directory: include - run: | - python3 -m pip install --user -U ../dist/* - installed=$(python3 -c "import pybind11; print(pybind11.get_include() + '/pybind11')") - diff -rq $installed ./pybind11 - - win32: - strategy: - fail-fast: false - matrix: - python: - - 3.5 - - 3.6 - - 3.7 - - 3.8 - - 3.9 - - pypy3 - # TODO: fix hang on pypy2 - - include: - - python: 3.9 - args: -DCMAKE_CXX_STANDARD=20 -DDOWNLOAD_EIGEN=OFF - - python: 3.8 - args: -DCMAKE_CXX_STANDARD=17 - - name: "🐍 ${{ matrix.python }} • MSVC 2019 • x86 ${{ matrix.args }}" - runs-on: windows-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python }} - architecture: x86 - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.5 - - - name: Prepare MSVC - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x86 - - - name: Prepare env - run: python -m pip install -r tests/requirements.txt --prefer-binary - - # First build - C++11 mode and inplace - - name: Configure ${{ matrix.args }} - run: > - cmake -S . -B build - -G "Visual Studio 16 2019" -A Win32 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - ${{ matrix.args }} - - name: Build C++11 - run: cmake --build build -j 2 - - - name: Run tests - run: cmake --build build -t pytest - - win32-msvc2015: - name: "🐍 ${{ matrix.python }} • MSVC 2015 • x64" - runs-on: windows-latest - strategy: - fail-fast: false - matrix: - python: - - 2.7 - - 3.6 - - 3.7 - # todo: check/cpptest does not support 3.8+ yet - - steps: - - uses: actions/checkout@v2 - - - name: Setup 🐍 ${{ matrix.python }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python }} - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.5 - - - name: Prepare MSVC - uses: ilammy/msvc-dev-cmd@v1 - with: - toolset: 14.0 - - - name: Prepare env - run: python -m pip install -r tests/requirements.txt --prefer-binary - - # First build - C++11 mode and inplace - - name: Configure - run: > - cmake -S . -B build - -G "Visual Studio 14 2015" -A x64 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - - - name: Build C++14 - run: cmake --build build -j 2 - - - name: Run all checks - run: cmake --build build -t check - - - win32-msvc2017: - name: "🐍 ${{ matrix.python }} • MSVC 2017 • x64" - runs-on: windows-2016 - strategy: - fail-fast: false - matrix: - python: - - 2.7 - - 3.5 - - 3.7 - std: - - 14 - - include: - - python: 2.7 - std: 17 - args: > - -DCMAKE_CXX_FLAGS="/permissive- /EHsc /GR" - - steps: - - uses: actions/checkout@v2 - - - name: Setup 🐍 ${{ matrix.python }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python }} - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.5 - - - name: Prepare env - run: python -m pip install -r tests/requirements.txt --prefer-binary - - # First build - C++11 mode and inplace - - name: Configure - run: > - cmake -S . -B build - -G "Visual Studio 15 2017" -A x64 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=${{ matrix.std }} - ${{ matrix.args }} - - - name: Build ${{ matrix.std }} - run: cmake --build build -j 2 - - - name: Run all checks - run: cmake --build build -t check diff --git a/.github/workflows/configure.yml b/.github/workflows/configure.yml deleted file mode 100644 index 5eb6a9717f..0000000000 --- a/.github/workflows/configure.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: Config - -on: - workflow_dispatch: - pull_request: - push: - branches: - - master - - stable - - v* - -jobs: - # This tests various versions of CMake in various combinations, to make sure - # the configure step passes. - cmake: - strategy: - fail-fast: false - matrix: - runs-on: [ubuntu-latest, macos-latest, windows-latest] - arch: [x64] - cmake: [3.18] - - include: - - runs-on: ubuntu-latest - arch: x64 - cmake: 3.4 - - - runs-on: macos-latest - arch: x64 - cmake: 3.7 - - - runs-on: windows-2016 - arch: x86 - cmake: 3.8 - - - runs-on: windows-2016 - arch: x86 - cmake: 3.18 - - name: 🐍 3.7 • CMake ${{ matrix.cmake }} • ${{ matrix.runs-on }} - runs-on: ${{ matrix.runs-on }} - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python 3.7 - uses: actions/setup-python@v2 - with: - python-version: 3.7 - architecture: ${{ matrix.arch }} - - - name: Prepare env - run: python -m pip install -r tests/requirements.txt - - # An action for adding a specific version of CMake: - # https://github.com/jwlawson/actions-setup-cmake - - name: Setup CMake ${{ matrix.cmake }} - uses: jwlawson/actions-setup-cmake@v1.5 - with: - cmake-version: ${{ matrix.cmake }} - - # These steps use a directory with a space in it intentionally - - name: Make build directories - run: mkdir "build dir" - - - name: Configure - working-directory: build dir - shell: bash - run: > - cmake .. - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)") - - # Only build and test if this was manually triggered in the GitHub UI - - name: Build - working-directory: build dir - if: github.event_name == 'workflow_dispatch' - run: cmake --build . --config Release - - - name: Test - working-directory: build dir - if: github.event_name == 'workflow_dispatch' - run: cmake --build . --config Release --target check diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml deleted file mode 100644 index 5cebed17da..0000000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,46 +0,0 @@ -# This is a format job. Pre-commit has a first-party GitHub action, so we use -# that: https://github.com/pre-commit/action - -name: Format - -on: - workflow_dispatch: - pull_request: - push: - branches: - - master - - stable - - "v*" - -jobs: - pre-commit: - name: Format - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: pre-commit/action@v2.0.0 - with: - # Slow hooks are marked with manual - slow is okay here, run them too - extra_args: --hook-stage manual --all-files - - clang-tidy: - name: Clang-Tidy - runs-on: ubuntu-latest - container: silkeh/clang:10 - steps: - - uses: actions/checkout@v2 - - - name: Install requirements - run: apt-get update && apt-get install -y python3-dev python3-pytest - - - name: Configure - run: > - cmake -S . -B build - -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);--warnings-as-errors=*" - -DDOWNLOAD_EIGEN=ON - -DDOWNLOAD_CATCH=ON - -DCMAKE_CXX_STANDARD=17 - - - name: Build - run: cmake --build build -j 2 diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml deleted file mode 100644 index d2b5979681..0000000000 --- a/.github/workflows/labeler.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Labeler -on: - pull_request_target: - types: [closed] - -jobs: - label: - name: Labeler - runs-on: ubuntu-latest - steps: - - - uses: actions/labeler@main - if: github.event.pull_request.merged == true - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - configuration-path: .github/labeler_merged.yml diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml deleted file mode 100644 index 4414a12ee4..0000000000 --- a/.github/workflows/pip.yml +++ /dev/null @@ -1,103 +0,0 @@ -name: Pip - -on: - workflow_dispatch: - pull_request: - push: - branches: - - master - - stable - - v* - release: - types: - - published - -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 - # challenging matrix element. - test-packaging: - name: 🐍 2.7 • 📦 tests • windows-latest - runs-on: windows-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup 🐍 2.7 - uses: actions/setup-python@v2 - with: - python-version: 2.7 - - - name: Prepare env - run: python -m pip install -r tests/requirements.txt --prefer-binary - - - name: Python Packaging tests - run: pytest tests/extra_python_package/ - - - # This runs the packaging tests and also builds and saves the packages as - # artifacts. - packaging: - name: 🐍 3.8 • 📦 & 📦 tests • ubuntu-latest - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup 🐍 3.8 - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - - name: Prepare env - run: python -m pip install -r tests/requirements.txt build twine --prefer-binary - - - name: Python Packaging tests - run: pytest tests/extra_python_package/ - - - name: Build SDist and wheels - run: | - python -m build - PYBIND11_GLOBAL_SDIST=1 python -m build - - - name: Check metadata - run: twine check dist/* - - - name: Save standard package - uses: actions/upload-artifact@v2 - with: - name: standard - path: dist/pybind11-* - - - name: Save global package - uses: actions/upload-artifact@v2 - with: - name: global - path: dist/pybind11_global-* - - - - # When a GitHub release is made, upload the artifacts to PyPI - upload: - name: Upload to PyPI - runs-on: ubuntu-latest - if: github.event_name == 'release' && github.event.action == 'published' - needs: [packaging] - - steps: - - uses: actions/setup-python@v2 - - # Downloads all to directories matching the artifact names - - uses: actions/download-artifact@v2 - - - name: Publish standard package - uses: pypa/gh-action-pypi-publish@v1.4.1 - with: - password: ${{ secrets.pypi_password }} - packages_dir: standard/ - - - name: Publish global package - uses: pypa/gh-action-pypi-publish@v1.4.1 - with: - password: ${{ secrets.pypi_password_global }} - packages_dir: global/ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dae8b5ad43..8bd0f33d8e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -84,45 +84,49 @@ if(PYBIND11_CUDA_TESTS) set(CMAKE_CUDA_STANDARD_REQUIRED ON) endif() +# cmake-format: off # Full set of test files (you can override these; see below) set(PYBIND11_TEST_FILES - test_async.cpp - test_buffers.cpp - test_builtin_casters.cpp - test_call_policies.cpp - test_callbacks.cpp - test_chrono.cpp - test_class.cpp - test_constants_and_functions.cpp - test_copy_move.cpp - test_custom_type_casters.cpp - test_docstring_options.cpp - test_eigen.cpp - test_enum.cpp - test_eval.cpp - test_exceptions.cpp - test_factory_constructors.cpp - test_gil_scoped.cpp - test_iostream.cpp - test_kwargs_and_defaults.cpp - test_local_bindings.cpp - test_methods_and_attributes.cpp - test_modules.cpp - test_multiple_inheritance.cpp - test_numpy_array.cpp - test_numpy_dtypes.cpp - test_numpy_vectorize.cpp - test_opaque_types.cpp - test_operator_overloading.cpp - test_pickling.cpp - test_pytypes.cpp - test_sequences_and_iterators.cpp - test_smart_ptr.cpp - test_stl.cpp - test_stl_binders.cpp - test_tagbased_polymorphic.cpp - test_union.cpp - test_virtual_functions.cpp) + # test_async.cpp + # test_buffers.cpp + # test_builtin_casters.cpp + # test_call_policies.cpp + # test_callbacks.cpp + # test_chrono.cpp + # test_class.cpp + # test_constants_and_functions.cpp + # test_copy_move.cpp + # test_custom_type_casters.cpp + # test_docstring_options.cpp + # test_eigen.cpp + # test_enum.cpp + # test_eval.cpp + # test_exceptions.cpp + # test_factory_constructors.cpp + # test_gil_scoped.cpp + # test_iostream.cpp + # test_kwargs_and_defaults.cpp + # test_local_bindings.cpp + # test_methods_and_attributes.cpp + # test_modules.cpp + # test_multiple_inheritance.cpp + # test_numpy_array.cpp + # test_numpy_dtypes.cpp + # test_numpy_vectorize.cpp + # test_opaque_types.cpp + # test_operator_overloading.cpp + # test_pickling.cpp + # test_pytypes.cpp + # test_sequences_and_iterators.cpp + # test_smart_ptr.cpp + # test_stl.cpp + # test_stl_binders.cpp + # test_tagbased_polymorphic.cpp + # test_union.cpp + # test_virtual_functions.cpp) + test_keep_alive.cpp + ) +# cmake-format: on # Invoking cmake with something like: # cmake -DPYBIND11_TEST_OVERRIDE="test_callbacks.cpp;test_pickling.cpp" .. diff --git a/tests/test_keep_alive.cpp b/tests/test_keep_alive.cpp new file mode 100644 index 0000000000..b727418894 --- /dev/null +++ b/tests/test_keep_alive.cpp @@ -0,0 +1,12 @@ +#include "pybind11_tests.h" + +class SimpleClass {}; + +TEST_SUBMODULE(keep_alive, m) { + m.def("keep_alive_impl", [](py::handle nurse, py::handle patient) { + py::detail::keep_alive_impl(nurse, patient); + }); + + py::class_(m, "SimpleClass") + .def(py::init()); +} diff --git a/tests/test_keep_alive.py b/tests/test_keep_alive.py new file mode 100644 index 0000000000..fd4f109dc0 --- /dev/null +++ b/tests/test_keep_alive.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# N.B. This is only focused on CPython, so using gc directly, rather than +# `pytest.gc_collect()`. +import gc +import weakref + +from pybind11_tests import keep_alive as m + + +def test_keep_alive_cycle(): + # See #2761. + o1 = m.SimpleClass() + wr1 = weakref.ref(o1) + o2 = m.SimpleClass() + wr2 = weakref.ref(o2) + assert wr1() is not None + assert wr2() is not None + + # Add a direct cycle. + m.keep_alive_impl(o1, o2) + m.keep_alive_impl(o2, o1) + + del o1 + del o2 + gc.collect() + + # This shows that py::keep_alive will leak objects :( + assert wr1() is not None + assert wr2() is not None