Skip to content

Instantly share code, notes, and snippets.

@pieterb
Last active January 16, 2018 09:32
Show Gist options
  • Save pieterb/69c77021e7891bcd7ec0adfc0e388109 to your computer and use it in GitHub Desktop.
Save pieterb/69c77021e7891bcd7ec0adfc0e388109 to your computer and use it in GitHub Desktop.
Sphinx documentation template
# -*- coding: utf-8 -*-
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file. See <http://www.sphinx-doc.org/en/stable/config.html>
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import os
import sphinx_rtd_theme
import urllib.request
#import sys
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('..'))
# -- General configuration ------------------------------------------------
# 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.autosectionlabel',
'sphinx.ext.extlinks',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.viewcode',
]
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# General information about the project.
project = 'Datapunt Authentication & Authorization'
# noinspection PyShadowingBuiltins
copyright = '2017, Evert Lammerts'
author = 'Evert Lammerts'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.1'
# The full version, including alpha/beta/rc tags.
release = version
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
add_module_names = False
default_role = 'py:obj'
# -- Options for extensions -----------------------------------------------
intersphinx_mapping = {
'python': ('https://docs.python.org/3.6/', 'python.inv'),
'sphinx': ('http://www.sphinx-doc.org/en/stable/', 'sphinx.inv'),
'requests': ('http://docs.python-requests.org/en/master/', 'requests.inv'),
'flask': ('https://flask.readthedocs.io/en/latest/', 'flask.inv'),
'jwt': ('https://pyjwt.readthedocs.io/en/latest/', 'jwt.inv'),
}
for inventory in intersphinx_mapping:
if not os.path.exists(intersphinx_mapping[inventory][1]):
urllib.request.urlretrieve(
intersphinx_mapping[inventory][0] + 'objects.inv',
filename=intersphinx_mapping[inventory][1]
)
os.system(
"""
{{
printf "\\x1f\\x8b\\x08\\x00\\x00\\x00\\x00\\x00";
tail -n +5 '{0}';
}} | gunzip --quiet >'{0}.txt'
""".format(intersphinx_mapping[inventory][1])
)
autodoc_default_flags = [
'members',
'private-members',
# 'special-members',
# 'undoc-members',
'show-inheritance'
]
extlinks = {
'epic': ('https://taiga.datapunt.amsterdam.nl/project/kpaska-datapunt-backend/epic/%s', 'epic #'),
'story': ('https://taiga.datapunt.amsterdam.nl/project/kpaska-datapunt-backend/us/%s', 'user story #'),
'task': ('https://taiga.datapunt.amsterdam.nl/project/kpaska-datapunt-backend/task/%s', 'task #'),
}
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
# Sphinx RTD theme:
html_theme_options = {
# 'typekit_id': 'hiw1hhg',
# 'analytics_id': None,
# 'sticky_navigation': False,
# 'logo_only': None,
# 'collapse_navigation': False,
# 'display_version': True,
'display_version': False,
# 'navigation_depth': 4,
# 'prev_next_buttons_location': 'bottom',
# 'canonical_url': None,
}

General Index

Glossary

.. glossary::

    Term1
        Definition 1.


    Term2
        Definition 2.
.. toctree::
    :hidden:
    :glob:

    api
    running
    settings
    manual
    sphinx_101
    todo_list
    glossary
    License <license>
    Index <genindex>
.. _license:
.. include:: ../LICENSE.rst
# .PHONY: help server clean inv
RM = rm -rf
SPHINXOPTS =
SPHINXBUILD = sphinx-build
AUTOBUILD = sphinx-autobuild
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS)
html:
$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS)
server:
@$(AUTOBUILD) "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) \
--watch ../auth
clean:
@$(RM) $(BUILDDIR) *.inv *.inv.txt

Sphinx 101

ReST formatting

For details on basic rST formatting, see the :ref:`sphinx:rst-primer`

  • emphasis, strong empasis, code

  • ``nesting`` *won’t* ``work``

  • roles are formatted as :rolename:`some text`. RST predefines emphasis, strong, literal, subscript, superscript, and title-reference.

    1. Numbered lists look like this
      1. or like this, and can be nested,
      2. as long as there is
    2. an empty line between the lists.
  • Definition lists

    have one line for the term, followed by one or more indented multiline paragraphs.

    Like this.

  • There must be a space between the link text and the url in hyperlinks.

  • Conventions for header markup:

    1. # with overline
    2. * with overline
    3. =
    4. -
    5. ^
    6. "

