Force re-cythonization to fix stale .c files breaking downstream builds - #121
Merged
Conversation
`setup.py` shipped Cython-generated .c/.h files in the sdist, produced at release time with whatever NumPy/Cython happened to be newest. Since the old `Cython.Distutils.build_ext` only re-cythonized when the .pyx was newer than the shipped .c, downstream builders (e.g. bioconda) compiled that stale .c as-is against their own, often older, NumPy headers, causing "implicit declaration" errors for `PyDataType_*` functions, see: bioconda/bioconda-recipes#68558 Replace this with an explicit `cythonize(ext_modules, force=True)` call in `setup.py`, so every real build always regenerates C sources fresh against whatever NumPy/Cython is actually installed. NumPy and Cython are both already hard build-time requirements (`build-system.requires` in `pyproject.toml`), so drop the now-pointless `ImportError` fallback and merge their imports. With sources always regenerated, there's no need to ship the generated .c/.h files in the sdist either: trim `MANIFEST.in` to just the .pyx/.pxd sources plus the one genuinely hand-written .c/.h pair (`lib/bx/align/sitemask/find_cpg.*`), and skip building ext_modules for the "sdist" action so setuptools doesn't pull the freshly cythonized files back in as extension sources. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Collaborator
Author
|
@mr-c Would this be a problem for Debian? |
Contributor
|
@nsoranzo Not a problem for us, we already delete the ".c" files before building execute_after_dh_auto_clean:
# C files are generated by Cython
find -name "*.pyx" | sed 's/pyx$$/c/' | xargs $(RM)
grep -rli "Generated by Cython" lib/ | xargs -r rm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
setup.pyshipped Cython-generated .c/.h files in the sdist, produced at release time with whatever NumPy/Cython happened to be newest. Since the oldCython.Distutils.build_extonly re-cythonized when the .pyx was newer than the shipped .c, downstream builders (e.g. bioconda) compiled that stale .c as-is against their own, often older, NumPy headers, causing "implicit declaration" errors forPyDataType_*functions, see:bioconda/bioconda-recipes#68558
Replace this with an explicit
cythonize(ext_modules, force=True)call insetup.py, so every real build always regenerates C sources fresh against whatever NumPy/Cython is actually installed.NumPy and Cython are both already hard build-time requirements (
build-system.requiresinpyproject.toml), so drop the now-pointlessImportErrorfallback and merge their imports.With sources always regenerated, there's no need to ship the generated .c/.h files in the sdist either: trim
MANIFEST.into just the .pyx/.pxd sources plus the one genuinely hand-written .c/.h pair (lib/bx/align/sitemask/find_cpg.*), and skip building ext_modules for the "sdist" action so setuptools doesn't pull the freshly cythonized files back in as extension sources.