Fix Python 3.12 and NumPy 2.x compatibility issues #47
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes multiple compatibility issues preventing zigzag from building on Python 3.12 with NumPy 2.x and Cython 3.x. These changes enable zigzag to work with modern Python environments.
Problem
The current version fails to install on Python 3.12+ with errors:
error: invalid-pyproject-build-system-requires - invalid requirement: 'Cython>=^0.29'ModuleNotFoundError: No module named 'distutils'(removed in Python 3.12)Invalid typeerrors withnp.int_(removed in NumPy 2.x)Invalid typeerrors withint_t(deprecated in Cython 3.x)get_outputs()fails withoutbuild_pycommandChanges
1. Fix pyproject.toml (commit e0c62a0)
File:
pyproject.tomlBefore:
After:
Reason: The
^operator is Poetry-specific syntax and not valid in PEP 508/PEP 440 dependency specifications used bybuild-system.requires.2. Replace distutils with setuptools (commit 013d2cc)
File:
build.pyChanges:
from distutils.command.build_ext import build_ext→from setuptools.command.build_ext import build_extfrom distutils.core import Distribution, Extension→from setuptools.dist import Distribution+from setuptools import ExtensionReason: Python 3.12 removed the
distutilsmodule. Usesetuptoolsas the modern replacement.3. Add setuptools to build requirements (commit 922933f)
File:
pyproject.tomlBefore:
After:
Reason: Since
build.pynow imports from setuptools, it must be inbuild-system.requires.4. Fix NumPy 2.x type compatibility (commit 98167d0)
File:
zigzag/core.pyxChanges:
dtype=np.int_→dtype=np.intpdtype=np.int_→dtype=np.intpReason: NumPy 2.0 removed
np.int_type alias. Usenp.intp(platform-specific signed integer type used for indexing).5. Fix Cython 3.x type compatibility (commit 7a2df2e)
File:
zigzag/core.pyxChanges:
cimport numpy as cnpint_twithcnp.intp_tReason: The
int_ttype is deprecated in modern Cython with NumPy 2.x. Usecnp.intp_tfor platform-specific integer types.6. Add error handling to build script (commit 1b7bcf3)
File:
build.pyChanges: Added try/except block with glob fallback for
cmd.get_outputs():Reason:
get_outputs()can fail whenbuild_pycommand doesn't exist in the minimal Distribution setup. Fallback uses glob to find built.so/.pydfiles.Testing
Tested successfully on:
Build output:
Import test:
Impact
This fixes installation for:
smartmoneyconceptsthat require zigzagBackward Compatibility
All changes maintain backward compatibility:
Cython>=0.29still accepts older versionssetuptoolsis widely availablenp.intpworks on all NumPy versionscnp.intp_tis the recommended modern Cython typeReferences