Skip to content

Modernize build for Python 3.10+/3.12 and NumPy 2#38

Open
homfunc wants to merge 2 commits intogetspams:mainfrom
homfunc:warp/pep517-numpy2-py312
Open

Modernize build for Python 3.10+/3.12 and NumPy 2#38
homfunc wants to merge 2 commits intogetspams:mainfrom
homfunc:warp/pep517-numpy2-py312

Conversation

@homfunc
Copy link

@homfunc homfunc commented Dec 23, 2025

This PR modernizes the Python packaging/build for SPAMS to work out-of-the-box with Python 3.10+ (incl. 3.12) and NumPy 2.

Key changes:

  • Switch to explicit PEP 517 backend (setuptools.build_meta) and prefer NumPy 2 in build isolation
  • Remove distutils/numpy.distutils usage (Python 3.12 compatibility)
  • Vendor SWIG 4.2.0 generated wrappers (removes imp usage; fixes NumPy 2 / NPY_NO_DEPRECATED_API compatibility)
  • Build extension as spams_wrap._spams_wrap to match generated imports
  • Replace pkg_resources version lookup with importlib.metadata
  • Document OpenBLAS/OpenMP warning and add build-time toggle (SPAMS_DISABLE_OPENMP / SPAMS_USE_OPENMP)

Notes:

  • The OpenBLAS OpenMP warning is upstream OpenBLAS behavior when calling a non-OpenMP OpenBLAS from OpenMP regions; README includes mitigations.

Co-Authored-By: Warp agent@warp.dev

homfunc and others added 2 commits December 23, 2025 20:28
- Switch to explicit PEP 517 backend (setuptools.build_meta)

- Drop distutils/numpy.distutils usage

- Make BLAS/LAPACK/OpenMP configuration env-overridable

- Replace pkg_resources with importlib.metadata

Co-Authored-By: Warp <agent@warp.dev>
- Vendor SWIG 4.2.0 generated spams_wrap.{cpp,py}

- Build extension as spams_wrap._spams_wrap to match generated imports

- Document OpenBLAS/OpenMP warning and mitigation

Co-Authored-By: Warp <agent@warp.dev>
@samuelstjean
Copy link
Collaborator

There is alot of things in there, so did you re-generate the swig wrappers or edit the cpp file directly ?

@homfunc
Copy link
Author

homfunc commented Dec 24, 2025

There are a lot of things - apologies for that. I regenerated the swig wrapper and there is another PR in spams-devel: spams-devel update SWIG for Python 3.12+ and NumPy 2.

The driver was mainly to support NumPy 2 but I figured that updating the SWIG sources was the best idea.

@samuelstjean
Copy link
Collaborator

No it is a great idea, it's just I realised I also updated the wrappers on my side to swig 4.3.0 (here it says it's 4.2.0) and also updated the build system to use meson. While the meson part is a big change as it dumps setup.py in the process but makes it far easier to find any blas implementation, just changing the wrapper is easy enough indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants