Skip to content

Cythonizing pyx files

Moses Chan edited this page Apr 30, 2025 · 2 revisions

.pyx files that use numpy must be cythonized with respect to a target version of numpy. In accord with surmise packaging requirements, that same version of numpy must be used to compile the generated C code.

To manage this, we have added a cythonize task to tox, which lists numpy as a dependence with the target version specified as the only acceptable version. That same fixed version is specified as a build system environment requirement in pyproject.toml. Therefore, we strongly suggest that all cythonization of .pyx files be carried out with tox and using a current version of tox.ini.

TODO: How does this work with both the coverage and nocoverage tox tasks?

  • If necessary, merge into your feature branch the current pyproject.toml and tox.ini files from main.
  • Confirm that the two files have matching numpy versions and that this version is acceptable for your work.
  • From a system that has tox installed, run tox -r -e cythonize (optionally without -r if you understand what that means) and confirm creation/update of the associated .c file.
  • Runs tests that use the new .c file to confirm that the generated code is functioning.
  • Commit functioning code and have this aspect of your work carefully reviewed and tested as part of your branch's PR.

Clone this wiki locally