conf.py 4.34 KB
Newer Older
Rahix's avatar
Rahix committed
1
2
3
4
5
import os
import subprocess
import sys
import time
import sphinx.util.logging
Rahix's avatar
Rahix committed
6
7
from docutils import nodes
from docutils.parsers import rst
Rahix's avatar
Rahix committed
8
9
10
11
12
13

# 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("../pycardium/modules/py"))
ch3's avatar
ch3 committed
14
sys.path.insert(0, os.path.abspath("./"))
Rahix's avatar
Rahix committed
15
16
17
18
19
20
21
22
23
24

logger = sphinx.util.logging.getLogger("card10/conf.py")


# -- Project information -----------------------------------------------------

project = "card10-firmware"
copyright = "2019"

# The full version, including alpha/beta/rc tags
Rahix's avatar
Rahix committed
25
26
27
release = (
    subprocess.check_output(["git", "describe", "--long", "--always"]).decode().strip()
)
Rahix's avatar
Rahix committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
release += "<br />"
release += time.strftime("%F %R")
version = release


# -- 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.viewcode",
    "sphinx.ext.ifconfig",
Rahix's avatar
Rahix committed
42
    "sphinx.ext.todo",
Rahix's avatar
Rahix committed
43
44
]

Rahix's avatar
Rahix committed
45
46
todo_include_todos = True

Rahix's avatar
Rahix committed
47
48
49
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
ch3's avatar
ch3 committed
50
exclude_patterns = ["output", "Thumbs.db", ".DS_Store", "hawkmoth"]
Rahix's avatar
Rahix committed
51

Rahix's avatar
Rahix committed
52
53
54
55
56
57
58
59
60
61
62
63
64
# -- Extensions -------------------------------------------------------------- {{{


class ColorExample(rst.Directive):
    has_content = False
    required_arguments = 1
    optional_arguments = 0
    option_spec = {}

    def run(self):
        color = self.arguments[0]
        html_text = '<div style="width: 30px;height: 30px;background: {};border: black 1px solid;border-radius: 15px;"></div>'
        return [nodes.raw("", html_text.format(color), format="html")]
schneider's avatar
schneider committed
65
66


Rahix's avatar
Rahix committed
67
68
# }}}

Rahix's avatar
Rahix committed
69
70
71
72
73
74
75
76
# -- Options for HTML output ------------------------------------------------- {{{

# The Read the Docs theme is available from
# - https://github.com/snide/sphinx_rtd_theme
# - https://pypi.python.org/pypi/sphinx_rtd_theme
# - python-sphinx-rtd-theme package (on Debian)
try:
    import sphinx_rtd_theme
Rahix's avatar
Rahix committed
77

Rahix's avatar
Rahix committed
78
79
80
81
    html_theme = "sphinx_rtd_theme"
    html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
    pygments_style = "monokai"
except ImportError:
Rahix's avatar
Rahix committed
82
83
84
    logger.warning(
        'The Sphinx "sphinx_rtd_theme" HTML theme was not found. Make sure you have the theme installed to produce pretty HTML output. Falling back to the default theme.'
    )
Rahix's avatar
Rahix committed
85
86
87
88
89
90


# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["static"]
Rahix's avatar
Rahix committed
91
92

# Theme Options
Rahix's avatar
Rahix committed
93
html_theme_options = {"style_external_links": True}
Rahix's avatar
Rahix committed
94
95
96
97
98
99
100
101
102
103
104
105

# Show "Edit on GitLab" links
html_show_sourcelink = False
html_context = {
    "display_gitlab": True,
    "gitlab_host": "git.card10.badge.events.ccc.de",
    "gitlab_user": "card10",
    "gitlab_repo": "firmware",
    "gitlab_version": "master/",
    "conf_py_path": "Documentation/",
    "theme_vcs_pageview_mode": "edit",
}
Rahix's avatar
Rahix committed
106
107
108
# }}}

# -- Options for Auto-Doc ---------------------------------------------------- {{{
Rahix's avatar
Rahix committed
109
autodoc_mock_imports = [
Rahix's avatar
Rahix committed
110
111
    "buttons",
    "interrupt",
112
    "sys_bme680",
113
    "sys_bhi160",
Rahix's avatar
Rahix committed
114
115
    "sys_display",
    "sys_leds",
Rahix's avatar
Rahix committed
116
    "sys_max30001",
Rahix's avatar
Rahix committed
117
    "sys_max86150",
schneider's avatar
schneider committed
118
    "sys_config",
Rahix's avatar
Rahix committed
119
    "ucollections",
Rahix's avatar
Rahix committed
120
    "uerrno",
Rahix's avatar
Rahix committed
121
122
123
    "urandom",
    "utime",
]
Rahix's avatar
Rahix committed
124
125
126
127
128
129
130
131
132

autodoc_member_order = "bysource"
# }}}

# -- Options for Hawkmoth ---------------------------------------------------- {{{
has_hawkmoth = False
try:
    # Attempt importing hawkmoth
    import hawkmoth  # noqa: F401
Rahix's avatar
Rahix committed
133

Rahix's avatar
Rahix committed
134
135
136
    extensions.append("hawkmoth")

    cautodoc_root = os.path.abspath("..")
Rahix's avatar
Rahix committed
137
    cautodoc_clang = "-D__SPHINX_DOC"
Rahix's avatar
Rahix committed
138
    has_hawkmoth = True
ch3's avatar
ch3 committed
139
140
except ImportError as e:
    if e.name == "clang":
Rahix's avatar
Rahix committed
141
142
143
        logger.warning(
            "hawkmoth requires the clang python module.  Documentation for Epicardium API will not be generated."
        )
Rahix's avatar
Rahix committed
144
145
146
147
148
149
# }}}


# -- Sphinx Setup ------------------------------------------------------------
def setup(app):
    app.add_config_value("has_hawkmoth", has_hawkmoth, "")
Rahix's avatar
Rahix committed
150
    app.add_directive("color-example", ColorExample)