1# BSD LICENSE 2# Copyright(c) 2010-2015 Intel Corporation. All rights reserved. 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 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 14# distribution. 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. 18# 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. 30 31import subprocess 32from docutils import nodes 33from distutils.version import LooseVersion 34from sphinx import __version__ as sphinx_version 35from sphinx.highlighting import PygmentsBridge 36from pygments.formatters.latex import LatexFormatter 37 38project = 'Data Plane Development Kit' 39 40if LooseVersion(sphinx_version) >= LooseVersion('1.3.1'): 41 html_theme = "sphinx_rtd_theme" 42html_logo = '../logo/DPDK_logo_vertical_rev_small.png' 43latex_logo = '../logo/DPDK_logo_horizontal_tag.png' 44html_add_permalinks = "" 45html_show_copyright = False 46highlight_language = 'none' 47 48version = subprocess.check_output(['make', '-sRrC', '../../', 'showversion']).decode('utf-8') 49release = version 50 51master_doc = 'index' 52 53# Figures, tables and code-blocks automatically numbered if they have caption 54numfig = True 55 56latex_documents = [ 57 ('index', 58 'doc.tex', 59 '', 60 '', 61 'manual') 62] 63 64# Latex directives to be included directly in the latex/pdf docs. 65latex_preamble = r""" 66\usepackage[utf8]{inputenc} 67\usepackage[T1]{fontenc} 68\usepackage{helvet} 69\renewcommand{\familydefault}{\sfdefault} 70\RecustomVerbatimEnvironment{Verbatim}{Verbatim}{xleftmargin=5mm} 71""" 72 73# Configuration for the latex/pdf docs. 74latex_elements = { 75 'papersize': 'a4paper', 76 'pointsize': '11pt', 77 # remove blank pages 78 'classoptions': ',openany,oneside', 79 'babel': '\\usepackage[english]{babel}', 80 # customize Latex formatting 81 'preamble': latex_preamble 82} 83 84# Override the default Latex formatter in order to modify the 85# code/verbatim blocks. 86class 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' 91 92# Replace the default latex formatter. 93PygmentsBridge.latex_formatter = CustomLatexFormatter 94 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. 100 101def numref_role(reftype, rawtext, text, lineno, inliner): 102 """ 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 105 isn't available. 106 """ 107 # Add an identifier to distinguish numref from other references. 108 newnode = nodes.reference('', 109 '', 110 refuri='_local_numref_#%s' % text, 111 internal=True) 112 return [newnode], [] 113 114def process_numref(app, doctree, from_docname): 115 """ 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. 119 """ 120 121 # Iterate over the reference nodes in the doctree. 122 for node in doctree.traverse(nodes.reference): 123 target = node.get('refuri', '') 124 125 # Look for numref nodes. 126 if target.startswith('_local_numref_#'): 127 target = target.replace('_local_numref_#', '') 128 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) 133 134 # Add a text label to the link. 135 if target.startswith('figure'): 136 caption = 'Figure' 137 elif target.startswith('table'): 138 caption = 'Table' 139 else: 140 caption = 'Link' 141 142 # New reference node with the updated link information. 143 newnode = nodes.reference('', 144 caption, 145 refuri='%s#%s' % (relative_url, label), 146 internal=True) 147 node.replace_self(newnode) 148 149def setup(app): 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) 157