1
0

conf.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. # -*- coding: utf-8 -*-
  2. # pylint: disable=C0103,W0622
  3. """
  4. Sphinx documentation for Salt
  5. """
  6. import os
  7. import re
  8. import sys
  9. import time
  10. import types
  11. from sphinx.directives.other import TocTree
  12. class Mock(object):
  13. """
  14. Mock out specified imports.
  15. This allows autodoc to do its thing without having oodles of req'd
  16. installed libs. This doesn't work with ``import *`` imports.
  17. This Mock class can be configured to return a specific values at specific names, if required.
  18. https://read-the-docs.readthedocs.io/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules
  19. """
  20. def __init__(
  21. self, mapping=None, *args, **kwargs
  22. ): # pylint: disable=unused-argument
  23. """
  24. Mapping allows autodoc to bypass the Mock object, but actually assign
  25. a specific value, expected by a specific attribute returned.
  26. """
  27. self.__mapping = mapping or {}
  28. __all__ = []
  29. def __call__(self, *args, **kwargs):
  30. # If mocked function is used as a decorator, expose decorated function.
  31. # if args and callable(args[-1]):
  32. # functools.update_wrapper(ret, args[0])
  33. return Mock(mapping=self.__mapping)
  34. def __getattr__(self, name):
  35. if name in self.__mapping:
  36. data = self.__mapping.get(name)
  37. elif name in ("__file__", "__path__"):
  38. data = "/dev/null"
  39. elif name in ("__mro_entries__", "__qualname__"):
  40. raise AttributeError("'Mock' object has no attribute '%s'" % (name))
  41. else:
  42. data = Mock(mapping=self.__mapping)
  43. return data
  44. def __iter__(self):
  45. return self
  46. @staticmethod
  47. def __next__():
  48. raise StopIteration
  49. # For Python 2
  50. next = __next__
  51. def mock_decorator_with_params(*oargs, **okwargs): # pylint: disable=unused-argument
  52. """
  53. Optionally mock a decorator that takes parameters
  54. E.g.:
  55. @blah(stuff=True)
  56. def things():
  57. pass
  58. """
  59. def inner(fn, *iargs, **ikwargs): # pylint: disable=unused-argument
  60. if hasattr(fn, "__call__"):
  61. return fn
  62. return Mock()
  63. return inner
  64. MOCK_MODULES = [
  65. # Python stdlib
  66. "user",
  67. # salt core
  68. "Crypto",
  69. "Crypto.Signature",
  70. "Crypto.Cipher",
  71. "Crypto.Hash",
  72. "Crypto.PublicKey",
  73. "Crypto.Random",
  74. "Crypto.Signature",
  75. "Crypto.Signature.PKCS1_v1_5",
  76. "distro",
  77. "M2Crypto",
  78. "msgpack",
  79. "yaml",
  80. "yaml.constructor",
  81. "yaml.nodes",
  82. "yaml.parser",
  83. "yaml.scanner",
  84. "zmq",
  85. "zmq.eventloop",
  86. "zmq.eventloop.ioloop",
  87. # third-party libs for cloud modules
  88. "libcloud",
  89. "libcloud.compute",
  90. "libcloud.compute.base",
  91. "libcloud.compute.deployment",
  92. "libcloud.compute.providers",
  93. "libcloud.compute.types",
  94. "libcloud.loadbalancer",
  95. "libcloud.loadbalancer.types",
  96. "libcloud.loadbalancer.providers",
  97. "libcloud.common",
  98. "libcloud.common.google",
  99. # third-party libs for netapi modules
  100. "cherrypy",
  101. "cherrypy.lib",
  102. "cherrypy.process",
  103. "cherrypy.wsgiserver",
  104. "cherrypy.wsgiserver.ssl_builtin",
  105. "tornado",
  106. "tornado.concurrent",
  107. "tornado.escape",
  108. "tornado.gen",
  109. "tornado.httpclient",
  110. "tornado.httpserver",
  111. "tornado.httputil",
  112. "tornado.ioloop",
  113. "tornado.iostream",
  114. "tornado.netutil",
  115. "tornado.simple_httpclient",
  116. "tornado.stack_context",
  117. "tornado.web",
  118. "tornado.websocket",
  119. "tornado.locks",
  120. "ws4py",
  121. "ws4py.server",
  122. "ws4py.server.cherrypyserver",
  123. "ws4py.websocket",
  124. # modules, renderers, states, returners, et al
  125. "ClusterShell",
  126. "ClusterShell.NodeSet",
  127. "MySQLdb",
  128. "MySQLdb.cursors",
  129. "OpenSSL",
  130. "avahi",
  131. "boto.regioninfo",
  132. "dbus",
  133. "django",
  134. "dns",
  135. "dns.resolver",
  136. "dson",
  137. "hjson",
  138. "jnpr",
  139. "jnpr.junos",
  140. "jnpr.junos.utils",
  141. "jnpr.junos.utils.config",
  142. "jnpr.junos.utils.sw",
  143. "keyring",
  144. "kubernetes",
  145. "kubernetes.config",
  146. "libvirt",
  147. "lxml",
  148. "lxml.etree",
  149. "msgpack",
  150. "nagios_json",
  151. "napalm",
  152. "netaddr",
  153. "netaddr.IPAddress",
  154. "netaddr.core",
  155. "netaddr.core.AddrFormatError",
  156. "ntsecuritycon",
  157. "psutil",
  158. "pycassa",
  159. "pyconnman",
  160. "pyiface",
  161. "pymongo",
  162. "pyroute2",
  163. "pyroute2.ipdb",
  164. "rabbitmq_server",
  165. "redis",
  166. "rpm",
  167. "rpmUtils",
  168. "rpmUtils.arch",
  169. "salt.ext.six.moves.winreg",
  170. "twisted",
  171. "twisted.internet",
  172. "twisted.internet.protocol",
  173. "twisted.internet.protocol.DatagramProtocol",
  174. "win32security",
  175. "yum",
  176. "zfs",
  177. ]
  178. MOCK_MODULES_MAPPING = {
  179. "cherrypy": {"config": mock_decorator_with_params},
  180. "ntsecuritycon": {"STANDARD_RIGHTS_REQUIRED": 0, "SYNCHRONIZE": 0,},
  181. "psutil": {"total": 0}, # Otherwise it will crash Sphinx
  182. }
  183. for mod_name in MOCK_MODULES:
  184. sys.modules[mod_name] = Mock(mapping=MOCK_MODULES_MAPPING.get(mod_name))
  185. # Define a fake version attribute for the following libs.
  186. sys.modules["libcloud"].__version__ = "0.0.0"
  187. sys.modules["msgpack"].version = (1, 0, 0)
  188. sys.modules["psutil"].version_info = (3, 0, 0)
  189. sys.modules["pymongo"].version = "0.0.0"
  190. sys.modules["tornado"].version_info = (0, 0, 0)
  191. sys.modules["boto.regioninfo"]._load_json_file = {"endpoints": None}
  192. # -- Add paths to PYTHONPATH ---------------------------------------------------
  193. try:
  194. docs_basepath = os.path.abspath(os.path.dirname(__file__))
  195. except NameError:
  196. # sphinx-intl and six execute some code which will raise this NameError
  197. # assume we're in the doc/ directory
  198. docs_basepath = os.path.abspath(os.path.dirname("."))
  199. addtl_paths = (
  200. os.pardir, # salt itself (for autodoc)
  201. "_ext", # custom Sphinx extensions
  202. )
  203. for addtl_path in addtl_paths:
  204. sys.path.insert(0, os.path.abspath(os.path.join(docs_basepath, addtl_path)))
  205. # We're now able to import salt
  206. import salt.version # isort:skip
  207. formulas_dir = os.path.join(os.pardir, docs_basepath, "formulas")
  208. # ----- Intersphinx Settings ------------------------------------------------>
  209. intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
  210. # <---- Intersphinx Settings -------------------------------------------------
  211. # -- General Configuration -----------------------------------------------------
  212. # Set a var if we're building docs for the live site or not
  213. on_saltstack = "SALT_ON_SALTSTACK" in os.environ
  214. project = "Salt"
  215. repo_primary_branch = (
  216. "master" # This is the default branch on GitHub for the Salt project
  217. )
  218. version = salt.version.__version__
  219. latest_release = os.environ.get(
  220. "LATEST_RELEASE", "latest_release"
  221. ) # latest release (2019.2.3)
  222. previous_release = os.environ.get(
  223. "PREVIOUS_RELEASE", "previous_release"
  224. ) # latest release from previous branch (2018.3.5)
  225. previous_release_dir = os.environ.get(
  226. "PREVIOUS_RELEASE_DIR", "previous_release_dir"
  227. ) # path on web server for previous branch (2018.3)
  228. next_release = "" # next release
  229. next_release_dir = "" # path on web server for next release branch
  230. today = ""
  231. copyright = ""
  232. if on_saltstack:
  233. today = (
  234. "Generated on "
  235. + time.strftime("%B %d, %Y")
  236. + " at "
  237. + time.strftime("%X %Z")
  238. + "."
  239. )
  240. copyright = time.strftime("%Y")
  241. # < --- START do not merge these settings to other branches START ---> #
  242. build_type = os.environ.get(
  243. "BUILD_TYPE", repo_primary_branch
  244. ) # latest, previous, master, next
  245. # < --- END do not merge these settings to other branches END ---> #
  246. # Set google custom search engine
  247. if build_type == repo_primary_branch:
  248. release = latest_release
  249. search_cx = "011515552685726825874:v1had6i279q" # master
  250. # search_cx = '011515552685726825874:x17j5zl74g8' # develop
  251. elif build_type == "next":
  252. release = next_release
  253. search_cx = "011515552685726825874:ht0p8miksrm" # latest
  254. elif build_type == "previous":
  255. release = previous_release
  256. if release.startswith("3000"):
  257. search_cx = "011515552685726825874:3skhaozjtyn" # 3000
  258. elif release.startswith("2019.2"):
  259. search_cx = "011515552685726825874:huvjhlpptnm" # 2019.2
  260. elif release.startswith("2018.3"):
  261. search_cx = "011515552685726825874:vadptdpvyyu" # 2018.3
  262. elif release.startswith("2017.7"):
  263. search_cx = "011515552685726825874:w-hxmnbcpou" # 2017.7
  264. elif release.startswith("2016.11"):
  265. search_cx = "011515552685726825874:dlsj745pvhq" # 2016.11
  266. else:
  267. search_cx = "011515552685726825874:ht0p8miksrm" # latest
  268. else: # latest or something else
  269. release = latest_release
  270. search_cx = "011515552685726825874:ht0p8miksrm" # latest
  271. needs_sphinx = "1.3"
  272. spelling_lang = "en_US"
  273. language = "en"
  274. locale_dirs = [
  275. "_locale",
  276. ]
  277. master_doc = "contents"
  278. templates_path = ["_templates"]
  279. exclude_patterns = ["_build", "_incl/*", "ref/cli/_includes/*.rst"]
  280. extensions = [
  281. "saltdomain", # Must come early
  282. "sphinx.ext.autodoc",
  283. "sphinx.ext.napoleon",
  284. "sphinx.ext.autosummary",
  285. "sphinx.ext.extlinks",
  286. "sphinx.ext.intersphinx",
  287. "httpdomain",
  288. "youtube",
  289. "saltrepo"
  290. #'saltautodoc', # Must be AFTER autodoc
  291. #'shorturls',
  292. ]
  293. try:
  294. import sphinxcontrib.spelling # false positive, pylint: disable=unused-import
  295. except ImportError:
  296. pass
  297. else:
  298. extensions += ["sphinxcontrib.spelling"]
  299. modindex_common_prefix = ["salt."]
  300. autosummary_generate = True
  301. # strip git rev as there won't necessarily be a release based on it
  302. stripped_release = re.sub(r"-\d+-g[0-9a-f]+$", "", release)
  303. # Define a substitution for linking to the latest release tarball
  304. rst_prolog = """\
  305. .. |current_release_doc| replace:: :doc:`/topics/releases/{release}`
  306. .. |saltrepo| replace:: https://github.com/saltstack/salt
  307. .. _`salt-users`: https://groups.google.com/forum/#!forum/salt-users
  308. .. _`salt-announce`: https://groups.google.com/forum/#!forum/salt-announce
  309. .. _`salt-packagers`: https://groups.google.com/forum/#!forum/salt-packagers
  310. .. _`salt-slack`: https://saltstackcommunity.herokuapp.com/
  311. .. |windownload| raw:: html
  312. <p>Python2 x86: <a
  313. href="https://repo.saltstack.com/windows/Salt-Minion-{release}-Py2-x86-Setup.exe"><strong>Salt-Minion-{release}-x86-Setup.exe</strong></a>
  314. | <a href="https://repo.saltstack.com/windows/Salt-Minion-{release}-Py2-x86-Setup.exe.md5"><strong>md5</strong></a></p>
  315. <p>Python2 AMD64: <a
  316. href="https://repo.saltstack.com/windows/Salt-Minion-{release}-Py2-AMD64-Setup.exe"><strong>Salt-Minion-{release}-AMD64-Setup.exe</strong></a>
  317. | <a href="https://repo.saltstack.com/windows/Salt-Minion-{release}-Py2-AMD64-Setup.exe.md5"><strong>md5</strong></a></p>
  318. <p>Python3 x86: <a
  319. href="https://repo.saltstack.com/windows/Salt-Minion-{release}-Py3-x86-Setup.exe"><strong>Salt-Minion-{release}-x86-Setup.exe</strong></a>
  320. | <a href="https://repo.saltstack.com/windows/Salt-Minion-{release}-Py3-x86-Setup.exe.md5"><strong>md5</strong></a></p>
  321. <p>Python3 AMD64: <a
  322. href="https://repo.saltstack.com/windows/Salt-Minion-{release}-Py3-AMD64-Setup.exe"><strong>Salt-Minion-{release}-AMD64-Setup.exe</strong></a>
  323. | <a href="https://repo.saltstack.com/windows/Salt-Minion-{release}-Py3-AMD64-Setup.exe.md5"><strong>md5</strong></a></p>
  324. .. |osxdownloadpy2| raw:: html
  325. <p>x86_64: <a href="https://repo.saltstack.com/osx/salt-{release}-py2-x86_64.pkg"><strong>salt-{release}-py2-x86_64.pkg</strong></a>
  326. | <a href="https://repo.saltstack.com/osx/salt-{release}-py2-x86_64.pkg.md5"><strong>md5</strong></a></p>
  327. .. |osxdownloadpy3| raw:: html
  328. <p>x86_64: <a href="https://repo.saltstack.com/osx/salt-{release}-py3-x86_64.pkg"><strong>salt-{release}-py3-x86_64.pkg</strong></a>
  329. | <a href="https://repo.saltstack.com/osx/salt-{release}-py3-x86_64.pkg.md5"><strong>md5</strong></a></p>
  330. """.format(
  331. release=stripped_release
  332. )
  333. # A shortcut for linking to tickets on the GitHub issue tracker
  334. extlinks = {
  335. "blob": (
  336. "https://github.com/saltstack/salt/blob/%s/%%s" % repo_primary_branch,
  337. None,
  338. ),
  339. "issue": ("https://github.com/saltstack/salt/issues/%s", "issue #"),
  340. "pull": ("https://github.com/saltstack/salt/pull/%s", "PR #"),
  341. "formula_url": ("https://github.com/saltstack-formulas/%s", ""),
  342. }
  343. # ----- Localization -------------------------------------------------------->
  344. locale_dirs = ["locale/"]
  345. gettext_compact = False
  346. # <---- Localization ---------------------------------------------------------
  347. ### HTML options
  348. # set 'HTML_THEME=saltstack' to use previous theme
  349. html_theme = os.environ.get("HTML_THEME", "saltstack2")
  350. html_theme_path = ["_themes"]
  351. html_title = u""
  352. html_short_title = "Salt"
  353. html_static_path = ["_static"]
  354. html_logo = None # specified in the theme layout.html
  355. html_favicon = "favicon.ico"
  356. smartquotes = False
  357. # Use Google customized search or use Sphinx built-in JavaScript search
  358. if on_saltstack:
  359. html_search_template = "googlesearch.html"
  360. else:
  361. html_search_template = "searchbox.html"
  362. html_additional_pages = {
  363. "404": "404.html",
  364. }
  365. html_default_sidebars = [
  366. html_search_template,
  367. "version.html",
  368. "localtoc.html",
  369. "relations.html",
  370. "sourcelink.html",
  371. "saltstack.html",
  372. ]
  373. html_sidebars = {
  374. "ref/**/all/salt.*": [
  375. html_search_template,
  376. "version.html",
  377. "modules-sidebar.html",
  378. "localtoc.html",
  379. "relations.html",
  380. "sourcelink.html",
  381. "saltstack.html",
  382. ],
  383. "ref/formula/all/*": [],
  384. }
  385. html_context = {
  386. "on_saltstack": on_saltstack,
  387. "html_default_sidebars": html_default_sidebars,
  388. "github_base": "https://github.com/saltstack/salt",
  389. "github_issues": "https://github.com/saltstack/salt/issues",
  390. "github_downloads": "https://github.com/saltstack/salt/downloads",
  391. "latest_release": latest_release,
  392. "previous_release": previous_release,
  393. "previous_release_dir": previous_release_dir,
  394. "next_release": next_release,
  395. "next_release_dir": next_release_dir,
  396. "search_cx": search_cx,
  397. "build_type": build_type,
  398. "today": today,
  399. "copyright": copyright,
  400. "repo_primary_branch": repo_primary_branch,
  401. }
  402. html_use_index = True
  403. html_last_updated_fmt = "%b %d, %Y"
  404. html_show_sourcelink = False
  405. html_show_sphinx = True
  406. html_show_copyright = True
  407. ### Latex options
  408. latex_documents = [
  409. ("contents", "Salt.tex", "Salt Documentation", "SaltStack, Inc.", "manual"),
  410. ]
  411. latex_logo = "_static/salt-logo.png"
  412. latex_elements = {
  413. "inputenc": "", # use XeTeX instead of the inputenc LaTeX package.
  414. "utf8extra": "",
  415. "preamble": r"""
  416. \usepackage{fontspec}
  417. \setsansfont{Linux Biolinum O}
  418. \setromanfont{Linux Libertine O}
  419. \setmonofont{Source Code Pro}
  420. """,
  421. }
  422. ### Linux Biolinum, Linux Libertine: http://www.linuxlibertine.org/
  423. ### Source Code Pro: https://github.com/adobe-fonts/source-code-pro/releases
  424. ### Linkcheck options
  425. linkcheck_ignore = [
  426. r"http://127.0.0.1",
  427. r"http://salt:\d+",
  428. r"http://local:\d+",
  429. r"https://console.aws.amazon.com",
  430. r"http://192.168.33.10",
  431. r"http://domain:\d+",
  432. r"http://123.456.789.012:\d+",
  433. r"http://localhost",
  434. r"https://groups.google.com/forum/#!forum/salt-users",
  435. r"https://www.elastic.co/logstash/docs/latest/inputs/udp",
  436. r"https://www.elastic.co/logstash/docs/latest/inputs/zeromq",
  437. r"http://www.youtube.com/saltstack",
  438. r"https://raven.readthedocs.io",
  439. r"https://getsentry.com",
  440. r"https://salt-cloud.readthedocs.io",
  441. r"https://salt.readthedocs.io",
  442. r"http://www.pip-installer.org/",
  443. r"http://www.windowsazure.com/",
  444. r"https://github.com/watching",
  445. r"dash-feed://",
  446. r"https://github.com/saltstack/salt/",
  447. r"http://bootstrap.saltstack.org",
  448. r"https://bootstrap.saltstack.com",
  449. r"https://raw.githubusercontent.com/saltstack/salt-bootstrap/stable/bootstrap-salt.sh",
  450. r"media.readthedocs.org/dash/salt/latest/salt.xml",
  451. r"https://portal.aws.amazon.com/gp/aws/securityCredentials",
  452. r"https://help.github.com/articles/fork-a-repo",
  453. r"dash-feed://https%3A//media.readthedocs.org/dash/salt/latest/salt.xml",
  454. ]
  455. linkcheck_anchors = False
  456. ### Manpage options
  457. # One entry per manual page. List of tuples
  458. # (source start file, name, description, authors, manual section).
  459. authors = [
  460. "Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file",
  461. ]
  462. man_pages = [
  463. ("contents", "salt", "Salt Documentation", authors, 7),
  464. ("ref/cli/salt", "salt", "salt", authors, 1),
  465. ("ref/cli/salt-master", "salt-master", "salt-master Documentation", authors, 1),
  466. ("ref/cli/salt-minion", "salt-minion", "salt-minion Documentation", authors, 1),
  467. ("ref/cli/salt-key", "salt-key", "salt-key Documentation", authors, 1),
  468. ("ref/cli/salt-cp", "salt-cp", "salt-cp Documentation", authors, 1),
  469. ("ref/cli/salt-call", "salt-call", "salt-call Documentation", authors, 1),
  470. ("ref/cli/salt-proxy", "salt-proxy", "salt-proxy Documentation", authors, 1),
  471. ("ref/cli/salt-syndic", "salt-syndic", "salt-syndic Documentation", authors, 1),
  472. ("ref/cli/salt-run", "salt-run", "salt-run Documentation", authors, 1),
  473. ("ref/cli/salt-ssh", "salt-ssh", "salt-ssh Documentation", authors, 1),
  474. ("ref/cli/salt-cloud", "salt-cloud", "Salt Cloud Command", authors, 1),
  475. ("ref/cli/salt-api", "salt-api", "salt-api Command", authors, 1),
  476. ("ref/cli/salt-unity", "salt-unity", "salt-unity Command", authors, 1),
  477. ("ref/cli/spm", "spm", "Salt Package Manager Command", authors, 1),
  478. ]
  479. ### epub options
  480. epub_title = "Salt Documentation"
  481. epub_author = "SaltStack, Inc."
  482. epub_publisher = epub_author
  483. epub_copyright = copyright
  484. epub_scheme = "URL"
  485. epub_identifier = "http://saltstack.com/"
  486. epub_tocdup = False
  487. # epub_tocdepth = 3
  488. def skip_mod_init_member(app, what, name, obj, skip, options):
  489. # pylint: disable=too-many-arguments,unused-argument
  490. if name.startswith("_"):
  491. return True
  492. if isinstance(obj, types.FunctionType) and obj.__name__ == "mod_init":
  493. return True
  494. return False
  495. def _normalize_version(args):
  496. _, path = args
  497. return ".".join([x.zfill(4) for x in (path.split("/")[-1].split("."))])
  498. class ReleasesTree(TocTree):
  499. option_spec = dict(TocTree.option_spec)
  500. def run(self):
  501. rst = super(ReleasesTree, self).run()
  502. entries = rst[0][0]["entries"][:]
  503. entries.sort(key=_normalize_version, reverse=True)
  504. rst[0][0]["entries"][:] = entries
  505. return rst
  506. def setup(app):
  507. app.add_directive("releasestree", ReleasesTree)
  508. app.connect("autodoc-skip-member", skip_mod_init_member)