Non-Karabo-Related Documentation¶
For non-Karabo projects you need to create this yourself through a relatively simple procedure. You can use the sphinx-quickstart utility to generate an initial conf.py (the file that configures documentation processing), folder structure and index.rst (your top-level index).
Starting A Sphinx Project¶
From within the directory you would like to create documentation in run ./sphinx-quickstart. You should then see the following sequence of queries, where suggested answers have already been chosen.
Welcome to the Sphinx 1.2.3 quickstart utility.
Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).
Enter the root path for documentation.
> Root path for the documentation [.]:
You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.
> Separate source and build directories (y/n) [n]: y
Inside the root directory, two more directories will be created; "_templates"
for custom HTML templates and "_static" for custom stylesheets and other static
files. You can enter another prefix (such as ".") to replace the underscore.
> Name prefix for templates and static dir [_]:
The project name will occur in several places in the built documentation.
> Project name: XFEL ReadTheDocs
> Author name(s): S. Hauf
Sphinx has the notion of a "version" and a "release" for the
software. Each version can have multiple releases. For example, for
Python the version is something like 2.5 or 3.0, while the release is
something like 2.5.1 or 3.0a1. If you don't need this dual structure,
just set both to the same value.
> Project version: 1.0
> Project release [1.0]:
The file name suffix for source files. Commonly, this is either ".txt"
or ".rst". Only files with this suffix are considered documents.
> Source file suffix [.rst]:
One document is special in that it is considered the top node of the
"contents tree", that is, it is the root of the hierarchical structure
of the documents. Normally, this is "index", but if your "index"
document is a custom template, you can also set this to another filename.
> Name of your master document (without suffix) [index]:
Sphinx can also add configuration for epub output:
> Do you want to use the epub builder (y/n) [n]: n
Please indicate if you want to use one of the following Sphinx extensions:
> autodoc: automatically insert docstrings from modules (y/n) [n]: y
> doctest: automatically test code snippets in doctest blocks (y/n) [n]: n
> intersphinx: link between Sphinx documentation of different projects (y/n) [n]: y
> todo: write "todo" entries that can be shown or hidden on build (y/n) [n]: y
> coverage: checks for documentation coverage (y/n) [n]:
> pngmath: include math, rendered as PNG images (y/n) [n]: y
> mathjax: include math, rendered in the browser by MathJax (y/n) [n]: y
Note: pngmath and mathjax cannot be enabled at the same time.
pngmath has been deselected.
> ifconfig: conditional inclusion of content based on config values (y/n) [n]: y
> viewcode: include links to the source code of documented Python objects (y/n) [n]: y
A Makefile and a Windows command file can be generated for you so that you
only have to run e.g. `make html' instead of invoking sphinx-build
directly.
> Create Makefile? (y/n) [y]: y
> Create Windows command file? (y/n) [y]: n
Creating file ./source/conf.py.
Creating file ./source/index.rst.
Creating file ./Makefile.
Finished: An initial directory structure has been created.
You should now populate your master file ./source/index.rst and create other documentation
source files. Use the Makefile to build the docs, like so:
make builder
where "builder" is one of the supported builders, e.g. html, latex or linkcheck.
Including InterSphinx Information for all Local Projects¶
In the next step you should adapt your conf.py which you can find in the directory you started sphinx-quickstart from. Specifically, you should include the following code snippet at the end:
#we add a custum function to work with intersphinx
import slumber
import json
# the RTDHOST should be set to localhost if you only compile on RTD
# otherwise it needs to be set to the server hosting the internal RTD
RTDHOST = 'https://in.xfel.eu/readthedocs
api = slumber.API(base_url='{}/api/v1/'.format(RTDHOST))
projects = api.project.get()['objects']
isphinx = {'python': ('http://python.readthedocs.io/en/latest/', None),
'numpy': ('http://numpy.readthedocs.io/en/latest/', None),
'scipy': ('http://scipy.readthedocs.io/en/latest/', None)}
for proj in projects:
isphinx[proj['slug'].replace('-', '')] = \
('{}/docs/{}/en/latest'.format(RTDHOST, proj['slug']), None)
intersphinx_mapping = isphinx
Check Referencing across Projects on how to link across projects hosted on RTD.
Adding GraphViz Extension for Inline Graphs¶
To enable graphs as shown in Graphs make sure you have the corresponding extension enabled in your conf.py:
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.mathjax',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.graphviz',
]
Enabling Conditional Rendering of Developer Info¶
To enable conditional rendering of developer information, add the following line to your conf.py and make sure the sphinx.ext.ifconfig extension is in your extension list.
def setup(app):
app.add_config_value('includeDevInfo', 'false', 'env')
Warning
Do not enable usage of custom themes in your conf.py. The theme files are not available on the RTD server and thus building you project may either fail or in the very least lead to aweful rendering in the browser.