Skip to content

chore(build): pybind11 v3 pin, C++17, MSVC /WX, config and stub cleanups#1145

Draft
henryiii wants to merge 4 commits into
developfrom
chore/build-modernize
Draft

chore(build): pybind11 v3 pin, C++17, MSVC /WX, config and stub cleanups#1145
henryiii wants to merge 4 commits into
developfrom
chore/build-modernize

Conversation

@henryiii

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Part of #1143.

Build/tooling fixes verified against the sources:

  • E1 — pybind11 pin mismatch (CMakeLists.txt): the FetchContent fallback pinned pybind11 v2.13.3 while pyproject.toml requires pybind11>=3, so pure-CMake builds (including the CMake CI job) built a different pybind11 major than shipped wheels. Now pins the v3.0.4 commit (d03662f) and uses FIND_PACKAGE_ARGS 3 as a version floor. Also sets CMAKE_CXX_STANDARD to 17 — pybind11 3 mandates C++17, so wheels already compile as 17; the declared standard is now honest. (No C++ header modernization here; that is deferred.)
  • E2 — MSVC warnings-as-errors (CMakeLists.txt): BOOST_HISTOGRAM_ERRORS=ON passed /WE, which is not an MSVC flag, so it silently did nothing. Fixed to /WX.
  • E3 — stub drift in src/boost_histogram/_core/accumulators.pyi: WeightedSum.fill now declares variance keyword-only (matches py::kw_only() in register_accumulators.cpp); Mean.__call__/WeightedMean.__call__ take a scalar float (the binding is make_mean_call, which binds a double), not ArrayLike; _ipython_key_completions_ moved off _BaseAccumulator onto WeightedSum/Mean/WeightedMean — Sum never had it in C++.
  • E4 — pyproject.toml cleanup: stray leading space in the Chat URL; dead sdist excludes for extern/pybind11 (not a submodule); dead gp311_242-* cibuildwheel test-skip identifiers; cp310-musllinux_* subsumed by cp31*-musllinux_*; "Hypothosis" typo.
  • E5 — CI/nox: examples.yml push trigger now includes develop (the active default branch); removed --ignore=docs/.build from the nox docs session (nonexistent dir — outdir is docs/_build, which sphinx-autobuild auto-ignores).

Verification: uv sync --reinstall-package boost-histogram rebuilds cleanly with C++17 + pybind11 3; pure-CMake configure fetches pybind11 v3.0.4 at the pinned commit; full test suite passes (997 passed, 1 xfail); mypy strict clean; prek -a clean.

🤖 Generated with Claude Code

henryiii added 4 commits June 11, 2026 00:58
…+17, fix MSVC /WX

The FetchContent fallback pinned pybind11 v2.13.3 while pyproject.toml
requires pybind11>=3, so pure-CMake builds used a different pybind11
major than shipped wheels. Pin the v3.0.4 commit and add a version floor
to FIND_PACKAGE_ARGS. pybind11 3 mandates C++17, so declare the standard
the wheels already compile with.

Also fix BOOST_HISTOGRAM_ERRORS on MSVC: /WE is not a valid flag; the
warnings-as-errors flag is /WX.

Part of #1143

Assisted-by: ClaudeCode:claude-fable-5
- WeightedSum.fill takes variance as keyword-only (py::kw_only in the
  binding), like Mean/WeightedMean already do in the stubs
- Mean.__call__/WeightedMean.__call__ take a scalar value (the binding
  is make_mean_call, which binds a double), not ArrayLike
- _ipython_key_completions_ is only registered on WeightedSum, Mean,
  and WeightedMean, not on Sum, so move it off the shared base class

Part of #1143

Assisted-by: ClaudeCode:claude-fable-5
- Remove a stray leading space in the Chat URL
- Drop sdist excludes for extern/pybind11, which is not a submodule
- Drop gp311_242-* cibuildwheel test-skips (no such identifiers exist)
- Drop cp310-musllinux_*, subsumed by cp31*-musllinux_*
- Fix 'Hypothosis' typo

Part of #1143

Assisted-by: ClaudeCode:claude-fable-5
The examples workflow only triggered on pushes to master, but the
active default branch is develop. Also remove --ignore=docs/.build
from the docs session: the directory does not exist (the outdir is
docs/_build) and sphinx-autobuild ignores its outdir automatically.

Part of #1143

Assisted-by: ClaudeCode:claude-fable-5
@github-actions github-actions Bot added the needs changelog Might need a changelog entry label Jun 11, 2026
henryiii added a commit to scikit-hep/hist that referenced this pull request Jun 11, 2026
#697)

🤖 _AI text below_ 🤖

## Problem

boost-histogram's downstream `hist` CI job ([example:
scikit-hep/boost-histogram#1145](scikit-hep/boost-histogram#1145))
was failing on its Python 3.10 leg with:

```
src/hist/chunked.py:60: error: Missing type arguments for generic type "ndarray"  [type-arg]
... (9 total)
```

`np.ndarray` is generic. NumPy **≥2.3** added [PEP
696](https://peps.python.org/pep-0696/) **defaults** to `ndarray`'s type
parameters, so its stubs silently accept a bare `np.ndarray`. NumPy
**≤2.2** has no defaults, so strict mypy (`disallow_any_generics`) flags
it.

The downstream job type-checks on Python 3.10, where the newest
installable NumPy is 2.2.x — hence the failure. It passed on the 3.14
leg, and never showed up here, because hist's only mypy run is the
pre-commit hook pinned to `numpy~=2.4.0` (which has the defaults).

The `accumulators.pyi` changes in that PR are unrelated — they don't
affect hist.

## Fix

- `src/hist/chunked.py`: replace the nine bare `np.ndarray` annotations
with `np.typing.NDArray[Any]` (the convention already used in
`plot.py`). Correct under every supported NumPy version, including the
`numpy>=1.21.3` floor. The runtime `isinstance(value, np.ndarray)` check
is untouched.

## Preventing regressions

There is no single NumPy pin that both lacks the defaults *and* ships
Python 3.14 wheels, so the pre-commit hook can't catch this. Instead:

- `noxfile.py`: a new `nox -s mypy` session **pinned to Python 3.10**,
where NumPy permanently resolves to <2.3 (no defaults), mirroring the
downstream environment.
- `.github/workflows/ci.yml`: a `Type check` job running it, added to
the `pass` gate.

Verified the new session **catches** the bug (9 errors with the fix
reverted) and **passes** with it. Used normal resolution rather than
`--resolution=lowest-direct` to avoid unrelated noise from
boost-histogram 1.6.1 (no `MultiCell`, non-generic `Histogram`).

`prek -a` and the chunked tests (61 passed) are green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs changelog Might need a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant