Skip to content

Commit

Permalink
Fixes for numpy-2.0 (#81)
Browse files Browse the repository at this point in the history
This patch fixes a couple of deprecations/dependency changes.

* Resolved issues with numpy-2.0: replaced
numpy.VisibleDeprecationWarning, upgraded pybind11 to 2.13.2
* Fixed issues with clang-format, which destroyed the jupyter notebooks
* Updated CI scripts analog to iminuit
* Dropped support for python-3.8

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
HDembinski and pre-commit-ci[bot] authored Oct 10, 2024
1 parent 87e8add commit 997dfc6
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 123 deletions.
2 changes: 2 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docs/examples/*
extern/*
40 changes: 20 additions & 20 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0 # needed for setuptools_scm
# must come after checkout
- uses: hendrikmuhs/[email protected]
with:
key: ${{ github.job }}-${{ matrix.os }}-${{ matrix.python-version }}
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- run: sudo apt-get install pandoc
- run: python -m pip install --prefer-binary -v .[doc]
- run: python -m ipykernel install --user --name python3
- run: python docs/build.py
- uses: actions/upload-pages-artifact@v1
with:
path: 'docs/_build/html'
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0 # needed for setuptools_scm
# must come after checkout
- uses: hendrikmuhs/[email protected]
with:
key: ${{ github.job }}-${{ matrix.os }}-${{ matrix.python-version }}
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: sudo apt-get install pandoc
- run: python -m pip install --prefer-binary -v .[doc]
- run: python -m ipykernel install --user --name python3
- run: python docs/build.py
- uses: actions/upload-pages-artifact@v1
with:
path: "docs/_build/html"

deploy:
if: github.ref_type == 'tag' || github.ref_name == 'main'
Expand All @@ -49,5 +49,5 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/configure-pages@v2
- uses: actions/deploy-pages@v1
- uses: actions/configure-pages@v2
- uses: actions/deploy-pages@v1
52 changes: 28 additions & 24 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: Test
on:
pull_request:
paths-ignore:
- 'docs/**'
- '*.rst'
- '*.md'
- "docs/**"
- "*.rst"
- "*.md"
workflow_dispatch:

concurrency:
Expand All @@ -22,27 +22,31 @@ jobs:
# version number must be string, otherwise 3.10 becomes 3.1
- os: windows-latest
python-version: "3.11"
- os: macos-13
python-version: "3.8"
installs: "numpy>=2"
- os: macos-14
python-version: "3.9"
installs: "numpy==1.21.0"
- os: ubuntu-latest
python-version: "pypy-3.8"
python-version: "3.13"
installs: "'numpy>=2' scipy matplotlib"
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 3
# must come after checkout
- uses: hendrikmuhs/[email protected]
with:
key: ${{ github.job }}-${{ matrix.os }}-${{ matrix.python-version }}
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: python -m pip install --upgrade pip
- run: python -m pip install --prefer-binary -v .[test]
env:
DEBUG: 1
- uses: ts-graphviz/setup-graphviz@v1
if: ${{ matrix.os != 'macos-13' }}
- run: python -m pytest
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 3
# must come after checkout
- uses: hendrikmuhs/[email protected]
with:
key: ${{ github.job }}-${{ matrix.os }}-${{ matrix.python-version }}
- uses: astral-sh/setup-uv@v3
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- uses: ts-graphviz/setup-graphviz@v1
if: ${{ matrix.os != 'macos-13' }}
- run: uv pip install --system .[test] ${{ matrix.installs }}
env:
DEBUG: 1
- run: python -m pytest
52 changes: 28 additions & 24 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Wheels
on:
push:
tags:
- '**'
- "**"
workflow_dispatch:

concurrency:
Expand All @@ -22,40 +22,33 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-13]
arch: [auto, aarch64, universal2]
py: [cp38, cp39, cp310, cp311, cp312]
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
arch: [auto, aarch64]
py: [cp39, cp310, cp311, cp312, cp313]
exclude:
- os: windows-latest
arch: aarch64
- os: windows-latest
arch: universal2
- os: macos-13
arch: aarch64
- os: ubuntu-latest
arch: universal2
# some unrelated error with installing pillow
- os: ubuntu-latest
py: cp38
env:
CIBW_BUILD: ${{ matrix.py }}-*
CIBW_ARCHS_LINUX: ${{ matrix.arch }}
- os: macos-14
arch: aarch64
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0 # needed by setuptools_scm
fetch-depth: 0 # needed by setuptools_scm

- if: ${{ matrix.arch == 'aarch64' }}
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- uses: pypa/cibuildwheel@v2.16.5
- uses: pypa/cibuildwheel@v2.21
env:
CIBW_BUILD: ${{ matrix.py }}-*
CIBW_ARCHS: ${{ matrix.arch }}

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.py }}-${{ matrix.os }}-${{ matrix.arch }}
path: ./wheelhouse/*.whl

sdist:
Expand All @@ -65,28 +58,39 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0 # needed by setuptools_scm
fetch-depth: 0 # needed by setuptools_scm

- uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: "3.11"

- run: python -m pip install --upgrade pip setuptools wheel
- run: python setup.py sdist
- run: pipx run build --sdist
- run: python -m pip install --upgrade pip setuptools
- run: python -m pip install -v $(echo dist/*)'[test]'
- run: python -m pytest

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz

upload:
if: github.event_name == 'push' && contains(github.event.ref, '/tags/')
needs: [wheels, sdist]
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.event.ref, '/tags/')

environment:
name: pypi
url: https://pypi.org/project/pyhepmc/

permissions:
id-token: write
attestations: write

steps:
- uses: actions/[email protected]
with:
pattern: "*"
name: artifact
path: dist

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ var
build
dist
*.pyc
*.pyd
*.so
*.egg-info
tests/__pycache__
__pycache__
.eggs
.cache
.compiler_support_cache
Expand All @@ -17,6 +18,7 @@ py??
py???
.ci_bak
venv
.venv
.coverage
htmlcov
src/pyhepmc/_version.py
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-case-conflict
- id: check-docstring-first
Expand All @@ -35,20 +35,20 @@ repos:

# Python formatting
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
rev: 24.10.0
hooks:
- id: black

# Ruff linter, replacement for flake8, pydocstyle, isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.4.5'
rev: 'v0.6.9'
hooks:
- id: ruff
args: [--fix, --show-fixes]

# C++ formatting
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.5
rev: v19.1.1
hooks:
- id: clang-format

Expand All @@ -63,7 +63,7 @@ repos:

# Python type checking
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.10.0'
rev: 'v1.11.2'
hooks:
- id: mypy
# additional_dependencies: [numpy]
Expand Down
9 changes: 1 addition & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
import pyhepmc
import os

project = "pyhepmc"
copyright = "2022, Hans Dembinski"
Expand All @@ -30,13 +29,7 @@

html_static_path = ["_static"]

on_rtd = os.environ.get("READTHEDOCS", None) == "True"
if not on_rtd:
# Import and set the theme if we're building docs locally
import sphinx_rtd_theme

html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
html_theme = "sphinx_rtd_theme"

# Autodoc options
autodoc_member_order = "groupwise"
Expand Down
2 changes: 1 addition & 1 deletion extern/pybind11
Submodule pybind11 updated 239 files
16 changes: 7 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ build-backend = "setuptools.build_meta"
[project]
name = "pyhepmc"
description = "Pythonic interface to the HepMC3 C++ library licensed under LGPL-v3."
maintainers = [
{ name = "Hans Dembinski" },
{ email = "[email protected]" },
]
maintainers = [{ name = "Hans Dembinski", email = "[email protected]" }]
readme = "README.rst"
requires-python = ">=3.8"
requires-python = ">=3.9"
license = { text = "BSD 3-Clause License" }
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand All @@ -27,7 +24,7 @@ classifiers = [
"Topic :: Scientific/Engineering",
"Intended Audience :: Developers",
]
dependencies = ["numpy"]
dependencies = ["numpy>=1.21", "packaging"]
dynamic = ["version"]

[project.urls]
Expand All @@ -54,8 +51,9 @@ testpaths = ["tests"]
log_cli_level = "INFO"
xfail_strict = true
filterwarnings = [
"error::PendingDeprecationWarning",
"error::DeprecationWarning",
"error::numpy.VisibleDeprecationWarning",
"error::FutureWarning",
]

[tool.coverage.run]
Expand All @@ -66,10 +64,10 @@ source = ["pyhepmc"]
exclude_lines = ["pragma: no cover"]

[tool.ruff]
src = ["src"]
exclude = ["docs/examples/*"]

[tool.ruff.lint]
select = [
extend-select = [
"E",
"F", # flake8
"D", # pydocstyle
Expand Down
11 changes: 11 additions & 0 deletions src/equal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@
#include <HepMC3/GenParticle.h>
#include <HepMC3/GenRunInfo.h>
#include <HepMC3/GenVertex.h>
#include <type_traits>

namespace HepMC3 {

template <class...>
using void_t = void;

template <class, class = void>
struct has_unequal_op : std::false_type {};

template <class T>
struct has_unequal_op<T, void_t<decltype(std::declval<T>() != std::declval<T>())>>
: std::true_type {};

template <class T, class = std::enable_if_t<!has_unequal_op<T>::value>>
bool operator!=(const T& a, const T& b) {
return !operator==(a, b);
}
Expand Down
2 changes: 1 addition & 1 deletion src/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void register_io(py::module& m) {
.def(py::init<>())
.def(py::init<std::string>())
.def("__str__",
(std::string(std::stringstream::*)() const) & std::stringstream::str);
(std::string(std::stringstream::*)() const)&std::stringstream::str);

py::class_<Reader>(m, "Reader")
// clang-format off
Expand Down
Loading

0 comments on commit 997dfc6

Please sign in to comment.