Skip to content

Commit

Permalink
fix: support NumPy 2 (#918)
Browse files Browse the repository at this point in the history
* fix: support NumPy 2

Signed-off-by: Henry Schreiner <[email protected]>

* style: pre-commit fixes

---------

Signed-off-by: Henry Schreiner <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
henryiii and pre-commit-ci[bot] authored Mar 28, 2024
1 parent 8cae366 commit 23bab22
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
allow-prereleases: true

- name: Install python tools
run: python -m pip install -r dev-requirements.txt pytest-github-actions-annotate-failures
run: python -m pip install -r dev-requirements.txt pytest-github-actions-annotate-failures numpy>=2.0a1

- name: Configure
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DBOOST_HISTOGRAM_ERRORS=ON ${{ matrix.cmake-extras }}
Expand Down
2 changes: 1 addition & 1 deletion extern/pybind11
Submodule pybind11 updated 91 files
+1 −1 .github/CONTRIBUTING.md
+9 −1 .github/dependabot.yml
+111 −74 .github/workflows/ci.yml
+3 −3 .github/workflows/configure.yml
+4 −4 .github/workflows/format.yml
+1 −1 .github/workflows/labeler.yml
+8 −8 .github/workflows/pip.yml
+7 −7 .github/workflows/upstream.yml
+21 −19 .pre-commit-config.yaml
+19 −2 .readthedocs.yml
+57 −6 CMakeLists.txt
+5 −4 README.rst
+1 −1 docs/advanced/embedding.rst
+11 −11 docs/advanced/exceptions.rst
+1 −1 docs/advanced/functions.rst
+29 −0 docs/advanced/misc.rst
+1 −1 docs/benchmark.py
+182 −2 docs/changelog.rst
+12 −4 docs/compiling.rst
+86 −42 docs/release.rst
+28 −0 docs/upgrade.rst
+142 −9 include/pybind11/cast.h
+18 −13 include/pybind11/detail/class.h
+16 −4 include/pybind11/detail/common.h
+1 −1 include/pybind11/detail/init.h
+16 −5 include/pybind11/detail/internals.h
+51 −10 include/pybind11/detail/type_caster_base.h
+3 −2 include/pybind11/eigen/tensor.h
+2 −1 include/pybind11/functional.h
+9 −1 include/pybind11/gil.h
+91 −0 include/pybind11/gil_safe_call_once.h
+157 −22 include/pybind11/numpy.h
+121 −48 include/pybind11/pybind11.h
+22 −5 include/pybind11/pytypes.h
+8 −7 include/pybind11/stl.h
+28 −56 include/pybind11/stl_bind.h
+125 −0 include/pybind11/typing.h
+1 −1 noxfile.py
+1 −1 pybind11/_version.py
+3 −1 pybind11/setup_helpers.py
+8 −11 pyproject.toml
+9 −4 tests/CMakeLists.txt
+1 −0 tests/conftest.py
+2 −2 tests/cross_module_interleaved_error_already_set.cpp
+2 −0 tests/extra_python_package/test_files.py
+4 −4 tests/pybind11_cross_module_tests.cpp
+9 −3 tests/pybind11_tests.cpp
+14 −8 tests/requirements.txt
+7 −0 tests/test_buffers.py
+2 −2 tests/test_builtin_casters.py
+7 −0 tests/test_callbacks.py
+14 −0 tests/test_class.py
+1 −2 tests/test_cmake_build/CMakeLists.txt
+3 −3 tests/test_cmake_build/installed_embed/CMakeLists.txt
+3 −3 tests/test_cmake_build/installed_function/CMakeLists.txt
+3 −3 tests/test_cmake_build/installed_target/CMakeLists.txt
+9 −3 tests/test_cmake_build/subdirectory_embed/CMakeLists.txt
+9 −3 tests/test_cmake_build/subdirectory_function/CMakeLists.txt
+9 −3 tests/test_cmake_build/subdirectory_target/CMakeLists.txt
+4 −0 tests/test_constants_and_functions.cpp
+12 −0 tests/test_custom_type_casters.cpp
+17 −0 tests/test_eigen_matrix.cpp
+8 −1 tests/test_eigen_matrix.py
+6 −3 tests/test_enum.py
+54 −13 tests/test_exceptions.cpp
+1 −1 tests/test_exceptions.h
+21 −2 tests/test_exceptions.py
+2 −2 tests/test_factory_constructors.py
+46 −0 tests/test_kwargs_and_defaults.cpp
+37 −1 tests/test_kwargs_and_defaults.py
+19 −15 tests/test_methods_and_attributes.py
+9 −3 tests/test_numpy_array.py
+29 −4 tests/test_numpy_dtypes.cpp
+11 −3 tests/test_numpy_dtypes.py
+45 −0 tests/test_python_multiple_inheritance.cpp
+35 −0 tests/test_python_multiple_inheritance.py
+26 −3 tests/test_pytypes.cpp
+57 −1 tests/test_pytypes.py
+19 −0 tests/test_sequences_and_iterators.cpp
+13 −0 tests/test_sequences_and_iterators.py
+15 −12 tests/test_smart_ptr.cpp
+12 −12 tests/test_stl.py
+80 −0 tests/test_stl_binders.cpp
+44 −6 tests/test_stl_binders.py
+2 −2 tests/test_type_caster_pyobject_ptr.cpp
+24 −1 tools/FindPythonLibsNew.cmake
+29 −1 tools/make_changelog.py
+30 −16 tools/pybind11Common.cmake
+1 −1 tools/pybind11Config.cmake.in
+77 −22 tools/pybind11NewTools.cmake
+13 −7 tools/pybind11Tools.cmake
15 changes: 12 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

import nox

ALL_PYTHONS = ["3.7", "3.8", "3.9", "3.10", "3.11"]

nox.options.sessions = ["lint", "tests"]


@nox.session(python=ALL_PYTHONS)
@nox.session
def tests(session: nox.Session) -> None:
"""
Run the unit and regular tests.
Expand All @@ -22,6 +20,17 @@ def tests(session: nox.Session) -> None:
session.run("pytest", *session.posargs)


@nox.session
def testsnp2(session: nox.Session) -> None:
"""
Run the unit and regular tests with NumPy 2.
"""

shutil.rmtree("build", ignore_errors=True)
session.install(".[test]", "numpy>=2.0a1")
session.run("pytest", *session.posargs)


@nox.session
def hist(session: nox.Session) -> None:
"""
Expand Down
42 changes: 42 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
from __future__ import annotations

import contextlib
import sys
from pathlib import Path

if sys.version_info < (3, 11):
import tomli as tomllib
else:
import tomllib

import pytest
from packaging.requirements import Requirement

import boost_histogram as bh

DIR = Path(__file__).parent.resolve()
BASE = DIR.parent


@pytest.fixture(params=(False, True), ids=("no_growth", "growth"))
def growth(request):
Expand Down Expand Up @@ -58,3 +71,32 @@ def count_storage(request):
)
def count_single_storage(request):
return request.param


def pytest_report_header() -> str:
if sys.version_info < (3, 8):
import importlib_metadata as metadata
else:
from importlib import metadata

with BASE.joinpath("pyproject.toml").open("rb") as f:
pyproject = tomllib.load(f)
project = pyproject.get("project", {})

pkgs = project.get("dependencies", [])
pkgs += [p for ps in project.get("optional-dependencies", {}).values() for p in ps]
if "name" in project:
pkgs.append(project["name"])
interesting_packages = {Requirement(p).name for p in pkgs}
interesting_packages.add("pip")
interesting_packages.add("numpy")

valid = []
for package in sorted(interesting_packages):
with contextlib.suppress(ModuleNotFoundError):
valid.append(f"{package}=={metadata.version(package)}")
reqs = " ".join(valid)
lines = [
f"installed packages of interest: {reqs}",
]
return "\n".join(lines)

0 comments on commit 23bab22

Please sign in to comment.