2 # Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in
13 # the documentation and/or other materials provided with the
15 # * Neither the name of Intel Corporation nor the names of its
16 # contributors may be used to endorse or promote products derived
17 # from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 from docutils import nodes
33 from distutils.version import LooseVersion
34 from sphinx import __version__ as sphinx_version
35 from sphinx.highlighting import PygmentsBridge
36 from pygments.formatters.latex import LatexFormatter
38 project = 'Data Plane Development Kit'
40 if LooseVersion(sphinx_version) >= LooseVersion('1.3.1'):
41 html_theme = "sphinx_rtd_theme"
42 html_logo = '../logo/DPDK_logo_vertical_rev_small.png'
43 latex_logo = '../logo/DPDK_logo_horizontal_tag.png'
44 html_add_permalinks = ""
45 html_show_copyright = False
46 highlight_language = 'none'
48 version = subprocess.check_output(['make', '-sRrC', '../../', 'showversion']).decode('utf-8').rstrip()
53 # Figures, tables and code-blocks automatically numbered if they have caption
64 # Latex directives to be included directly in the latex/pdf docs.
66 \usepackage[utf8]{inputenc}
67 \usepackage[T1]{fontenc}
69 \renewcommand{\familydefault}{\sfdefault}
70 \RecustomVerbatimEnvironment{Verbatim}{Verbatim}{xleftmargin=5mm}
73 # Configuration for the latex/pdf docs.
75 'papersize': 'a4paper',
78 'classoptions': ',openany,oneside',
79 'babel': '\\usepackage[english]{babel}',
80 # customize Latex formatting
81 'preamble': latex_preamble
84 # Override the default Latex formatter in order to modify the
85 # code/verbatim blocks.
86 class CustomLatexFormatter(LatexFormatter):
87 def __init__(self, **options):
88 super(CustomLatexFormatter, self).__init__(**options)
89 # Use the second smallest font size for code/verbatim blocks.
90 self.verboptions = r'formatcom=\footnotesize'
92 # Replace the default latex formatter.
93 PygmentsBridge.latex_formatter = CustomLatexFormatter
95 ######## :numref: fallback ########
96 # The following hook functions add some simple handling for the :numref:
97 # directive for Sphinx versions prior to 1.3.1. The functions replace the
98 # :numref: reference with a link to the target (for all Sphinx doc types).
99 # It doesn't try to label figures/tables.
101 def numref_role(reftype, rawtext, text, lineno, inliner):
103 Add a Sphinx role to handle numref references. Note, we can't convert
104 the link here because the doctree isn't build and the target information
107 # Add an identifier to distinguish numref from other references.
108 newnode = nodes.reference('',
110 refuri='_local_numref_#%s' % text,
114 def process_numref(app, doctree, from_docname):
116 Process the numref nodes once the doctree has been built and prior to
117 writing the files. The processing involves replacing the numref with a
118 link plus text to indicate if it is a Figure or Table link.
121 # Iterate over the reference nodes in the doctree.
122 for node in doctree.traverse(nodes.reference):
123 target = node.get('refuri', '')
125 # Look for numref nodes.
126 if target.startswith('_local_numref_#'):
127 target = target.replace('_local_numref_#', '')
129 # Get the target label and link information from the Sphinx env.
130 data = app.builder.env.domains['std'].data
131 docname, label, _ = data['labels'].get(target, ('', '', ''))
132 relative_url = app.builder.get_relative_uri(from_docname, docname)
134 # Add a text label to the link.
135 if target.startswith('figure'):
137 elif target.startswith('table'):
142 # New reference node with the updated link information.
143 newnode = nodes.reference('',
145 refuri='%s#%s' % (relative_url, label),
147 node.replace_self(newnode)
150 if LooseVersion(sphinx_version) < LooseVersion('1.3.1'):
151 print('Upgrade sphinx to version >= 1.3.1 for '
152 'improved Figure/Table number handling.')
153 # Add a role to handle :numref: references.
154 app.add_role('numref', numref_role)
155 # Process the numref references once the doctree has been created.
156 app.connect('doctree-resolved', process_numref)