Files
primitive-type/docs/source/conf.py
2026-02-10 12:55:16 +08:00

141 lines
4.7 KiB
Python

# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Import Python modules ---------------------------------------------------
import datetime
import os
import sys
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from sphinx.application import Sphinx
sys.path.insert(0, os.path.abspath(os.path.join("..", "..")))
import primitive_type
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
project = "primitive-type"
copyright = f"{datetime.datetime.now().year}, CleMooling"
author = "CleMooling"
release = primitive_type.__version__
# -- General configuration ---------------------------------------------------
# https://docs.readthedocs.com/platform/stable/reference/environment-variables.html#envvar-READTHEDOCS
RTD: bool = os.environ.get("READTHEDOCS", "").lower() == "true"
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosectionlabel",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
"sphinx_copybutton",
"sphinx_prompt",
"sphinxcontrib.jquery",
"sphinx_inline_tabs",
"sphinxcontrib.mermaid",
"sphinx_design",
"sphinxcontrib.asciinema",
]
source_suffix = [".rst"]
templates_path = ["_templates"]
exclude_patterns = ["build", "Thumbs.db", ".DS_Store"]
# def setup(app: 'Sphinx'):
# from typing import List
# from sphinx_prompt import PromptDirective
# class PromptWithVersion(PromptDirective):
# content: List[str]
# def run(self):
# self.assert_has_content()
# for i in range(len(self.content)):
# self.content[i] = self.content[i].replace('@@VERSION@@', release)
# return super().run()
# app.add_directive('prompt-version', PromptWithVersion)
# autodoc_setup(app)
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = "sphinx_rtd_theme"
html_static_path = ["../static"]
html_search_language = "en"
html_css_files = [
# Save the table width
# override wide tables in RTD theme
# https://rackerlabs.github.io/docs-rackspace/tools/rtd-tables.html
"css/theme_overrides.css",
# Tweak styles of the sphinx_inline_tabs extension
"css/codeblock_tab.css",
# Tweak styles of the readthedocs addons
# https://docs.readthedocs.io/en/stable/addons.html
"css/rtd_addon.css",
]
html_js_files = [
("https://cdn.jsdelivr.net/npm/@docsearch/js@3", {"defer": "defer"}),
("js/readthedoc-flyout.js", {"defer": "defer"}),
]
# Show a deeper toctree in the sidebar
# https://stackoverflow.com/questions/27669376/show-entire-toctree-in-read-the-docs-sidebar
html_theme_options = {
"navigation_depth": 6,
"logo_only": True,
}
# html_logo = ''
# -- Options for sphinx-intl -------------------------------------------------
# available languages: en_US, zh_CN
language: str = os.environ.get("READTHEDOCS_LANGUAGE", "en_US")
# po files will be created in this directory
# path is example but recommended.
locale_dirs = ["locales"]
gettext_compact = False # optional
# -- Options for sphinx.ext.autodoc -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html
autodoc_member_order = "bysource"
autodoc_inherit_docstrings = False # so overridden methods won't pop up
add_module_names = False
# -- Options for sphinx.ext.autosectionlabel -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/extensions/autosectionlabel.html
autosectionlabel_prefix_document = True
# -- Options for sphinx.ext.intersphinx -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html
intersphinx_mapping = {
# curl https://docs.python.org/3/objects.inv -o python3-objects.inv
"python": (
"https://docs.python.org/3",
None if RTD else (None, "./python3-objects.inv"),
), # always fetch from internet in rtd env
}
# disable all auto external document references
# implicit ref for general std domain is bad
intersphinx_disabled_reftypes = ["std:*"]
intersphinx_timeout = 30
def autodoc_setup(app: "Sphinx"):
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#event-autodoc-skip-member
def autodoc_skip_member_handler(app_, what, name, obj, skip, options):
return skip
app.connect("autodoc-skip-member", autodoc_skip_member_handler)