Skip to content

ci: reduced runs on draft PRs #5707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
299 changes: 167 additions & 132 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .github/workflows/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ name: Config
on:
workflow_dispatch:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
push:
branches:
- master
Expand All @@ -16,6 +21,7 @@ jobs:
# This tests various versions of CMake in various combinations, to make sure
# the configure step passes.
cmake:
if: github.event.pull_request.draft == false
strategy:
fail-fast: false
matrix:
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/reusable-standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Reusable Standard Test

on:
workflow_call:
inputs:
python-version:
required: true
type: string
cmake-args:
required: false
type: string
default: ''
runs-on:
required: true
type: string

jobs:
standard:
name: 🧪
runs-on: ${{ inputs.runs-on }}

steps:
- uses: actions/checkout@v4

- name: Setup Python ${{ inputs.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
allow-prereleases: true

- name: Setup Boost (Linux)
if: runner.os == 'Linux'
run: sudo apt-get install libboost-dev

- name: Setup Boost (macOS)
if: runner.os == 'macOS'
run: brew install boost

- name: Install uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true

- name: Prepare env
run: uv pip install --python=python --system -r tests/requirements.txt

- name: Setup annotations on Linux
if: runner.os == 'Linux'
run: uv pip install --python=python --system pytest-github-actions-annotate-failures

# TODO Resolve Windows Ninja shared object issue on Python 3.8+
- name: Use Ninja except on Windows
if: runner.os != 'Windows'
run: echo "CMAKE_GENERATOR=Ninja" >> "$GITHUB_ENV"

- name: Configure
run: >
cmake -S. -Bbuild -Werror=dev
-DPYBIND11_WERROR=ON
-DPYBIND11_PYTEST_ARGS=-v
-DDOWNLOAD_CATCH=ON
-DDOWNLOAD_EIGEN=ON
${{ inputs.cmake-args }}

- name: Build
run: cmake --build build

- 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

- name: Setuptools helpers test
run: |
uv pip install --python=python --system setuptools
pytest tests/extra_setuptools
File renamed without changes.
4 changes: 2 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"DOWNLOAD_CATCH": true,
"DOWNLOAD_EIGEN": true,
"PYBIND11_FINDPYTHON": "NEW",
"PYBIND11_WERROR": true

"PYBIND11_WERROR": true,
"CMAKE_COLOR_DIAGNOSTICS": true
}
},
{
Expand Down
18 changes: 18 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../tools")
option(PYBIND11_WERROR "Report all warnings as errors" OFF)
option(DOWNLOAD_EIGEN "Download EIGEN" OFF)
option(PYBIND11_CUDA_TESTS "Enable building CUDA tests" OFF)
option(PYBIND11_TEST_SMART_HOLDER "Change the default to smart holder" OFF)
set(PYBIND11_TEST_OVERRIDE
""
CACHE STRING "Tests from ;-separated list of *.cpp files will be built instead of all tests")
Expand Down Expand Up @@ -499,6 +500,13 @@ foreach(target ${test_targets})
target_compile_definitions(${target} PRIVATE -DPYBIND11_TEST_BOOST)
endif()

if(PYBIND11_TEST_SMART_HOLDER)
target_compile_definitions(
${target}
PUBLIC -DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE
)
endif()

target_link_libraries(${target} PRIVATE ${STD_FS_LIB})

# Always write the output file directly into the 'tests' directory (even on MSVC)
Expand Down Expand Up @@ -572,6 +580,16 @@ if(NOT PYBIND11_CUDA_TESTS)
"$<1:${CMAKE_CURRENT_BINARY_DIR}>")
set_target_properties(mod_shared_interpreter_gil PROPERTIES LIBRARY_OUTPUT_DIRECTORY
"$<1:${CMAKE_CURRENT_BINARY_DIR}>")
if(PYBIND11_TEST_SMART_HOLDER)
target_compile_definitions(
mod_per_interpreter_gil
PUBLIC -DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE
)
target_compile_definitions(
mod_shared_interpreter_gil
PUBLIC -DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE
)
endif()
add_dependencies(pytest mod_per_interpreter_gil mod_shared_interpreter_gil)
endif()

Expand Down
12 changes: 11 additions & 1 deletion tests/pure_cpp/smart_holder_poc_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "smart_holder_poc.h"

#include <cstddef>
#include <functional>
#include <memory>
#include <type_traits>
Expand Down Expand Up @@ -380,8 +381,17 @@ TEST_CASE("error_cannot_disown_nullptr", "[E]") {

TEST_CASE("indestructible_int-from_raw_ptr_unowned+as_raw_ptr_unowned", "[S]") {
using zombie = helpers::indestructible_int;

// This is from C++17
#ifdef __cpp_lib_byte
using raw_byte = std::byte;
#else
using raw_byte = char;
#endif

// Using placement new instead of plain new, to not trigger leak sanitizer errors.
static std::aligned_storage<sizeof(zombie), alignof(zombie)>::type memory_block[1];
alignas(zombie) raw_byte memory_block[sizeof(zombie)];

auto *value = new (memory_block) zombie(19);
auto hld = smart_holder::from_raw_ptr_unowned(value);
REQUIRE(hld.as_raw_ptr_unowned<zombie>()->valu == 19);
Expand Down
5 changes: 5 additions & 0 deletions tests/test_cmake_build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ function(pybind11_add_build_test name)
add_dependencies(test_cmake_build test_build_${name})
endfunction()

if(PYBIND11_TEST_SMART_HOLDER)
add_compile_definitions(
-DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE)
endif()

possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID)

pybind11_add_build_test(subdirectory_function)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_embed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ endif()

find_package(Threads REQUIRED)

if(PYBIND11_TEST_SMART_HOLDER)
add_compile_definitions(
-DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE)
endif()

add_executable(test_embed catch.cpp test_interpreter.cpp test_subinterpreter.cpp)
pybind11_enable_warnings(test_embed)

Expand Down
6 changes: 4 additions & 2 deletions tests/test_pytypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,8 @@ TEST_SUBMODULE(pytypes, m) {

m.def("transform_tuple_plus_one", [](py::tuple &tpl) {
py::list ret{};
for (auto it : tpl | std::views::transform([](auto &o) { return py::cast<int>(o) + 1; })) {
for (auto &&it :
tpl | std::views::transform([](const auto &o) { return py::cast<int>(o) + 1; })) {
ret.append(py::int_(it));
}
return ret;
Expand All @@ -1025,7 +1026,8 @@ TEST_SUBMODULE(pytypes, m) {

m.def("transform_list_plus_one", [](py::list &lst) {
py::list ret{};
for (auto it : lst | std::views::transform([](auto &o) { return py::cast<int>(o) + 1; })) {
for (auto &&it :
lst | std::views::transform([](const auto &o) { return py::cast<int>(o) + 1; })) {
ret.append(py::int_(it));
}
return ret;
Expand Down
Loading