user595985
user595985

Reputation: 1583

Specifying a relative path in Sphinx conf.py for collaborative documentation

I am working on a python project with a few colleagues, we have a central repository(Hg) where we can push and pull from and local repos where we do most of the development and documentation. Sphinx has been great for generating the documentation. The structure is similar to this

projects-top/
      +python_application_folder
            +my_application_folder
            +docs_folder
                 +docs_build_folder
                 +docs_dist_folder
                  conf.py
                  index.rst

However currently when we pull and do work, to update the documentation we currently change the conf.py file to say where the code is, obviosuly the path changes from user to user, on user a it may be c:\usera\projects-top\python_application_folder\my_application_folder, and for user b it may be d:\userb\projects-top\python_application_folder\my_application_folder how can i specify a relative path in the conf.py file that will work for all users, I just want it to be like look in the the directory one level up and document the code in ..\my_application_folder

Upvotes: 0

Views: 6678

Answers (2)

mzjn
mzjn

Reputation: 51082

Add the following to conf.py:

import os, sys

sys.path.append(os.path.abspath('../my_application_folder'))

This will append the absolute path of my_application_folder to the list of module search paths.

In the documentation for the extensions configuration variable it is emphasized that absolute paths should be used when extending sys.path. I think the main reason is that relative paths won't work if you run sphinx-build from another directory than the configuration directory.

Upvotes: 4

andref
andref

Reputation: 750

You could use the relative path directly in the directives in your rst document:

.. literalinclude:: ../my_application_folder/setup.py
    :language: python

Upvotes: 2

Related Questions