Skip to content

Commit c455a65

Browse files
committed
fix: support NumPy 2
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 99e5a28 commit c455a65

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
allow-prereleases: true
8181

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

8585
- name: Configure
8686
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DBOOST_HISTOGRAM_ERRORS=ON ${{ matrix.cmake-extras }}

extern/pybind11

Submodule pybind11 updated 91 files

noxfile.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66

77
import nox
88

9-
ALL_PYTHONS = ["3.7", "3.8", "3.9", "3.10", "3.11"]
109

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

1312

14-
@nox.session(python=ALL_PYTHONS)
13+
@nox.session
1514
def tests(session: nox.Session) -> None:
1615
"""
1716
Run the unit and regular tests.
@@ -22,6 +21,17 @@ def tests(session: nox.Session) -> None:
2221
session.run("pytest", *session.posargs)
2322

2423

24+
@nox.session
25+
def testsnp2(session: nox.Session) -> None:
26+
"""
27+
Run the unit and regular tests with NumPy 2.
28+
"""
29+
30+
shutil.rmtree("build", ignore_errors=True)
31+
session.install(".[test]", "numpy>=2.0a1")
32+
session.run("pytest", *session.posargs)
33+
34+
2535
@nox.session
2636
def hist(session: nox.Session) -> None:
2737
"""

tests/conftest.py

+41
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
from __future__ import annotations
22

3+
import contextlib
4+
import sys
5+
from pathlib import Path
6+
7+
if sys.version_info < (3, 11):
8+
import tomli as tomllib
9+
else:
10+
import tomllib
11+
312
import pytest
13+
from packaging.requirements import Requirement
414

515
import boost_histogram as bh
616

17+
DIR = Path(__file__).parent.resolve()
18+
BASE = DIR.parent
19+
720

821
@pytest.fixture(params=(False, True), ids=("no_growth", "growth"))
922
def growth(request):
@@ -58,3 +71,31 @@ def count_storage(request):
5871
)
5972
def count_single_storage(request):
6073
return request.param
74+
75+
def pytest_report_header() -> str:
76+
if sys.version_info < (3, 8):
77+
import importlib_metadata as metadata
78+
else:
79+
from importlib import metadata
80+
81+
with BASE.joinpath("pyproject.toml").open("rb") as f:
82+
pyproject = tomllib.load(f)
83+
project = pyproject.get("project", {})
84+
85+
pkgs = project.get("dependencies", [])
86+
pkgs += [p for ps in project.get("optional-dependencies", {}).values() for p in ps]
87+
if "name" in project:
88+
pkgs.append(project["name"])
89+
interesting_packages = {Requirement(p).name for p in pkgs}
90+
interesting_packages.add("pip")
91+
interesting_packages.add("numpy")
92+
93+
valid = []
94+
for package in sorted(interesting_packages):
95+
with contextlib.suppress(ModuleNotFoundError):
96+
valid.append(f"{package}=={metadata.version(package)}")
97+
reqs = " ".join(valid)
98+
lines = [
99+
f"installed packages of interest: {reqs}",
100+
]
101+
return "\n".join(lines)

0 commit comments

Comments
 (0)