Commit Graph

19 Commits

Author SHA1 Message Date
Malcolm Smith
cd538ed118 Re-enable Android tests in CIBW workflow (#6001)
* Re-enable Android tests in CIBW workflow

* Skip subprocess tests on Android

* Remove Android workarounds no longer necessary with current cibuildwheel version

* Skip more subprocess tests on Android
2026-03-02 15:03:46 -05:00
Xuehai Pan
3ae5a173c5 Add fallback implementation of PyCriticalSection_BeginMutex for Python 3.13t (#5981)
* Add failback implementation of `PyCriticalSection_BeginMutex` for Python 3.13t

* Add comment for Python version

* Use `_PyCriticalSection_BeginSlow`

* Add forward declaration

* Fix forward declaration

* Remove always true condition `defined(PY_VERSION_HEX)`

* Detect musllinux

* Add manylinux test

* Use direct mutex locking for Python 3.13t

`_PyCriticalSection_BeginSlow` is a private CPython function not exported
on Linux. For Python < 3.14.0rc1, use direct `mutex.lock()`/`mutex.unlock()`
instead of critical section APIs.

* Empty commit to trigger CI

* Empty commit to trigger CI

* Empty commit to trigger CI

* Run apt update before apt install

* Remove unnecessary prefix

* Add manylinux test with Python 3.13t

* Simplify pycritical_section with std::unique_lock fallback for Python < 3.14

* Fix potential deadlock in make_iterator_impl for Python 3.13t

Refactor pycritical_section into a unified class with internal version
checks instead of using a type alias fallback. Skip locking in
make_iterator_impl for Python < 3.14.0rc1 to avoid deadlock during
type registration, as pycritical_section cannot release the mutex
during Python callbacks without PyCriticalSection_BeginMutex.

* Add reference for xfail message
2026-02-09 21:14:07 -08:00
Xuehai Pan
e7754de037 Revert internals destruction and add test for internals recreation (#5972)
* Bump internals version

* Prevent internals destruction before all pybind11 types are destroyed

* Use Py_XINCREF and Py_XDECREF

* Hold GIL before decref

* Use weakrefs

* Remove unused code

* Move code location

* Move code location

* Move code location

* Try add tests

* Fix PYTHONPATH

* Fix PYTHONPATH

* Skip tests for subprocess

* Revert to leak internals

* Revert to leak internals

* Revert "Revert to leak internals"

This reverts commit c5ec1cf886.
This reverts commit 72c2e0aa9b.

* Revert internals version bump

* Reapply to leak internals

This reverts commit 8f25a254e8.

* Add re-entrancy detection for internals creation

Prevent re-creation of internals after destruction during interpreter
shutdown. If pybind11 code runs after internals have been destroyed,
fail early with a clear error message instead of silently creating
new empty internals that would cause type lookup failures.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix C++11/C++14 support

* Add lock under multiple interpreters

* Try fix tests

* Try fix tests

* Try fix tests

* Update comments and assertion messages

* Update comments and assertion messages

* Update comments

* Update lock scope

* Use original pointer type for Windows

* Change hard error to warning

* Update lock scope

* Update lock scope to resolve deadlock

* Remove scope release of GIL

* Update comments

* Lock pp on reset

* Mark content created after assignment

* Update comments

* Simplify implementation

* Update lock scope when delete unique_ptr

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 21:54:05 -08:00
Ralf W. Grosse-Kunstleve
b93c0f7ed8 Fix ambiguous str(handle) constructor for object-derived types (#5949)
* Fix ambiguous `str(handle)` constructor for object-derived types

Templatize `str(handle h)` with SFINAE to exclude types derived from
`object`, resolving ambiguity with `str(const object&)` when calling
`py::str()` on types like `kwargs`, `dict`, etc.

The template now only accepts `handle` or `PyObject*`, while all
`object`-derived types use the `str(const object&)` overload.

* fix(tests): CIBW test fixes from b-pass→vectorcall branch

- Install multiple-interpreter test modules into wheel (CMakeLists.txt)
  The mod_per_interpreter_gil, mod_shared_interpreter_gil, and
  mod_per_interpreter_gil_with_singleton modules were being built
  but not installed into the wheel when using scikit-build-core.

- Pin numpy 2.4.0 for Python 3.14 CI tests (requirements.txt)
  NumPy 2.4.0 is the first version with official Python 3.14 wheels.

- Add IOS platform constant to tests/env.py

- Skip subinterpreter tests on iOS (test_multiple_interpreters.py)
  Subinterpreters are not supported in the iOS simulator environment.

- Enable pytest timeout of 120s for CIBW tests (pyproject.toml)
  Provides a safety net to catch hanging tests before CI job timeout.

- Disable pytest-timeout for Pyodide (no signal.setitimer)
  Pyodide runs in WebAssembly without POSIX signals.

- Add -v flag for verbose pytest output in CIBW tests
2025-12-30 04:54:44 -08:00
Yuanyuan Chen
228f563610 Skip cross module exception translation on FreeBSD (#5925)
* Skip cross module exception translation on FreeBSD

Signed-off-by: cyy <cyyever@outlook.com>

* Link to PR number

Signed-off-by: cyy <cyyever@outlook.com>

---------

Signed-off-by: cyy <cyyever@outlook.com>
2025-12-08 16:00:51 -08:00
Ralf W. Grosse-Kunstleve
b30e72c6f6 Replace env.deprecated_call() with pytest.deprecated_call() (#5893)
Since we already require pytest>=6 (see tests/requirements.txt), the
old compatibility function is obsolete and pytest.deprecated_call() can
be used directly.

Extracted from PR #5879

Co-authored-by: Michael Carlstrom <rmc@carlstrom.com>
Co-authored-by: gentlegiantJGC <gentlegiantJGC@users.noreply.github.com>
2025-11-11 19:27:53 -08:00
Joshua Oreman
e6984c805e native_enum: add capsule containing enum information and cleanup logic (#5871)
* native_enum: add capsule containing enum information and cleanup logic

* style: pre-commit fixes

* Updates from code review

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-10-18 11:07:00 -06:00
Ralf W. Grosse-Kunstleve
cd56888c89 Bring CI back to all-working condition (#5822)
* Fix "🐍 3 • windows-latest • mingw64" job (apparently msys2/setup-msys2@v2 cannot be run twice anymore):

https://github.com/pybind/pybind11/actions/runs/17394902023/job/49417376616?pr=5796

```
Run msys2/setup-msys2@v2
  with:
    msystem: mingw64
    install: mingw-w64-x86_64-python-numpy mingw-w64-x86_64-python-scipy mingw-w64-x86_64-eigen3
    path-type: minimal
    update: false
    pacboy: false
    release: true
    location: RUNNER_TEMP
    platform-check-severity: fatal
    cache: true
  env:
    PYTHONDEVMODE: 1
    PIP_BREAK_SYSTEM_PACKAGES: 1
    PIP_ONLY_BINARY: numpy
    FORCE_COLOR: 3
    PYTEST_TIMEOUT: 300
    VERBOSE: 1
    CMAKE_COLOR_DIAGNOSTICS: 1
    MSYSTEM: MINGW64
Error: Trying to install MSYS2 to D:\a\_temp\msys64 but that already exists, cannot continue.
```

* Add `pytest.xfail("[TEST-GIL-SCOPED] macOS free-threading...)`

* Change env.SYS_IS_GIL_ENABLED constant to env.sys_is_gil_enabled function

* Change install_mingw64_only → extra_install

* Also xfail if macOS and PY_GIL_DISABLED, show SOABI

* build-ios: brew upgrade|install cmake

* Revert "build-ios: brew upgrade|install cmake"

This reverts commit bd3900ee79.

See also:

https://github.com/pybind/pybind11/pull/5822#issuecomment-3247827317

* Disable build-ios job in tests-cibw.yml

* Remove macos_brew_install_llvm job because it started failing, to reduce our maintenance overhead:

Failures tracked here: https://github.com/pybind/pybind11/pull/5822#issuecomment-3247998220

* Fix iOS build step for cmake installation

Replaced brew upgrade with brew install for cmake.

* Update cmake installation steps in CI workflow

Uninstall cmake before installing the latest version due to GitHub's local tap changes.

* Update .github/workflows/tests-cibw.yml

---------

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2025-09-03 09:06:41 -07:00
Henry Schreiner
23c59b6e3d ci: add android test (#5714)
* ci: add android test

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Fix Android tests (#23)

* Android tests working

* Clarifications

* ci: only use fork on Android

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* ci: add wheel (missing)

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* ci: no patchelf?

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* ci: forgot pyproject android mention

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Fix GHA configuration

* Update to cibuildwheel 3.1

* Restore installation of "wheel"

* Revert iOS to cibuildwheel 3.0

* Actually revert iOS back to cibuildwheel 3.0

* Restore iOS to cibuildwheel 3.1, and skip Python 3.14 instead

* Update .github/workflows/tests-cibw.yml

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Malcolm Smith <smith@chaquo.com>
2025-08-06 22:32:45 -04:00
Michael Šimáček
708ce4d9c7 Fix GraalPy version parsing on dev builds (#5609)
* Fix GraalPy version parsing on dev builds

* Unskip test on GraalPy
2025-04-09 09:09:15 -07:00
Henry Schreiner
8ef10a0ec9 ci: update to GraalPy 24.2 and mention in README (#5586)
* ci: update to GraalPy 24.2 and mention in README

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* tests: update for GRAALPY 24.2 and better printout

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* tests: use __graalpython__ for version number

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Update README.rst

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-03-31 22:50:55 -04:00
Michael Šimáček
c4a05f9344 Add support for GraalPy (#5380)
* Initial support for GraalPy

* Mark tests that currently fail on GraalPy with xfail

* Add graalpy to CI

* Limit test deps on graalpy to available binary wheels

* Skip cmake test installed_function on GraalPy

CMake won't find libpython on GraalPy, it either fails or silently picks
CPython's libpython.

* Factor out setting function docstrings into a macro

* Try to narrow down skipped tests
2024-10-07 14:12:04 -07:00
Ralf W. Grosse-Kunstleve
f1a2e03d19 feat: remove Python 3.6 support (#5177)
* Change Python version guard: PYTHON < 3.7 IS UNSUPPORTED.

* Replace or remove Python 3.6 jobs.

* Move appveyor to Python 3.8

* Change `[tool.pylint]` `master.py-version` from `3.6` to `3.8`

* Change `[tool.pylint]` `master.py-version` to `3.7`

* Remove `centos:7` job; Change almalinux:8 job to use Python 3.8

* Try 🐍 3.8 • ubuntu-20.04 • x64 without `-DCMAKE_CXX_FLAGS="-D_=1"`

* Update setup.cfg as suggested by @henryiii

* Try running `cmake --build . --target cpptest` on all platforms (`standard` job).

* Disable deadsnakes jobs entirely.

* Apply PR #5179: Add Python 3.10, 3.11, 3.12 to win32 job matrix.

* Add back `-DCMAKE_CXX_FLAGS="-D_=1"` but do not install boost in that case.

* PY_VERSION_HEX < 3.7 cleanup pass: include/pybind11

* WITH_THREAD cleanup pass: include/pybind11

* Undo incorrect change.

* Revert "Disable deadsnakes jobs entirely."

This reverts commit bbcd0087b2.

* WITH_THREAD cleanup pass: tests/

* Change Python version guard in pybind11/__init__.py: pybind11 does not support Python < 3.7.

* Misc cleanup pass

* chore: use future imports

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Update tests/test_numpy_array.py

* Update test_numpy_array.py

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
2024-06-22 00:55:00 -04:00
Sam Gross
baa540ec34 fix: support free-threaded CPython with GIL disabled (#5148)
* Support free-threaded CPython (PEP 703)

Some additional locking is added in the free-threaded build when
`Py_GIL_DISABLED` is defined:

- Most accesses to internals are protected by a single mutex
- The registered_instances uses a striped lock to improve concurrency

Pybind11 modules can indicate support for running with the GIL disabled
by calling `set_gil_not_used()`.

* refactor: use PYBIND11_MODULE (#11)

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Address code review

* Suppress MSVC warning

* Changes from review

* style: pre-commit fixes

* `py::mod_gil_not_used()` suggestion.

* Update include/pybind11/pybind11.h

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
2024-06-18 13:54:38 -07:00
Henry Schreiner
438034c5b8 chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
Ralf W. Grosse-Kunstleve
6493f496e3 Python 2 removal part 1: tests (C++ code is intentionally ~untouched) (#3688)
* `#error BYE_BYE_GOLDEN_SNAKE`

* Removing everything related to 2.7 from ci.yml

* Commenting-out Centos7

* Removing `PYTHON: 27` from .appveyor.yml

* "PY2" removal, mainly from tests. C++ code is not touched.

* Systematic removal of `u` prefix from `u"..."` and `u'...'` literals. Collateral cleanup of a couple minor other things.

* Cleaning up around case-insensitive hits for `[^a-z]py.*2` in tests/.

* Removing obsolete Python 2 mention in compiling.rst

* Proper `#error` for Python 2.

* Using PY_VERSION_HEX to guard `#error "PYTHON 2 IS NO LONGER SUPPORTED.`

* chore: bump pre-commit

* style: run pre-commit for pyupgrade 3+

* tests: use sys.version_info, not PY

* chore: more Python 2 removal

* Uncommenting Centos7 block (PR #3691 showed that it is working again).

* Update pre-commit hooks

* Fix pre-commit hook

* refactor: remove Python 2 from CMake

* refactor: remove Python 2 from setup code

* refactor: simplify, better static typing

* feat: fail with nice messages

* refactor: drop Python 2 C++ code

* docs: cleanup for Python 3

* revert: intree

revert: intree

* docs: minor touchup to py2 statement

Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2022-02-10 18:28:08 -08:00
Eric Cousineau
f676782bec env: Add surrogate for pytest.deprecated_call for ptyest<3.9 (#2923)
env: Add surrogate for pytest.deprecated_call for ptyest<3.9
2021-04-02 14:34:09 -04:00
Henry Schreiner
110e6c12ce ci: reduce flakiness a little (#2418) 2020-08-20 11:58:34 -04:00
Henry Schreiner
4d9024ec71 tests: cleanup and ci hardening (#2397)
* tests: refactor and cleanup

* refactor: more consistent

* tests: vendor six

* tests: more xfails, nicer system

* tests: simplify to info

* tests: suggestions from @YannickJadoul and @bstaletic

* tests: restore some pypy tests that now pass

* tests: rename info to env

* tests: strict False/True

* tests: drop explicit strict=True again

* tests: reduce minimum PyTest to 3.1
2020-08-16 16:02:12 -04:00