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 5.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 = '2020, 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
  114. def ultimateReplace(app, docname, source):
  115. path = app.env.doc2path(docname)
  116. _match = re.compile("\(/([^/]+)/([^)]+)\)")
  117. if path.endswith('.md'):
  118. new_line = []
  119. for line in source[0].split('\n'):
  120. error_link = _match.search(line)
  121. if error_link:
  122. _path, _detail = error_link.groups()
  123. if _path in ("docs", "examples") and ".md" in _detail.lower():
  124. tmp = os.path.join(_base_path, "docs")
  125. tmp2 = os.path.abspath(os.path.dirname(path))
  126. _relpath = os.path.relpath(tmp, tmp2).strip("/")
  127. line = line.replace("/docs/", f"{_relpath}/")
  128. line = line.replace("/examples/", f"{_relpath}/examples/")
  129. else:
  130. line = line.replace(f"/{_path}/",
  131. f"{BASE_URL}tree/main/{_path}/")
  132. line = re.sub(
  133. "\((?!http)([^\)]+)\.md([^\)]+)?\)",
  134. "(\g<1>.html\g<2>)", line
  135. )
  136. new_line.append(line)
  137. source[0] = "\n".join(new_line)
  138. def setup(app):
  139. app.add_config_value('ultimate_replacements', {}, True)
  140. app.connect('source-read', ultimateReplace)
  141. app.add_css_file('css/custom.css')