Ivan Mishalkin
Ivan Mishalkin

Reputation: 1108

Poetry + Sphinx + Cython

I use poetry to build my cython package. I have NumPy-style docstrings in all functions and classes. What I want to do now is to add Sphinx automatic documentation and publishing it at Read the Docs.

I have read this thread How do I use Sphinx with Cython? and understand that first I have to compile my .pyx files. However when I call poetry build in the end I get only .tar.gz and .whl files and no .pyd or .so ones.

So the question is following: are there any ways to insert callbacks in poetry build process so that when calling with some argument the docs generate automatically?

I will also appreciate links to packages, that use poetry, sphinx and cython together, so that I could learn from them.

Upvotes: 3

Views: 3661

Answers (1)

Ivan Mishalkin
Ivan Mishalkin

Reputation: 1108

I have written a small tutorial with example. You can find it here: https://github.com/iamishalkin/cyrtd

Important points:

Add readthedocs.yml

version: 2

python:
  install:
    - method: pip
      path: .
      extra_requirements:
        - docs
    - method: pip

sphinx:
  configuration: docs/source/conf.py

Add dependencies to pyproject.toml:

[tool.poetry.dependencies]
python = "^3.7"
cython = "^0.29.13"

sphinx = { version = "^2.2", optional = true }
sphinx_rtd_theme = { version = "^0.4.3", optional = true  }

[tool.poetry.extras]
docs = ["sphinx", "sphinx_rtd_theme"]

In the dashbord on ReadTheDocs activate "Install Project" checkbox

There is one inelegant workaround with setup.py. If you know, how to overcome this problem, please, let me know.

Upvotes: 2

Related Questions