Marking Cython as a Build Dependency?

cython, distutils, pip, pypi, python

Solution

You can specify Cython as a build dependency using PEP-518 project specification.

In the file `pyproject.toml` (in the same directory as `setup.py`) insert:

[build-system]
requires = ["setuptools", "wheel", "Cython"]

Cython will then be installed before building your package.

Note that (currently) you need to pass `--no-use-pep517` to `pip install` if you are installing your package locally as editable (ie with `--editable` or `-e`) setuptools v64 supports editable installs with pyproject.toml builds

Problem

There is a Python package with a setup.py that reads thusly: ``` from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext setup( name = 'fastahack', ext_modules=[ Extension("fastahack.cfastahack", sources=["fastahack/cfastahack.pyx", "lib/Fasta.cpp", "lib/split.cpp"], libraries=["stdc++"], include_dirs=["lib/"], language="c++"), ], package_data = {'lib': ['*.pyx', "*.c", "*.h", "README.rst"]}, package_dir = {"fastahack": "fastahack"}, cmdclass = {'build_ext': build_ext}, packages = ['fastahack', 'fastahack.tests'], author = "Brent Pedersen", author_email="bpederse@gmail.com", #test_suite='nose.collector' ) ``` This setup.py can't be imported if Cython is not installed. As far as I know, importing setup.py is how tools like pip figure out the dependencies of a package. I want to set up this package so that it could be uploaded to PyPI, with the fact that it depends on Cython noted, so that Cython will be downloaded and installed when you try to "pip install fastahack", or when you try to "pip install" directly from the Git repository. How would I package this module so that it installs correctly from the Internet when Cython is not installed? Always using the latest version of Cython would be a plus.

Original source