How do I use Sphinx with Cython?

前端 未结 3 492
自闭症患者
自闭症患者 2020-12-14 08:51

I have recently Cythonized a project of mine by renaming all of the modules (except for the top-level __init__.py) to *.pyx, and by putting e

3条回答
  •  余生分开走
    2020-12-14 08:53

    As Golgauth explains, Sphinx's autodoc module takes the docstrings from the .so, not the .pyx. The simplest way of generating your documentation without having to make any changes to your Sphinx configuration when cythonizing a Python module is to simple build the extension modules in place before you generate the docs:

    python setup.py build_ext --inplace
    

    That way autodoc will find the extension modules alongside the regular Python modules and will be able to generate the documentation as you'd expect.

    To not risk forgetting this step you can edit the Makefile generated by sphinx-quickstart to build the extension modules prior to running sphinx-build:

    html:
      @cd /path/to/setup.py; python setup.py build_ext --inplace
      ...
    

提交回复
热议问题