Sphinx Quickstart

We begin by creating a Sphinx documentation root directory:

youruser@yourpc:~yourWorkspacePath/simpleble-master$ mkdir docs
youruser@yourpc:~yourWorkspacePath/simpleble-master$ cd docs

Next we can call sphinx-quickstart to initialise our Sphinx project:

youruser@yourpc:~yourWorkspacePath/simpleble-master/docs$ sphinx-quickstart

We will be presented with a series of questions, the answer to which can depend from project to project, but a generally safe answer set is presented below:

Welcome to the Sphinx 1.7.1 quickstart utility.

Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).

Selected root path: .

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 [_]: (ENTER)

The project name will occur in several places in the built documentation.
> Project name: simpleble
> Author name(s): Lyudmil Vladimirov
> Project release []: 0.0.1

If the documents are to be written in a language other than English,
you can select a language here by its language code. Sphinx will then
translate text that it generates into that language.

For a list of supported codes, see
> Project language [en]: (ENTER)

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]: (ENTER)

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]: (ENTER)

Sphinx can also add configuration for epub output:
> Do you want to use the epub builder (y/n) [n]: (ENTER)
Indicate which of the following Sphinx extensions should be enabled:
> autodoc: automatically insert docstrings from modules (y/n) [n]: y
> doctest: automatically test code snippets in doctest blocks (y/n) [n]: (ENTER)
> intersphinx: link between Sphinx documentation of different projects (y/n) [n]: (ENTER)
> todo: write "todo" entries that can be shown or hidden on build (y/n) [n]:
> coverage: checks for documentation coverage (y/n) [n]: (ENTER)
> imgmath: include math, rendered as PNG or SVG images (y/n) [n]: (ENTER)
> mathjax: include math, rendered in the browser by MathJax (y/n) [n]: (ENTER)
> ifconfig: conditional inclusion of content based on config values (y/n) [n]: (ENTER)
> viewcode: include links to the source code of documented Python objects (y/n) [n]: y
> githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]: (ENTER)

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
> Create Makefile? (y/n) [y]: (ENTER)
> Create Windows command file? (y/n) [y]: (ENTER)

Creating file ./source/conf.py.
Creating file ./source/index.rst.
Creating file ./Makefile.
Creating file ./make.bat.

Finished: An initial directory structure has been created.

Now we can see that some foldes and files have been autogenerated for us:

youruser@yourpc:~yourWorkspacePath/simpleble-master/docs$ ls
build  make.bat  Makefile  source
youruser@yourpc:~yourWorkspacePath/simpleble-master/docs$ cd source
youruser@yourpc:~yourWorkspacePath/simpleble-master/docs$ ls
conf.py  index.rst  _static  _templates

Let’s see how each of these files matter:

  • source: This is where all our .rst files will reside.
  • source/conf.py: This is the file where all Sphinx configuration settings (including the settings we specified during the sphinx-quickstart setup) are specified. When any make <builder> or sphinx-build <builder> command is called, Sphinx runs this file to extract the desired configuration.
  • source/index.rst: This is the file which tells Sphinx how to render our index.html page. In general, each source/*.rst file is converted to a corresponding build/html/*.html page when make html is called.
  • build : This is the directory where the output of any builder is stored when a make <builder> or sphinx-build <builder> command is called. For the purposes of this tutorial, we are particularly interested in building html documentation and thus our build outputs will be stored under build/html. Note that build/html does not exist just yet, but will be autogenerated when we call make html later.