diff --git a/.appveyor.yml b/.appveyor.yml index 360760ac8d..934edfbd0b 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,6 +2,8 @@ version: 1.0.{build} image: - Visual Studio 2017 test: off +skip_commits: + message: /.*/ # Skip ALL commits. skip_branch_with_pr: true build: parallel: true diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 2c7d170839..0000000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: - # Maintain dependencies for GitHub Actions - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "daily" diff --git a/.github/labeler.yml b/.github/labeler.yml deleted file mode 100644 index abb0d05aaa..0000000000 --- a/.github/labeler.yml +++ /dev/null @@ -1,8 +0,0 @@ -docs: -- any: - - 'docs/**/*.rst' - - '!docs/changelog.rst' - - '!docs/upgrade.rst' - -ci: -- '.github/workflows/*.yml' diff --git a/.github/labeler_merged.yml b/.github/labeler_merged.yml deleted file mode 100644 index 2374ad42e4..0000000000 --- a/.github/labeler_merged.yml +++ /dev/null @@ -1,3 +0,0 @@ -needs changelog: -- all: - - '!docs/changelog.rst' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index a11cae1ab0..0000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,969 +0,0 @@ -name: CI - -on: - workflow_dispatch: - pull_request: - push: - branches: - - master - - stable - - v* - -concurrency: - group: test-${{ github.ref }} - cancel-in-progress: true - -env: - PIP_ONLY_BINARY: numpy - FORCE_COLOR: 3 - PYTEST_TIMEOUT: 300 - -jobs: - # This is the "main" test suite, which tests a large number of different - # versions of default compilers and Python versions in GitHub Actions. - standard: - strategy: - fail-fast: false - matrix: - runs-on: [ubuntu-latest, windows-2022, macos-latest] - python: - - '3.6' - - '3.9' - - '3.10' - - '3.11' - - 'pypy-3.7' - - 'pypy-3.8' - - 'pypy-3.9' - - # 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 - # existing keys match. - # - # We support an optional key: args, for cmake args - include: - # Just add a key - - runs-on: ubuntu-latest - python: '3.6' - args: > - -DPYBIND11_FINDPYTHON=ON - -DCMAKE_CXX_FLAGS="-D_=1" - - runs-on: ubuntu-latest - python: 'pypy-3.8' - args: > - -DPYBIND11_FINDPYTHON=ON - - runs-on: windows-2019 - python: '3.6' - args: > - -DPYBIND11_FINDPYTHON=ON - # Inject a couple Windows 2019 runs - - runs-on: windows-2019 - python: '3.9' - - name: "🐍 ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}" - runs-on: ${{ matrix.runs-on }} - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - - name: Setup Boost (Linux) - # Can't use boost + define _ - if: runner.os == 'Linux' && matrix.python != '3.6' - run: sudo apt-get install libboost-dev - - - name: Setup Boost (macOS) - if: runner.os == 'macOS' - run: brew install boost - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - name: Cache wheels - if: runner.os == 'macOS' - uses: actions/cache@v3 - with: - # This path is specific to macOS - we really only need it for PyPy NumPy wheels - # See https://github.com/actions/cache/blob/master/examples.md#python---pip - # for ways to do this more generally - path: ~/Library/Caches/pip - # Look to see if there is a cache hit for the corresponding requirements file - key: ${{ runner.os }}-pip-${{ matrix.python }}-x64-${{ hashFiles('tests/requirements.txt') }} - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt - - - name: Setup annotations on Linux - if: runner.os == 'Linux' - run: python -m pip install pytest-github-actions-annotate-failures - - # First build - C++11 mode and inplace - # More-or-less randomly adding -DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON here. - - name: Configure C++11 ${{ matrix.args }} - run: > - cmake -S . -B . - -DPYBIND11_WERROR=ON - -DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=11 - ${{ matrix.args }} - - - name: Build C++11 - run: cmake --build . -j 2 - - - name: Python tests C++11 - run: cmake --build . --target pytest -j 2 - - - 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' || matrix.python == 'pypy-3.8'))" - run: cmake --build . --target cpptest -j 2 - - - name: Interface test C++11 - run: cmake --build . --target test_cmake_build - - - name: Clean directory - run: git clean -fdx - - # Second build - C++17 mode and in a build directory - # More-or-less randomly adding -DPYBIND11_SIMPLE_GIL_MANAGEMENT=OFF here. - - name: Configure C++17 - run: > - cmake -S . -B build2 - -DPYBIND11_WERROR=ON - -DPYBIND11_SIMPLE_GIL_MANAGEMENT=OFF - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=17 - ${{ matrix.args }} - - - name: Build - run: cmake --build build2 -j 2 - - - name: Python tests - run: cmake --build build2 --target pytest - - - 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' || matrix.python == 'pypy-3.8'))" - run: cmake --build build2 --target cpptest - - # Third build - C++17 mode with unstable ABI - - name: Configure (unstable ABI) - run: > - cmake -S . -B build3 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=17 - -DPYBIND11_INTERNALS_VERSION=10000000 - "-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp" - ${{ matrix.args }} - - - name: Build (unstable ABI) - run: cmake --build build3 -j 2 - - - name: Python tests (unstable ABI) - run: cmake --build build3 --target pytest - - - name: Interface test - run: cmake --build build2 --target test_cmake_build - - # This makes sure the setup_helpers module can build packages using - # setuptools - - name: Setuptools helpers test - run: pytest tests/extra_setuptools - if: "!(matrix.runs-on == 'windows-2022')" - - - deadsnakes: - strategy: - fail-fast: false - matrix: - include: - # TODO: Fails on 3.10, investigate - - python-version: "3.9" - python-debug: true - valgrind: true - - python-version: "3.11" - python-debug: false - - name: "🐍 ${{ matrix.python-version }}${{ matrix.python-debug && '-dbg' || '' }} (deadsnakes)${{ matrix.valgrind && ' • Valgrind' || '' }} • x64" - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python ${{ matrix.python-version }} (deadsnakes) - uses: deadsnakes/action@v2.1.1 - with: - python-version: ${{ matrix.python-version }} - debug: ${{ matrix.python-debug }} - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - name: Valgrind cache - if: matrix.valgrind - uses: actions/cache@v3 - id: cache-valgrind - with: - path: valgrind - key: 3.16.1 # Valgrind version - - - name: Compile Valgrind - if: matrix.valgrind && steps.cache-valgrind.outputs.cache-hit != 'true' - run: | - VALGRIND_VERSION=3.16.1 - curl https://sourceware.org/pub/valgrind/valgrind-$VALGRIND_VERSION.tar.bz2 -o - | tar xj - mv valgrind-$VALGRIND_VERSION valgrind - cd valgrind - ./configure - make -j 2 > /dev/null - - - name: Install Valgrind - if: matrix.valgrind - working-directory: valgrind - run: | - sudo make install - sudo apt-get update - sudo apt-get install libc6-dbg # Needed by Valgrind - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt - - - name: Configure - env: - SETUPTOOLS_USE_DISTUTILS: stdlib - run: > - cmake -S . -B build - -DCMAKE_BUILD_TYPE=Debug - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=17 - - - 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: Run Valgrind on Python tests - if: matrix.valgrind - run: cmake --build build --target memcheck - - - # 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 - - clang: 11 - std: 20 - - clang: 12 - std: 20 - - clang: 13 - std: 20 - - clang: 14 - std: 20 - - name: "🐍 3 • Clang ${{ matrix.clang }} • C++${{ matrix.std }} • x64" - container: "silkeh/clang:${{ matrix.clang }}" - - steps: - - uses: actions/checkout@v3 - - - 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.10 • CUDA 11.7 • Ubuntu 22.04" - container: nvidia/cuda:11.7.0-devel-ubuntu22.04 - - steps: - - uses: actions/checkout@v3 - - # 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@v3 -# -# - 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 22.9 • x64" - container: centos:7 - - steps: - - uses: actions/checkout@v3 - - - 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 yum-utils - - - name: Install NVidia HPC SDK - run: yum-config-manager --add-repo https://developer.download.nvidia.com/hpc-sdk/rhel/nvhpc.repo && yum -y install nvhpc-22.9 - - # On CentOS 7, we have to filter a few tests (compiler internal error) - # and allow deeper template 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/22.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" - - # 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: - include: - - { gcc: 7, std: 11 } - - { gcc: 7, std: 17 } - - { gcc: 8, std: 14 } - - { gcc: 8, std: 17 } - - { gcc: 10, std: 17 } - - { gcc: 11, std: 20 } - - { gcc: 12, std: 20 } - - name: "🐍 3 • GCC ${{ matrix.gcc }} • C++${{ matrix.std }}• x64" - container: "gcc:${{ matrix.gcc }}" - - steps: - - uses: actions/checkout@v3 - - - 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: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - 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 ICC using the oneAPI apt repo - icc: - runs-on: ubuntu-20.04 - strategy: - fail-fast: false - - name: "🐍 3 • ICC latest • x64" - - steps: - - uses: actions/checkout@v3 - - - name: Add apt repo - run: | - sudo apt-get update - sudo apt-get install -y wget build-essential pkg-config cmake ca-certificates gnupg - wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB - sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB - echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list - - - name: Add ICC & Python 3 - run: sudo apt-get update; sudo apt-get install -y intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic cmake python3-dev python3-numpy python3-pytest python3-pip - - - name: Update pip - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - python3 -m pip install --upgrade pip - - - name: Install dependencies - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - python3 -m pip install -r tests/requirements.txt - - - name: Configure C++11 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake -S . -B build-11 \ - -DPYBIND11_WERROR=ON \ - -DDOWNLOAD_CATCH=ON \ - -DDOWNLOAD_EIGEN=OFF \ - -DCMAKE_CXX_STANDARD=11 \ - -DCMAKE_CXX_COMPILER=$(which icpc) \ - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - - - name: Build C++11 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake --build build-11 -j 2 -v - - - name: Python tests C++11 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - sudo service apport stop - cmake --build build-11 --target check - - - name: C++ tests C++11 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake --build build-11 --target cpptest - - - name: Interface test C++11 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake --build build-11 --target test_cmake_build - - - name: Configure C++17 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake -S . -B build-17 \ - -DPYBIND11_WERROR=ON \ - -DDOWNLOAD_CATCH=ON \ - -DDOWNLOAD_EIGEN=OFF \ - -DCMAKE_CXX_STANDARD=17 \ - -DCMAKE_CXX_COMPILER=$(which icpc) \ - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - - - name: Build C++17 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake --build build-17 -j 2 -v - - - name: Python tests C++17 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - sudo service apport stop - cmake --build build-17 --target check - - - name: C++ tests C++17 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake --build build-17 --target cpptest - - - name: Interface test C++17 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake --build build-17 --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: - container: - - "centos:7" # GCC 4.8 - - "almalinux:8" - - "almalinux:9" - - name: "🐍 3 • ${{ matrix.container }} • x64" - container: "${{ matrix.container }}" - - steps: - - uses: actions/checkout@v3 - - - name: Add Python 3 (RHEL 7) - if: matrix.container == 'centos:7' - run: yum update -y && yum install -y python3-devel gcc-c++ make git - - - name: Add Python 3 (RHEL 8+) - if: matrix.container != 'centos:7' - run: dnf update -y && dnf 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 - - - name: Configure - shell: bash - run: > - cmake -S . -B build - -DCMAKE_BUILD_TYPE=MinSizeRel - -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.7 • Debian • x86 • Install" - runs-on: ubuntu-latest - container: i386/debian:buster - - steps: - - uses: actions/checkout@v1 # Required to run inside docker - - - name: Install requirements - run: | - apt-get update - apt-get install -y git make cmake g++ libeigen3-dev python3-dev python3-pip - pip3 install "pytest==6.*" - - - 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: Python tests - run: make pytest -j 2 - working-directory: /build-tests - - - # This verifies that the documentation is not horribly broken, and does a - # basic validation check on the SDist. - doxygen: - name: "Documentation build test" - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-python@v4 - with: - python-version: "3.x" - - - name: Install Doxygen - run: sudo apt-get install -y doxygen librsvg2-bin # Changed to rsvg-convert in 20.04 - - - name: Build docs - run: pipx run nox -s docs - - - name: Make SDist - run: pipx run nox -s build -- --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/*.tar.gz - installed=$(python3 -c "import pybind11; print(pybind11.get_include() + '/pybind11')") - diff -rq $installed ./pybind11 - - win32: - strategy: - fail-fast: false - matrix: - python: - - 3.6 - - 3.7 - - 3.8 - - 3.9 - - include: - - python: 3.9 - args: -DCMAKE_CXX_STANDARD=20 - - python: 3.8 - args: -DCMAKE_CXX_STANDARD=17 - - python: 3.7 - args: -DCMAKE_CXX_STANDARD=14 - - - name: "🐍 ${{ matrix.python }} • MSVC 2019 • x86 ${{ matrix.args }}" - runs-on: windows-2019 - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - architecture: x86 - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - name: Prepare MSVC - uses: ilammy/msvc-dev-cmd@v1.12.0 - with: - arch: x86 - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt - - # 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: Python tests - run: cmake --build build -t pytest - - win32-debug: - strategy: - fail-fast: false - matrix: - python: - - 3.8 - - 3.9 - - include: - - python: 3.9 - args: -DCMAKE_CXX_STANDARD=20 - - python: 3.8 - args: -DCMAKE_CXX_STANDARD=17 - - name: "🐍 ${{ matrix.python }} • MSVC 2019 (Debug) • x86 ${{ matrix.args }}" - runs-on: windows-2019 - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - architecture: x86 - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - name: Prepare MSVC - uses: ilammy/msvc-dev-cmd@v1.12.0 - with: - arch: x86 - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt - - # First build - C++11 mode and inplace - - name: Configure ${{ matrix.args }} - run: > - cmake -S . -B build - -G "Visual Studio 16 2019" -A Win32 - -DCMAKE_BUILD_TYPE=Debug - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - ${{ matrix.args }} - - name: Build C++11 - run: cmake --build build --config Debug -j 2 - - - name: Python tests - run: cmake --build build --config Debug -t pytest - - - windows-2022: - strategy: - fail-fast: false - matrix: - python: - - 3.9 - - name: "🐍 ${{ matrix.python }} • MSVC 2022 C++20 • x64" - runs-on: windows-2022 - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - - name: Prepare env - run: | - python3 -m pip install -r tests/requirements.txt - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - name: Configure C++20 - run: > - cmake -S . -B build - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=20 - - - name: Build C++20 - run: cmake --build build -j 2 - - - name: Python tests - run: cmake --build build --target pytest - - - name: C++20 tests - run: cmake --build build --target cpptest -j 2 - - - name: Interface test C++20 - run: cmake --build build --target test_cmake_build - - mingw: - name: "🐍 3 • windows-latest • ${{ matrix.sys }}" - runs-on: windows-latest - defaults: - run: - shell: msys2 {0} - strategy: - fail-fast: false - matrix: - include: - - { sys: mingw64, env: x86_64 } - - { sys: mingw32, env: i686 } - steps: - - uses: msys2/setup-msys2@v2 - with: - msystem: ${{matrix.sys}} - install: >- - git - mingw-w64-${{matrix.env}}-gcc - mingw-w64-${{matrix.env}}-python-pip - mingw-w64-${{matrix.env}}-python-numpy - mingw-w64-${{matrix.env}}-python-scipy - mingw-w64-${{matrix.env}}-cmake - mingw-w64-${{matrix.env}}-make - mingw-w64-${{matrix.env}}-python-pytest - mingw-w64-${{matrix.env}}-eigen3 - mingw-w64-${{matrix.env}}-boost - mingw-w64-${{matrix.env}}-catch - - - uses: actions/checkout@v3 - - - name: Configure C++11 - # LTO leads to many undefined reference like - # `pybind11::detail::function_call::function_call(pybind11::detail::function_call&&) - run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build - - - name: Build C++11 - run: cmake --build build -j 2 - - - name: Python tests C++11 - run: cmake --build build --target pytest -j 2 - - - name: C++11 tests - run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build --target cpptest -j 2 - - - name: Interface test C++11 - run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build --target test_cmake_build - - - name: Clean directory - run: git clean -fdx - - - name: Configure C++14 - run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build2 - - - name: Build C++14 - run: cmake --build build2 -j 2 - - - name: Python tests C++14 - run: cmake --build build2 --target pytest -j 2 - - - name: C++14 tests - run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build2 --target cpptest -j 2 - - - name: Interface test C++14 - run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build2 --target test_cmake_build - - - name: Clean directory - run: git clean -fdx - - - name: Configure C++17 - run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build3 - - - name: Build C++17 - run: cmake --build build3 -j 2 - - - name: Python tests C++17 - run: cmake --build build3 --target pytest -j 2 - - - name: C++17 tests - run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build3 --target cpptest -j 2 - - - name: Interface test C++17 - run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build3 --target test_cmake_build diff --git a/.github/workflows/configure.yml b/.github/workflows/configure.yml deleted file mode 100644 index 5ec0dd462f..0000000000 --- a/.github/workflows/configure.yml +++ /dev/null @@ -1,80 +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.23"] - - include: - - runs-on: ubuntu-latest - arch: x64 - cmake: 3.4 - - - runs-on: macos-latest - arch: x64 - cmake: 3.7 - - - runs-on: windows-2019 - arch: x64 # x86 compilers seem to be missing on 2019 image - cmake: 3.18 - - name: 🐍 3.7 • CMake ${{ matrix.cmake }} • ${{ matrix.runs-on }} - runs-on: ${{ matrix.runs-on }} - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python 3.7 - uses: actions/setup-python@v4 - 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.13 - 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 31d893c479..0000000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,55 +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*" - -env: - FORCE_COLOR: 3 - -jobs: - pre-commit: - name: Format - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.x" - - name: Add matchers - run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json" - - uses: pre-commit/action@v3.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: - # When making changes here, please also review the "Clang-Tidy" section - # in .github/CONTRIBUTING.md and update as needed. - name: Clang-Tidy - runs-on: ubuntu-latest - container: silkeh/clang:13 - steps: - - uses: actions/checkout@v3 - - - 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);--use-color;--warnings-as-errors=*" - -DDOWNLOAD_EIGEN=ON - -DDOWNLOAD_CATCH=ON - -DCMAKE_CXX_STANDARD=17 - - - name: Build - run: cmake --build build -j 2 -- --keep-going diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml deleted file mode 100644 index 165a2fd87b..0000000000 --- a/.github/workflows/labeler.yml +++ /dev/null @@ -1,20 +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 && - !startsWith(github.event.pull_request.title, 'chore(deps):') && - !startsWith(github.event.pull_request.title, 'ci(fix):') && - !startsWith(github.event.pull_request.title, 'docs(changelog):') - 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 f03a397019..0000000000 --- a/.github/workflows/pip.yml +++ /dev/null @@ -1,110 +0,0 @@ -name: Pip - -on: - workflow_dispatch: - pull_request: - push: - branches: - - master - - stable - - v* - release: - 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 3.6, since that is often the most - # challenging matrix element. - test-packaging: - name: 🐍 3.6 • 📦 tests • windows-latest - runs-on: windows-latest - - steps: - - uses: actions/checkout@v3 - - - name: Setup 🐍 3.6 - uses: actions/setup-python@v4 - with: - python-version: 3.6 - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt - - - 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@v3 - - - name: Setup 🐍 3.8 - uses: actions/setup-python@v4 - with: - python-version: 3.8 - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt build twine - - - 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@v3 - with: - name: standard - path: dist/pybind11-* - - - name: Save global package - uses: actions/upload-artifact@v3 - 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@v4 - with: - python-version: "3.x" - - # Downloads all to directories matching the artifact names - - uses: actions/download-artifact@v3 - - - name: Publish standard package - uses: pypa/gh-action-pypi-publish@v1.5.1 - with: - password: ${{ secrets.pypi_password }} - packages_dir: standard/ - - - name: Publish global package - uses: pypa/gh-action-pypi-publish@v1.5.1 - with: - password: ${{ secrets.pypi_password_global }} - packages_dir: global/ diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml deleted file mode 100644 index 366284acf4..0000000000 --- a/.github/workflows/upstream.yml +++ /dev/null @@ -1,112 +0,0 @@ - -name: Upstream - -on: - workflow_dispatch: - pull_request: - -concurrency: - group: upstream-${{ github.ref }} - cancel-in-progress: true - -env: - PIP_ONLY_BINARY: numpy - -jobs: - standard: - name: "🐍 3.11 latest internals • ubuntu-latest • x64" - runs-on: ubuntu-latest - if: "contains(github.event.pull_request.labels.*.name, 'python dev')" - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python 3.11 - uses: actions/setup-python@v4 - with: - python-version: "3.11-dev" - - - name: Setup Boost (Linux) - if: runner.os == 'Linux' - run: sudo apt-get install libboost-dev - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt - - - name: Setup annotations on Linux - if: runner.os == 'Linux' - run: python -m pip install pytest-github-actions-annotate-failures - - # First build - C++11 mode and inplace - - name: Configure C++11 - run: > - cmake -S . -B . - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=11 - - - name: Build C++11 - run: cmake --build . -j 2 - - - name: Python tests C++11 - run: cmake --build . --target pytest -j 2 - - - name: C++11 tests - run: cmake --build . --target cpptest -j 2 - - - name: Interface test C++11 - run: cmake --build . --target test_cmake_build - - - name: Clean directory - run: git clean -fdx - - # Second build - C++17 mode and in a build directory - - name: Configure C++17 - run: > - cmake -S . -B build2 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=17 - ${{ matrix.args }} - ${{ matrix.args2 }} - - - name: Build - run: cmake --build build2 -j 2 - - - name: Python tests - run: cmake --build build2 --target pytest - - - name: C++ tests - run: cmake --build build2 --target cpptest - - # Third build - C++17 mode with unstable ABI - - name: Configure (unstable ABI) - run: > - cmake -S . -B build3 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=17 - -DPYBIND11_INTERNALS_VERSION=10000000 - "-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp" - ${{ matrix.args }} - - - name: Build (unstable ABI) - run: cmake --build build3 -j 2 - - - name: Python tests (unstable ABI) - run: cmake --build build3 --target pytest - - - name: Interface test - run: cmake --build build3 --target test_cmake_build - - # This makes sure the setup_helpers module can build packages using - # setuptools - - name: Setuptools helpers test - run: pytest tests/extra_setuptools diff --git a/.github/workflows/windows_clang.yml b/.github/workflows/windows_clang.yml new file mode 100644 index 0000000000..703118eca3 --- /dev/null +++ b/.github/workflows/windows_clang.yml @@ -0,0 +1,77 @@ +name: WindowsClang + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + windows_clang: + + strategy: + matrix: + os: [windows-latest] + python: ['3.10'] + + runs-on: "${{ matrix.os }}" + + name: "🐍 ${{ matrix.python }} • ${{ matrix.os }} • clang-latest" + + steps: + - name: Show env + run: env + + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Clang + uses: egor-tensin/setup-clang@v1 + + - name: Setup Python ${{ matrix.python }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + + - name: Update CMake + uses: jwlawson/actions-setup-cmake@v1.13 + + - name: Install ninja-build tool + uses: seanmiddleditch/gha-setup-ninja@v3 + + - name: Run pip installs + run: | + python -m pip install --upgrade pip + python -m pip install -r tests/requirements.txt + + - name: Show Clang++ version + run: clang++ --version + + - name: Show CMake version + run: cmake --version + + # TODO: WERROR=ON + - name: Configure Clang + run: > + cmake -G Ninja -S . -B . + -DCMAKE_VERBOSE_MAKEFILE=ON + -DPYBIND11_WERROR=OFF + -DPYBIND11_SIMPLE_GIL_MANAGEMENT=OFF + -DDOWNLOAD_CATCH=ON + -DDOWNLOAD_EIGEN=ON + -DCMAKE_CXX_COMPILER=clang++ + -DCMAKE_CXX_STANDARD=17 + + - name: Build + run: cmake --build . -j 2 + + - name: Python tests + run: cmake --build . --target pytest -j 2 + + - name: C++ tests + run: cmake --build . --target cpptest -j 2 + + - name: Interface test + run: cmake --build . --target test_cmake_build -j 2 + + - name: Clean directory + run: git clean -fdx diff --git a/docs/classes.rst b/docs/classes.rst index c0c53135b8..5fbe08870e 100644 --- a/docs/classes.rst +++ b/docs/classes.rst @@ -58,6 +58,15 @@ interactive Python session demonstrating this example is shown below: Static member functions can be bound in the same way using :func:`class_::def_static`. +.. note:: + + Binding C++ types in unnamed namespaces (also known as anonymous namespaces) + works reliably only with GCC and MSVC, but not with CLANG, or if libc++ is used. + See `#4319 `_ for background. + If portability is a concern, it is therefore not recommended to bind C++ + types in unnamed namespaces. It will be safest to manually pick unique + namespace names. + Keyword and default arguments ============================= It is possible to specify keyword and default arguments using the syntax diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 6fd61098c4..31e9287318 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -34,7 +34,7 @@ /// further ABI-incompatible changes may be made before the ABI is officially /// changed to the new version. #ifndef PYBIND11_INTERNALS_VERSION -# define PYBIND11_INTERNALS_VERSION 4 +# define PYBIND11_INTERNALS_VERSION 5 #endif PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) @@ -114,7 +114,7 @@ inline void tls_replace_value(PYBIND11_TLS_KEY_REF key, void *value) { // libstdc++, this doesn't happen: equality and the type_index hash are based on the type name, // which works. If not under a known-good stl, provide our own name-based hash and equality // functions that use the type name. -#if defined(__GLIBCXX__) +#if !defined(_LIBCPP_VERSION) inline bool same_type(const std::type_info &lhs, const std::type_info &rhs) { return lhs == rhs; } using type_hash = std::hash; using type_equal_to = std::equal_to; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 491f215cef..285f43b5b9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -156,6 +156,8 @@ set(PYBIND11_TEST_FILES test_tagbased_polymorphic test_thread test_union + test_unnamed_namespace_a + test_unnamed_namespace_b test_virtual_functions) # Invoking cmake with something like: diff --git a/tests/test_unnamed_namespace_a.cpp b/tests/test_unnamed_namespace_a.cpp new file mode 100644 index 0000000000..e8704edca0 --- /dev/null +++ b/tests/test_unnamed_namespace_a.cpp @@ -0,0 +1,31 @@ +#include "pybind11_tests.h" + +namespace { +struct any_struct {}; +} // namespace + +TEST_SUBMODULE(unnamed_namespace_a, m) { + if (py::detail::get_type_info(typeid(any_struct)) == nullptr) { + py::class_(m, "unnamed_namespace_a_any_struct"); + } else { + m.attr("unnamed_namespace_a_any_struct") = py::none(); + } + m.attr("defined_WIN32_or__WIN32") = +#if defined(WIN32) || defined(_WIN32) + true; +#else + false; +#endif + m.attr("defined___clang__") = +#if defined(__clang__) + true; +#else + false; +#endif + m.attr("defined__LIBCPP_VERSION") = +#if defined(_LIBCPP_VERSION) + true; +#else + false; +#endif +} diff --git a/tests/test_unnamed_namespace_a.py b/tests/test_unnamed_namespace_a.py new file mode 100644 index 0000000000..be4f4bfe9b --- /dev/null +++ b/tests/test_unnamed_namespace_a.py @@ -0,0 +1,30 @@ +import pytest + +from pybind11_tests import unnamed_namespace_a as m +from pybind11_tests import unnamed_namespace_b as mb + +XFAIL_CONDITION = "not m.defined_WIN32_or__WIN32 and (m.defined___clang__ or m.defined__LIBCPP_VERSION)" +XFAIL_REASON = "Known issues: https://github.com/pybind/pybind11/pull/4319" + + +@pytest.mark.xfail(XFAIL_CONDITION, reason=XFAIL_REASON, strict=False) +@pytest.mark.parametrize( + "any_struct", (m.unnamed_namespace_a_any_struct, mb.unnamed_namespace_b_any_struct) +) +def test_have_class_any_struct(any_struct): + assert any_struct is not None + + +def test_have_at_least_one_class_any_struct(): + assert ( + m.unnamed_namespace_a_any_struct is not None + or mb.unnamed_namespace_b_any_struct is not None + ) + + +@pytest.mark.xfail(XFAIL_CONDITION, reason=XFAIL_REASON, strict=True) +def test_have_both_class_any_struct(): + assert ( + m.unnamed_namespace_a_any_struct is not None + and mb.unnamed_namespace_b_any_struct is not None + ) diff --git a/tests/test_unnamed_namespace_b.cpp b/tests/test_unnamed_namespace_b.cpp new file mode 100644 index 0000000000..f97757a7de --- /dev/null +++ b/tests/test_unnamed_namespace_b.cpp @@ -0,0 +1,13 @@ +#include "pybind11_tests.h" + +namespace { +struct any_struct {}; +} // namespace + +TEST_SUBMODULE(unnamed_namespace_b, m) { + if (py::detail::get_type_info(typeid(any_struct)) == nullptr) { + py::class_(m, "unnamed_namespace_b_any_struct"); + } else { + m.attr("unnamed_namespace_b_any_struct") = py::none(); + } +} diff --git a/tests/test_unnamed_namespace_b.py b/tests/test_unnamed_namespace_b.py new file mode 100644 index 0000000000..4bcaa7a6c5 --- /dev/null +++ b/tests/test_unnamed_namespace_b.py @@ -0,0 +1,5 @@ +from pybind11_tests import unnamed_namespace_b as m + + +def test_have_attr_any_struct(): + assert hasattr(m, "unnamed_namespace_b_any_struct")