Search code examples
pythoncythonpython-sphinxread-the-docs

How to build the cython doc on readthedoc and in local


I am currently working on a cython project.

After following some tutorials, I was able to build in place cython, then use sphinx build with the line

sys.path.insert(0, os.path.abspath('../../')) # path to my_package in my conf.py to make it work.

Unfortunately, I need to delete this line to make it work with readthedocs as suggested here: how to document cython function on readthedocs.

My question is, what is the best practice to build documentation on read the docs and locally with the same code?

read-the-docs creates a venv, pip install requirements, install the cython project and then run sphinx-build.

I would like to avoid doing the same locally because this is time consuming. Is there antoher way? Which one is the best practice?


Solution

  • Always create and use a virtual environment. venv is a tool in Python 3 that creates a virtual environment, so one does not "create a venv". Install packages and your project into the virtual environment.

    # create and change working directory
    mkdir ~/projects/myproject
    cd ~/projects/myproject
    # create a virtual environment for your project
    python3 -m venv env
    # activate the virtual environment
    source env/bin/activate
    # optionally upgrade packaging tools
    pip install --upgrade pip setuptools
    # install your package in editable mode into your virtual environment
    pip install -e .
    # install other packages into your virtual environment
    pip install sphinx another_package one_more_package
    

    Now do all your Sphinx stuff and follow the rest of the instructions at the link you provided in your question.