conf.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. import os
  11. import subprocess
  12. import sys
  13. from sphinx.ext import autodoc
  14. from docutils import nodes
  15. from docutils.parsers.rst import Directive
  16. def install(package):
  17. subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
  18. requirements_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'requirements.txt'))
  19. if os.path.exists(requirements_path):
  20. with open(requirements_path) as f:
  21. packages = f.readlines()
  22. for package in packages:
  23. install(package.strip())
  24. sys.path.insert(0, os.path.abspath('../..'))
  25. # -- Project information -----------------------------------------------------
  26. project = 'MinerU'
  27. copyright = '2024, MinerU Contributors'
  28. author = 'OpenDataLab'
  29. # The full version, including alpha/beta/rc tags
  30. version_file = '../../magic_pdf/libs/version.py'
  31. with open(version_file) as f:
  32. exec(compile(f.read(), version_file, 'exec'))
  33. __version__ = locals()['__version__']
  34. # The short X.Y version
  35. version = __version__
  36. # The full version, including alpha/beta/rc tags
  37. release = __version__
  38. # -- General configuration ---------------------------------------------------
  39. # Add any Sphinx extension module names here, as strings. They can be
  40. # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
  41. # ones.
  42. extensions = [
  43. 'sphinx.ext.napoleon',
  44. 'sphinx.ext.viewcode',
  45. 'sphinx.ext.intersphinx',
  46. 'sphinx_copybutton',
  47. 'sphinx.ext.autodoc',
  48. 'sphinx.ext.autosummary',
  49. 'sphinx.ext.inheritance_diagram',
  50. 'myst_parser',
  51. 'sphinxarg.ext',
  52. 'sphinxcontrib.autodoc_pydantic',
  53. ]
  54. # class hierarchy diagram
  55. inheritance_graph_attrs = dict(rankdir="LR", size='"8.0, 12.0"', fontsize=14, ratio='compress')
  56. inheritance_node_attrs = dict(shape='ellipse', fontsize=14, height=0.75)
  57. inheritance_edge_attrs = dict(arrow='vee')
  58. autodoc_pydantic_model_show_json = True
  59. autodoc_pydantic_model_show_config_summary = False
  60. # Add any paths that contain templates here, relative to this directory.
  61. templates_path = ['_templates']
  62. # List of patterns, relative to source directory, that match files and
  63. # directories to ignore when looking for source files.
  64. # This pattern also affects html_static_path and html_extra_path.
  65. exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
  66. # Exclude the prompt "$" when copying code
  67. copybutton_prompt_text = r'\$ '
  68. copybutton_prompt_is_regexp = True
  69. language = 'en'
  70. # -- Options for HTML output -------------------------------------------------
  71. # The theme to use for HTML and HTML Help pages. See the documentation for
  72. # a list of builtin themes.
  73. #
  74. html_theme = 'sphinx_book_theme'
  75. html_logo = '_static/image/logo.png'
  76. html_theme_options = {
  77. 'path_to_docs': 'docs/en',
  78. 'repository_url': 'https://github.com/opendatalab/MinerU',
  79. 'use_repository_button': True,
  80. }
  81. # Add any paths that contain custom static files (such as style sheets) here,
  82. # relative to this directory. They are copied after the builtin static files,
  83. # so a file named "default.css" will overwrite the builtin "default.css".
  84. # html_static_path = ['_static']
  85. # Mock out external dependencies here.
  86. autodoc_mock_imports = [
  87. 'cpuinfo',
  88. 'torch',
  89. 'transformers',
  90. 'psutil',
  91. 'prometheus_client',
  92. 'sentencepiece',
  93. 'vllm.cuda_utils',
  94. 'vllm._C',
  95. 'numpy',
  96. 'tqdm',
  97. ]
  98. class MockedClassDocumenter(autodoc.ClassDocumenter):
  99. """Remove note about base class when a class is derived from object."""
  100. def add_line(self, line: str, source: str, *lineno: int) -> None:
  101. if line == ' Bases: :py:class:`object`':
  102. return
  103. super().add_line(line, source, *lineno)
  104. autodoc.ClassDocumenter = MockedClassDocumenter
  105. navigation_with_keys = False
  106. # add custom directive
  107. class VideoDirective(Directive):
  108. required_arguments = 1
  109. optional_arguments = 0
  110. final_argument_whitespace = True
  111. option_spec = {}
  112. def run(self):
  113. url = self.arguments[0]
  114. video_node = nodes.raw('', f'<iframe width="560" height="315" src="{url}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>', format='html')
  115. return [video_node]
  116. def setup(app):
  117. app.add_directive('video', VideoDirective)