Roles added by Sphinx

See :doc:`sphinx:markup/inline`.

Inline markup:
:abbr:
:command:
:dfn:
:file:
:kbd:
:mimetype:
:program:
:regexp:
Generic cross-referencing:
:any:
:ref:
:doc:
:envvar:
:term:
:pep:
:rfc:
Python cross-referencing:
:mod:
:func:
:data:
:const:
:class:
:meth:
:attr:
:exc:
:obj:

Directives

Explicit Markup Block
begins with a line starting with .. followed by whitespace and is terminated by the next paragraph at the same level of indentation.
Directives

are Explicit Markup with special semantics. Directives and roles form the extension mechanism of rST. Basically, a directive consists of a name, arguments, options and content:

.. name:: arg1
          arg2
    :option1: arg, arg
    :option2:

    Content

Directives are defined by

See :doc:`sphinx:domains` for ia. the Python and Standard domains with their special directives.

See :doc:`markup/para` for documentation of many handy directives, such as:

.. note::
.. warning::
.. versionadded:: version
.. versionchanged:: version
.. deprecated:: version
.. seealso::
.. hlist::

Google-style docstrings

Example:

Args:
    path (str): The path of the file to wrap
    field_storage (FileStorage): The :class:`FileStorage` instance to wrap
    temporary (bool): Whether or not to delete the file when the File
       instance is destructed

Returns:
    BufferedFileStorage: A buffered writable file descriptor

The following section headers are supported:

  • Args (alias of Parameters)
  • Arguments (alias of Parameters)
  • Attributes
  • Example
  • Examples
  • Keyword Args (alias of Keyword Arguments)
  • Keyword Arguments
  • Methods
  • Note
  • Notes
  • Other Parameters
  • Parameters
  • Return (alias of Returns)
  • Returns
  • Raises
  • References
  • See Also
  • Todo (doesn't work together with sphinx.ext.todo: items won't show up in the .. todolist::)
  • Warning
  • Warnings (alias of Warning)
  • Warns
  • Yield (alias of Yields)
  • Yields

Autodoc

See :doc:`sphinx:ext/autodoc`.

.. automodule:: my_module
    :members:
    :members: member1, member2
    :undoc-members:
    :private-members:
    :special-members:
    :synopsis: Short description
    :platform: Linux, OS-X, other platform
    :deprecated:
    :show-inheritance:
    :inherited-members:

.. autoclass:: MyClass
.. autoexception:: MyException
    :members:
    :members: member1, member2
    :undoc-members:
    :private-members:
    :special-members:
    :show-inheritance:
    :inherited-members:

.. autofunction:: my_function
.. autofunction:: my_function(arg1, arg2)
.. automethod:: my_method
.. automethod:: my_method(arg1, arg2)

.. autodata::
.. autoattribute::
    :annotation: Short description

Three ways of documenting module data members and class attributes:

#: Single- or multi-line comment before the definition,
#: starting with ``#:``.
foo = "bar"  #: Single line comment *after* the definition.
"""Docstring below the definition."""

Intersphinx

Intersphinx is configured with the following mappings:

intersphinx_mapping = {
    'python': ('https://docs.python.org/3.6/', 'python.inv'),
    'sphinx': ('http://www.sphinx-doc.org/en/stable/', 'sphinx.inv'),
    'aiohttp': ('http://aiohttp.readthedocs.io/en/stable/', 'aiohttp.inv'),
    'aiopg': ('https://aiopg.readthedocs.io/en/stable/', 'aiopg.inv'),
    'jwt': ('https://pyjwt.readthedocs.io/en/latest/', 'jwt.inv'),
}

For each of these external packages, a full list of available reference targets can be found in the corresponding :file:`*.inv.txt` files in the :file:`sphinx/` directory (after the first build).

Todo list

.. todolist::
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment