You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

conf.py 7.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. # Configuration file for the Sphinx documentation builder.
  2. #
  3. # This file only contains a selection of the most common options. For a full
  4. # list see the documentation:
  5. # https://www.sphinx-doc.org/en/master/usage/configuration.html
  6. # -- Path setup --------------------------------------------------------------
  7. # If extensions (or modules to document with autodoc) are in another directory,
  8. # add these directories to sys.path here. If the directory is relative to the
  9. # documentation root, use os.path.abspath to make it absolute, like shown here.
  10. #
  11. import os
  12. import re
  13. import sys
  14. import shutil
  15. import subprocess
  16. import sphinx_rtd_theme
  17. try:
  18. import m2r2
  19. except ModuleNotFoundError:
  20. subprocess.check_call([sys.executable, "-m", "pip", "install", "m2r2"])
  21. try:
  22. import autoapi
  23. except ModuleNotFoundError:
  24. subprocess.check_call([sys.executable, "-m", "pip",
  25. "install", "sphinx-autoapi"])
  26. _base_path = os.path.abspath('..')
  27. BASE_URL = 'https://github.com/kubeedge/sedna/'
  28. sys.path.append(os.path.join(_base_path, "lib"))
  29. sys.path.append(_base_path)
  30. extra_paths = [
  31. os.path.join(_base_path, "examples"),
  32. ]
  33. for p in extra_paths:
  34. dst = os.path.join(
  35. _base_path, "docs",
  36. os.path.basename(p)
  37. )
  38. if os.path.isfile(dst):
  39. os.remove(dst)
  40. elif os.path.isdir(dst):
  41. shutil.rmtree(dst)
  42. if os.path.isdir(p):
  43. shutil.copytree(p, dst)
  44. else:
  45. shutil.copy2(p, dst)
  46. with open(f'{_base_path}/lib/sedna/VERSION', "r", encoding="utf-8") as fh:
  47. __version__ = fh.read().strip()
  48. # -- Project information -----------------------------------------------------
  49. project = 'Sedna'
  50. copyright = '2021, Kubeedge'
  51. author = 'Kubeedge'
  52. version = __version__
  53. release = __version__
  54. # -- General configuration ---------------------------------------------------
  55. # Add any Sphinx extension module names here, as strings. They can be
  56. # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
  57. # ones.
  58. extensions = [
  59. "m2r2",
  60. "sphinx.ext.autodoc",
  61. "sphinx.ext.todo",
  62. "sphinx.ext.coverage",
  63. "sphinx.ext.viewcode",
  64. "autoapi.extension",
  65. "sphinx.ext.intersphinx",
  66. "sphinx.ext.autosummary",
  67. "sphinx.ext.napoleon"
  68. ]
  69. autodoc_inherit_docstrings = False
  70. autodoc_member_order = "bysource"
  71. # If true, `todo` and `todoList` produce output, else they produce nothing.
  72. todo_include_todos = True
  73. # Add any paths that contain templates here, relative to this directory.
  74. # templates_path = ['_templates']
  75. # List of patterns, relative to source directory, that match files and
  76. # directories to ignore when looking for source files.
  77. # This pattern also affects html_static_path and html_extra_path.
  78. exclude_patterns = []
  79. # The master toctree document
  80. master_doc = 'index'
  81. # The name of the Pygments (syntax highlighting) style to use.
  82. pygments_style = 'sphinx'
  83. html_static_path = ['_static']
  84. # -- Options for HTML output -------------------------------------------------
  85. # The theme to use for HTML and HTML Help pages. See the documentation for
  86. # a list of builtin themes.
  87. #
  88. html_theme = 'sphinx_rtd_theme'
  89. html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
  90. html_last_updated_fmt = "%b %d, %Y"
  91. html_theme_options = {
  92. 'prev_next_buttons_location': 'both'
  93. }
  94. # Add any paths that contain custom static files (such as style sheets) here,
  95. # relative to this directory. They are copied after the builtin static files,
  96. # so a file named "default.css" will overwrite the builtin "default.css".
  97. # html_static_path = ['_static']
  98. source_suffix = {
  99. '.rst': 'restructuredtext',
  100. '.txt': 'markdown',
  101. '.md': 'markdown',
  102. }
  103. autoapi_type = "python"
  104. autoapi_dirs = [f"{_base_path}/lib/sedna"]
  105. autoapi_options = [
  106. 'members', 'undoc-members', 'show-inheritance',
  107. 'show-module-summary', 'special-members', 'imported-members'
  108. ]
  109. extlinks = {
  110. "issue": f"{BASE_URL}issues",
  111. "pr": f"{BASE_URL}pull"
  112. }
  113. # hack to replace file link to html link in markdown
  114. def ultimateReplace(app, docname, source):
  115. """
  116. In the rendering with Sphinx, as some file links in markdown
  117. can not be automatically redirected, and 404 response during
  118. access, here define a regular to handle these links.
  119. """
  120. path = app.env.doc2path(docname) # get current path
  121. INLINE_LINK_RE = re.compile(r'\[[^\]]+\]\(([^)]+)\)')
  122. FOOTNOTE_LINK_URL_RE = re.compile(r'\[[^\]]+\](?:\s+)?:(?:\s+)?(\S+)')
  123. if path.endswith('.md'):
  124. new_line = []
  125. docs_url = os.path.join(_base_path, "docs")
  126. for line in source[0].split('\n'):
  127. line = re.sub(
  128. "\[`([^\]]+)`\]\[", "[\g<1>][", line
  129. ) # fix html render error: [`title`]
  130. replace_line = []
  131. prev_start = 0
  132. href_list = (
  133. list(INLINE_LINK_RE.finditer(line)) +
  134. list(FOOTNOTE_LINK_URL_RE.finditer(line))
  135. )
  136. for href in href_list:
  137. pstart = href.start(1)
  138. pstop = href.end(1)
  139. if pstart == -1 or pstop == -1:
  140. continue
  141. link = line[pstart: pstop]
  142. if not link or link.startswith("http"):
  143. continue
  144. if link.startswith("/"):
  145. tmp = _base_path
  146. else:
  147. tmp = os.path.abspath(os.path.dirname(path))
  148. _relpath = os.path.abspath(os.path.join(tmp, link.lstrip("/")))
  149. for sp in extra_paths: # these docs will move into `docs`
  150. sp = os.path.abspath(sp).rstrip("/")
  151. if not _relpath.startswith(sp):
  152. continue
  153. if os.path.isdir(sp):
  154. sp += "/"
  155. _relpath = os.path.join(
  156. docs_url, _relpath[len(_base_path):].lstrip("/")
  157. )
  158. break
  159. if _relpath.startswith(docs_url) and (
  160. os.path.isdir(_relpath) or
  161. os.path.splitext(_relpath)[-1].lower().startswith(
  162. (
  163. ".md", ".rst", ".txt", "html",
  164. ".png", ".jpg", ".jpeg", ".svg", ".gif"
  165. )
  166. )
  167. ):
  168. link = os.path.relpath(_relpath,
  169. os.path.dirname(path))
  170. if not os.path.isdir(_relpath): # suffix edit
  171. link = re.sub(
  172. "(?:\.md|\.rst|\.txt)(\W+\w+)?$",
  173. ".html\g<1>", link
  174. )
  175. else: # redirect to `github`
  176. _relpath = os.path.abspath(
  177. os.path.join(tmp, link.lstrip("/"))
  178. )
  179. _rel_root = os.path.relpath(_relpath, _base_path)
  180. link = f"{BASE_URL}tree/main/{_rel_root}"
  181. p_line = f"{line[prev_start:pstart]}{link}"
  182. prev_start = pstop
  183. replace_line.append(p_line)
  184. replace_line.append(line[prev_start:])
  185. new_line.append("".join(replace_line))
  186. source[0] = "\n".join(new_line)
  187. def setup(app):
  188. app.add_config_value('ultimate_replacements', {}, True)
  189. app.connect('source-read', ultimateReplace)
  190. app.add_css_file('css/custom.css')