cython-cmake ships two CMake modules (FindCython.cmake, UseCython.cmake)
plus a thin Python wrapper. The CMake modules are the actual product; the Python
package is the delivery mechanism. It is consumed two ways:
- As a build dependency — installed alongside
scikit-build-core, which adds the package'scmake/dir toCMAKE_MODULE_PATHvia thecmake.moduleentry point (seepyproject.toml). User CMake code then doesfind_package(Cython)/include(UseCython). - Vendored —
cython-cmake vendor <dir>copies the.cmakefiles into a user's project so they have no build-time dependency on this package.
src/cython_cmake/cmake/*.cmake— the real logic. Editing these changes behavior for every consumer.FindCython.cmake: locates thecythonexecutable (prefers one next to the found Python), setsCYTHON_EXECUTABLE/CYTHON_VERSIONand aCython::Cythontarget. Supports version ranges on CMake 3.19+.UseCython.cmake: definescython_transpile(), which wires anadd_custom_commandto turn a.pyxinto a.c/.cxxwith aDEPFILE. Language is taken fromLANGUAGE, else deduced from a# distutils: language=...directive, else from which of C/CXX is enabled.
src/cython_cmake/cmake/__init__.py— empty marker; its package dir is the module path exposed to scikit-build-core.vendor.py—Membersflag enum +vendorize(). Copies the.cmakefiles out viaimportlib.resources.__main__.py— argparse CLI (vendorsubcommand).FlagActionmaps repeated--memberschoices onto theMembersflag enum.
The Python side is intentionally tiny; most work and most tests exercise CMake.
Uses uv. Run Python tooling with uv run.
uv run pytest # run tests (needs cmake + ninja on PATH)
uv run pytest tests/test_package.py::test_simple # single test
prek -a --quiet # lint (pre-commit); preferred over pre-commit run -a
nox -s tests # tests in an isolated env
nox -s pylint # pylint (slower; needs install into env)
nox -s build # build sdist + wheelnoxfile.py is a uv run --script self-contained script; nox alone runs lint
- tests across installed Pythons.
tests/test_package.pydrives real builds: it callsscikit_build_core.build.build_wheelon the fixture projects intests/packages/and asserts on generated.c/.cxx/.depfiles and wheel contents. These needcmakeandninjaavailable.- Fixtures use a
# PLACEHOLDERmarker inCMakeLists.txtthat tests string-replace to inject arguments (e.g.OUTPUT,CYTHON_ARGS). tests/test_vendorize.pychecks the CLI copies files byte-for-byte against the sources — if you edit a.cmakefile, no test fixture needs updating, but vendoring tests compare against the live file.pytestruns withfilterwarnings = ["error"]andxfail_strict— warnings fail the suite..fmf/.distro/tests/*.fmfandtest_pure_cmake.share Fedora packaging (tmt/packit) tests, run downstream — not part of local dev.
- Python targets 3.8+; mypy is
strictand ruff selectsALL. Keep thefrom __future__ import annotationsheader and typed signatures. _version.pyis generated by hatch-vcs from git tags; never edit it.