Skip to content

Force re-cythonization to fix stale .c files breaking downstream builds - #121

Merged
nsoranzo merged 2 commits into
bxlab:mainfrom
nsoranzo:force_re-cythonize
Aug 27, 2026
Merged

Force re-cythonization to fix stale .c files breaking downstream builds#121
nsoranzo merged 2 commits into
bxlab:mainfrom
nsoranzo:force_re-cythonize

Conversation

@nsoranzo

Copy link
Copy Markdown
Collaborator

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.

nsoranzo and others added 2 commits August 27, 2026 13:25
`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>
@nsoranzo

Copy link
Copy Markdown
Collaborator Author

@mr-c Would this be a problem for Debian?

@mr-c

mr-c commented Aug 27, 2026

Copy link
Copy Markdown
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

https://salsa.debian.org/med-team/python-bx/-/blob/c40c6223f1fd6126e55e261eba892fa533340320/debian/rules#L17

@nsoranzo
nsoranzo merged commit d317df7 into bxlab:main Aug 27, 2026
13 checks passed
@nsoranzo
nsoranzo deleted the force_re-cythonize branch August 27, 2026 13:32
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