xref: /trafficserver/doc/conf.py (revision b63ba6fc)
1# -*- coding: utf-8 -*-
2#
3# Apache Traffic Server documentation build configuration file, created by
4# sphinx-quickstart on Mon Mar  4 06:23:15 2013.
5#
6# Licensed to the Apache Software Foundation (ASF) under one
7# or more contributor license agreements.  See the NOTICE file
8# distributed with this work for additional information
9# regarding copyright ownership.  The ASF licenses this file
10# to you under the Apache License, Version 2.0 (the
11# "License"); you may not use this file except in compliance
12# with the License.  You may obtain a copy of the License at
13#
14#      http://www.apache.org/licenses/LICENSE-2.0
15#
16# Unless required by applicable law or agreed to in writing, software
17# distributed under the License is distributed on an "AS IS" BASIS,
18# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19# See the License for the specific language governing permissions and
20# limitations under the License.
21
22# This file is execfile()d with the current directory set to its containing dir.
23#
24# Note that not all possible configuration values are present in this
25# autogenerated file.
26#
27# All configuration values have a default; values that are commented out
28# serve to show the default.
29
30import sys
31import os
32from datetime import date
33from sphinx import version_info
34
35# If extensions (or modules to document with autodoc) are in another directory,
36# add these directories to sys.path here. If the directory is relative to the
37# documentation root, use os.path.abspath to make it absolute, like shown here.
38sys.path.insert(0, os.path.abspath('ext'))
39sys.path.insert(0, os.path.abspath('.'))
40
41from manpages import man_pages
42
43# -- General configuration -----------------------------------------------------
44
45# Add any Sphinx extension module names here, as strings. They can be extensions
46# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
47extensions = [
48    'sphinx.ext.graphviz',
49    'sphinx.ext.intersphinx',
50    'sphinx.ext.autodoc',
51    'sphinx.ext.todo',
52    'sphinx.ext.coverage',
53    'sphinx.ext.viewcode',
54    'sphinxcontrib.plantuml',
55    'traffic-server',
56]
57
58# Contains values that are dependent on configure.ac.
59LOCAL_CONFIG = os.path.join(os.environ['PWD'], "ext", "local-config.py")
60with open(LOCAL_CONFIG) as f :
61    exec(compile(f.read(), LOCAL_CONFIG, 'exec'))
62
63if version_info >= (1, 4):
64    extensions.append('sphinx.ext.imgmath')
65else:
66    extensions.append('sphinx.ext.pngmath')
67
68# XXX Disabling docxygen for now, since it make RTD documentation builds time
69# out, eg. https://readthedocs.org/projects/trafficserver/builds/3525976/
70# extensions += [
71#   'doxygen',
72# ]
73
74# Add any paths that contain templates here, relative to this directory.
75templates_path = ['_templates']
76
77# The suffix of source filenames.
78source_suffix = '.rst'
79
80# The encoding of source files.
81#source_encoding = 'utf-8-sig'
82
83# The master toctree document.
84master_doc = 'index'
85
86# General information about the project.
87project = u'Apache Traffic Server'
88copyright = u'{}, dev@trafficserver.apache.org'.format(date.today().year)
89
90# The version info for the project you're documenting, acts as replacement for
91# |version| and |release|, also used in various other places throughout the
92# built documents.
93
94# Extract the version from the configure.ac file with regex so as to
95# work identically when building with Autotools (e.g. $ make html)
96# and without (e.g. on Read the Docs)
97
98import re
99
100contents = open('../configure.ac').read()
101match = re.compile('m4_define\(\[TS_VERSION_S],\[(.*?)]\)').search(contents)
102
103# The full version, including alpha/beta/rc tags.
104release = match.group(1)
105# The short X.Y version.
106version = '.'.join(release.split('.', 2)[:2])
107
108# The language for content autogenerated by Sphinx. Refer to documentation
109# for a list of supported languages.
110#language = None
111locale_dirs = ['locale/']
112gettext_compact = False
113
114# HACK for Read-the-Docs
115# Generate .mo files just in time
116if os.environ.get('READTHEDOCS') == 'True':
117    import polib
118    print("Generating .mo files"),
119    for locale_dir in locale_dirs:
120        for path, dummy, filenames in os.walk(locale_dir):
121            for filename in filenames:
122                po_file = os.path.join(path, filename)
123                base, ext = os.path.splitext(po_file)
124                if ext == ".po":
125                    mo_file = base + ".mo"
126                    po = polib.pofile(po_file)
127                    po.save_as_mofile(fpath=mo_file)
128    print("done")
129else:
130    # On RedHat-based distributions, install the python-sphinx_rtd_theme package
131    # to get an end result tht looks more like readthedoc.org.
132    try:
133        import sphinx_rtd_theme
134        html_theme = 'sphinx_rtd_theme'
135        html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
136    except:
137        pass
138# End of HACK
139
140# There are two options for replacing |today|: either, you set today to some
141# non-false value, then it is used:
142#today = ''
143# Else, today_fmt is used as the format for a strftime call.
144#today_fmt = '%B %d, %Y'
145
146# List of patterns, relative to source directory, that match files and
147# directories to ignore when looking for source files.
148exclude_patterns = []
149
150# The reST default role (used for this markup: `text`) to use for all documents.
151#default_role = None
152
153# If true, '()' will be appended to :func: etc. cross-reference text.
154#add_function_parentheses = True
155
156# If true, the current module name will be prepended to all description
157# unit titles (such as .. function::).
158#add_module_names = True
159
160# If true, sectionauthor and moduleauthor directives will be shown in the
161# output. They are ignored by default.
162#show_authors = False
163
164# The name of the Pygments (syntax highlighting) style to use.
165pygments_style = 'default'
166
167# A list of ignored prefixes for module index sorting.
168#modindex_common_prefix = []
169
170nitpicky = True
171nitpick_ignore = [ ('c:type', 'int64_t')
172                 , ('c:type', 'bool')
173                 , ('c:type', 'sockaddr')
174                 , ('cpp:identifier', 'T') # template arg
175                 , ('cpp:identifier', 'F') # template arg
176                 , ('cpp:identifier', 'Args') # variadic template arg
177                 , ('cpp:identifier', 'Rest') # variadic template arg
178                 ]
179
180# Autolink issue references.
181# See Customizing the Parser in the docutils.parsers.rst module.
182
183from docutils import nodes
184from docutils.parsers.rst import states
185from docutils.utils import punctuation_chars
186from docutils.utils import unescape
187
188# Customize parser.inliner in the only way that Sphinx supports.
189# docutils.parsers.rst.Parser takes an instance of states.Inliner or a
190# subclass, but Sphinx initializes the parser without any arguments,
191# in SphinxStandaloneReader.set_parser('restructuredtext'),
192# which is called from Publisher.set_components().
193
194# states.Inliner isn't a new-style class, so super() isn't an option.
195BaseInliner = states.Inliner
196
197
198class Inliner(states.Inliner):
199    def init_customizations(self, settings):
200        self.__class__ = BaseInliner
201        BaseInliner.init_customizations(self, settings)
202        self.__class__ = Inliner
203
204        # Copied from states.Inliner.init_customizations().
205        # In Docutils 0.13 these are locals.
206        if not hasattr(self, 'start_string_prefix'):
207            self.start_string_prefix = (u'(^|(?<=\\s|[%s%s]))' %
208                                        (punctuation_chars.openers,
209                                         punctuation_chars.delimiters))
210        if not hasattr(self, 'end_string_suffix'):
211            self.end_string_suffix = (u'($|(?=\\s|[\x00%s%s%s]))' %
212                                      (punctuation_chars.closing_delimiters,
213                                       punctuation_chars.delimiters,
214                                       punctuation_chars.closers))
215
216        issue = re.compile(
217            r'''
218      {start_string_prefix}
219      TS-\d+
220      {end_string_suffix}'''.format(
221                start_string_prefix=self.start_string_prefix,
222                end_string_suffix=self.end_string_suffix),
223            re.VERBOSE | re.UNICODE)
224
225        self.implicit_dispatch.append((issue, self.issue_reference))
226
227    def issue_reference(self, match, lineno):
228        text = match.group(0)
229
230        rawsource = unescape(text, True)
231        text = unescape(text, False)
232
233        refuri = 'https://issues.apache.org/jira/browse/' + text
234
235        return [nodes.reference(rawsource, text, refuri=refuri)]
236
237
238states.Inliner = Inliner
239
240# -- Options for HTML output ---------------------------------------------------
241
242# The theme to use for HTML and HTML Help pages.  See the documentation for
243# a list of builtin themes.
244#html_theme = 'agogo'
245
246# Theme options are theme-specific and customize the look and feel of a theme
247# further.  For a list of options available for each theme, see the
248# documentation.
249#html_theme_options = {}
250
251# Add any paths that contain custom themes here, relative to this directory.
252#html_theme_path = []
253
254# The name for this set of Sphinx documents.  If None, it defaults to
255# "<project> v<release> documentation".
256#html_title = None
257
258# A shorter title for the navigation bar.  Default is the same as html_title.
259#html_short_title = None
260
261# The name of an image file (relative to this directory) to place at the top
262# of the sidebar.
263html_logo = 'static/images/trans_logo_tm_380x69.png'
264
265# The name of an image file (within the static path) to use as favicon of the
266# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
267# pixels large.
268html_favicon = 'static/images/favicon.ico'
269
270# Add any paths that contain custom static files (such as style sheets) here,
271# relative to this directory. They are copied after the builtin static files,
272# so a file named "default.css" will overwrite the builtin "default.css".
273html_static_path = ['static']
274
275# Include a stylesheet that overrides default table styling, to provide
276# content wrapping.
277html_context = {
278    'css_files': [
279        '_static/override.css'
280    ]
281}
282if os.environ.get('READTHEDOCS', None) == 'True':
283    html_context = {
284        'css_files': [
285            'https://media.readthedocs.org/css/sphinx_rtd_theme.css',
286            'https://media.readthedocs.org/css/readthedocs-doc-embed.css',
287            '_static/override.css'
288        ]
289    }
290
291# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
292# using the given strftime format.
293#html_last_updated_fmt = '%b %d, %Y'
294
295# If true, SmartyPants will be used to convert quotes and dashes to
296# typographically correct entities.
297#html_use_smartypants = True
298
299# Custom sidebar templates, maps document names to template names.
300#html_sidebars = {}
301
302# Additional templates that should be rendered to pages, maps page names to
303# template names.
304#html_additional_pages = {}
305
306# If false, no module index is generated.
307#html_domain_indices = True
308
309# If false, no index is generated.
310#html_use_index = True
311
312# If true, the index is split into individual pages for each letter.
313#html_split_index = False
314
315# If true, links to the reST sources are added to the pages.
316#html_show_sourcelink = True
317
318# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
319#html_show_sphinx = True
320
321# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
322#html_show_copyright = True
323
324# If true, an OpenSearch description file will be output, and all pages will
325# contain a <link> tag referring to it.  The value of this option must be the
326# base URL from which the finished HTML is served.
327#html_use_opensearch = ''
328
329# This is the file name suffix for HTML files (e.g. ".xhtml").
330#html_file_suffix = None
331
332# Output file base name for HTML help builder.
333htmlhelp_basename = 'ApacheTrafficServerdoc'
334
335# -- Options for LaTeX output --------------------------------------------------
336
337latex_elements = {
338    # The paper size ('letterpaper' or 'a4paper').
339    #'papersize': 'letterpaper',
340
341    # The font size ('10pt', '11pt' or '12pt').
342    #'pointsize': '10pt',
343
344    # Additional stuff for the LaTeX preamble.
345    #'preamble': '',
346}
347
348if 'latex_a4' in tags:
349    latex_elements['papersize'] = 'a4paper'
350elif 'latex_paper' in tags:
351    latex_elements['papersiize'] = 'letterpaper'
352
353# Grouping the document tree into LaTeX files. List of tuples
354# (source start file, target name, title, author, documentclass [howto/manual]).
355latex_documents = [
356    ('index', 'ApacheTrafficServer.tex', u'Apache Traffic Server Documentation',
357     u'dev@trafficserver.apache.org', 'manual'),
358]
359
360# The name of an image file (relative to this directory) to place at the top of
361# the title page.
362#latex_logo = None
363
364# For "manual" documents, if this is true, then toplevel headings are parts,
365# not chapters.
366#latex_use_parts = False
367
368# If true, show page references after internal links.
369#latex_show_pagerefs = False
370
371# If true, show URL addresses after external links.
372#latex_show_urls = False
373
374# Documents to append as an appendix to all manuals.
375#latex_appendices = []
376
377# If false, no module index is generated.
378#latex_domain_indices = True
379
380# -- Options for manual page output --------------------------------------------
381
382# The global "man_pages" is imported from ts/manpages.py
383
384# If true, show URL addresses after external links.
385#man_show_urls = False
386
387# Get the manual page description from the reStructuredText document.
388# This keeps the list of manual pages consistent with the source
389# documents and includes the same brief description in both the HTML
390# and manual page outputs.
391
392from docutils.transforms import frontmatter
393from sphinx.writers import manpage
394
395# Override ManualPageWriter and ManualPageTranslator in the only way
396# that Sphinx supports
397
398BaseWriter = manpage.ManualPageWriter
399
400
401class ManualPageWriter(BaseWriter):
402    def translate(self):
403        transform = frontmatter.DocTitle(self.document)
404
405        section, index = transform.candidate_index(self.document)
406        if index:
407
408            # A sentence after the title is the manual page description
409            if len(section) > 1 and isinstance(section[1], nodes.paragraph):
410
411                description = section.pop(1).astext()
412                description = description[:1].lower() + description[1:]
413                description = description.rstrip('.')
414
415                self.document.settings.subtitle = description
416
417            # Instead of section_level = -1, use the standard Docutils
418            # DocTitle transform to hide the top level title
419            transform.promote_title(self.document)
420
421        # The title is the manual page name
422        transform.set_metadata()
423
424        BaseWriter.translate(self)
425
426
427manpage.ManualPageWriter = ManualPageWriter
428
429BaseTranslator = manpage.ManualPageTranslator
430
431
432class ManualPageTranslator(BaseTranslator):
433    def __init__(self, builder, *args, **kwds):
434        BaseTranslator.__init__(self, builder, *args, **kwds)
435
436        # Instead of section_level = -1, use the standard Docutils
437        # DocTitle transform to hide the top level title
438        self.section_level = 0
439
440
441manpage.ManualPageTranslator = ManualPageTranslator
442
443# -- Options for Texinfo output ------------------------------------------------
444
445# Grouping the document tree into Texinfo files. List of tuples
446# (source start file, target name, title, author,
447#  dir menu entry, description, category)
448texinfo_documents = [
449    ('index', 'ApacheTrafficServer', u'Apache Traffic Server Documentation',
450     u'dev@trafficserver.apache.org', 'ApacheTrafficServer', 'One line description of project.',
451     'Miscellaneous'),
452]
453
454# Documents to append as an appendix to all manuals.
455#texinfo_appendices = []
456
457# If false, no module index is generated.
458#texinfo_domain_indices = True
459
460# How to display URL addresses: 'footnote', 'no', or 'inline'.
461#texinfo_show_urls = 'footnote'
462
463# -- Options for Epub output ---------------------------------------------------
464
465# Bibliographic Dublin Core info.
466epub_title = u'Apache Traffic Server'
467epub_author = u'dev@trafficserver.apache.org'
468epub_publisher = u'dev@trafficserver.apache.org'
469epub_copyright = u'2013, dev@trafficserver.apache.org'
470
471# The language of the text. It defaults to the language option
472# or en if the language is not set.
473#epub_language = ''
474
475# The scheme of the identifier. Typical schemes are ISBN or URL.
476#epub_scheme = ''
477
478# The unique identifier of the text. This can be a ISBN number
479# or the project homepage.
480#epub_identifier = ''
481
482# A unique identification for the text.
483#epub_uid = ''
484
485# A tuple containing the cover image and cover page html template filenames.
486#epub_cover = ()
487
488# HTML files that should be inserted before the pages created by sphinx.
489# The format is a list of tuples containing the path and title.
490#epub_pre_files = []
491
492# HTML files shat should be inserted after the pages created by sphinx.
493# The format is a list of tuples containing the path and title.
494#epub_post_files = []
495
496# A list of files that should not be packed into the epub file.
497#epub_exclude_files = []
498
499# The depth of the table of contents in toc.ncx.
500#epub_tocdepth = 3
501
502# Allow duplicate toc entries.
503#epub_tocdup = True
504#mathjax_path = 'https://docs.trafficserver.apache.org/__RTD/MathJax.js'
505
506# Enabling marking bit fields as 'bitfield_N`.
507# Currently parameterized fields don't work. When they do, we should change to
508# 'bitfield(N)'.
509cpp_id_attributes = [ 'bitfield_1', 'bitfield_3', 'bitfield_24' ]
510