salt/doc/conf.py

177 lines
4.3 KiB
Python
Raw Normal View History

2012-09-24 20:17:56 +00:00
# -*- coding: utf-8 -*-
2012-10-15 17:48:56 +00:00
# pylint: disable=C0103,W0622
'''
Sphinx documentation for salt-api
'''
import os
import sys
2012-09-24 20:17:56 +00:00
2012-10-15 17:48:56 +00:00
from sphinx.directives import TocTree
# pylint: disable=R0903
2012-09-24 20:17:56 +00:00
class Mock(object):
'''
Mock out specified imports
This allows autodoc to do it's thing without having oodles of req'd
installed libs. This doesn't work with ``import *`` imports.
http://read-the-docs.readthedocs.org/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules
'''
def __init__(self, *args, **kwargs):
pass
def __call__(self, *args, **kwargs):
return Mock()
@classmethod
2012-10-15 17:48:56 +00:00
def __getattr__(cls, name):
2012-09-24 20:17:56 +00:00
if name in ('__file__', '__path__'):
return '/dev/null'
elif name[0] == name[0].upper():
return type(name, (), {})
else:
return Mock()
2012-10-15 17:48:56 +00:00
# pylint: enable=R0903
2012-09-24 20:17:56 +00:00
MOCK_MODULES = [
# third-party libs (for netapi modules)
'flask',
'flask.globals',
'flask.views',
'werkzeug',
'werkzeug.exceptions',
# salt libs
'salt',
'salt.client',
'salt.exceptions',
'salt.log',
'salt.runner',
'salt.utils',
2012-09-24 20:17:56 +00:00
]
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock()
2012-10-15 17:48:56 +00:00
# -- Add paths to PYTHONPATH ---------------------------------------------------
2012-09-24 20:17:56 +00:00
docs_basepath = os.path.abspath(os.path.dirname(__file__))
addtl_paths = (
2012-10-15 17:48:56 +00:00
os.pardir, # salt-api itself (for autodoc/autohttp)
'_ext', # custom Sphinx extensions
)
2012-09-24 20:17:56 +00:00
for path in addtl_paths:
sys.path.insert(0, os.path.abspath(os.path.join(docs_basepath, path)))
from saltapi.version import __version__
2012-10-15 17:48:56 +00:00
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
2012-09-24 20:17:56 +00:00
2012-10-15 17:48:56 +00:00
# -- General configuration -----------------------------------------------------
2012-09-24 20:17:56 +00:00
2012-10-15 17:48:56 +00:00
project = 'salt-api'
copyright = '2012, Thomas S. Hatch'
2012-09-24 20:17:56 +00:00
version = __version__
release = version
2012-10-15 17:48:56 +00:00
master_doc = 'index'
templates_path = ['_templates']
2012-09-24 20:17:56 +00:00
exclude_patterns = ['_build']
2012-10-15 17:48:56 +00:00
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.intersphinx',
'sphinxcontrib.httpdomain',
'sphinxcontrib.autohttp.flask',
]
2012-09-24 20:17:56 +00:00
2012-10-15 17:48:56 +00:00
modindex_common_prefix = ['saltapi.']
2012-09-24 20:17:56 +00:00
2012-10-15 17:48:56 +00:00
autosummary_generate = True
2012-09-24 20:17:56 +00:00
2012-10-15 17:48:56 +00:00
intersphinx_mapping = {
'salt': ('http://docs.saltstack.org/en/latest/', None),
}
2012-09-24 20:17:56 +00:00
2012-10-15 17:48:56 +00:00
### HTML options
2012-09-24 20:17:56 +00:00
html_theme = 'default'
2012-10-15 17:48:56 +00:00
html_title = None
html_short_title = 'salt-api'
2012-09-24 20:17:56 +00:00
html_static_path = ['_static']
2012-10-15 17:48:56 +00:00
html_logo = 'salt-vert.png'
html_favicon = 'favicon.ico'
html_use_smartypants = False
html_use_index = True
html_last_updated_fmt = '%b %d, %Y'
html_show_sourcelink = False
html_show_sphinx = True
html_show_copyright = True
2012-09-24 20:17:56 +00:00
#html_use_opensearch = ''
2012-10-15 17:48:56 +00:00
### Latex options
2012-09-24 20:17:56 +00:00
latex_documents = [
2012-10-15 17:48:56 +00:00
('contents', 'salt-api.tex', 'salt-api Documentation', 'Thomas Hatch', 'manual'),
2012-09-24 20:17:56 +00:00
]
2012-10-15 17:48:56 +00:00
latex_logo = '_static/salt-vert.png'
2012-09-24 20:17:56 +00:00
### Manpage options
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
authors = [
'Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file',
]
man_pages = [
2012-10-15 17:48:56 +00:00
('contents', 'salt-api', 'salt-api Documentation', authors, 1),
2012-09-24 20:17:56 +00:00
]
2012-10-15 17:48:56 +00:00
### epub options
epub_title = 'salt-api Documentation'
epub_author = 'Thomas S. Hatch'
epub_publisher = epub_author
epub_copyright = '2012, Thomas S. Hatch'
2012-09-24 20:17:56 +00:00
2012-10-15 17:48:56 +00:00
epub_scheme = 'URL'
epub_identifier = 'http://saltstack.org/'
2012-09-24 20:17:56 +00:00
#epub_tocdepth = 3
2012-10-15 17:48:56 +00:00
###############################################################################
def _normalize_version(args):
_, path = args
return '.'.join([x.zfill(4) for x in (path.split('/')[-1].split('.'))])
class ReleasesTree(TocTree):
option_spec = dict(TocTree.option_spec)
def run(self):
rst = super(ReleasesTree, self).run()
entries = rst[0][0]['entries'][:]
entries.sort(key=_normalize_version, reverse=True)
rst[0][0]['entries'][:] = entries
return rst
def setup(app):
# Copy ReleasesTree directive from Salt for properly sorting release
# numbers with glob
app.add_directive('releasestree', ReleasesTree)
# Copy crossref types from Salt for master/minion conf files
app.add_crossref_type(directivename="conf_master", rolename="conf_master",
indextemplate="pair: %s; conf/master")
app.add_crossref_type(directivename="conf_minion", rolename="conf_minion",
indextemplate="pair: %s; conf/minion")