| 1 |
import os |
| 2 |
import re |
| 3 |
import sys |
| 4 |
from pathlib import Path |
| 5 |
|
| 6 |
from sphinx.application import Sphinx |
| 7 |
|
| 8 |
sys.path.insert(0, os.path.abspath("..")) |
| 9 |
|
| 10 |
project = "isort" |
| 11 |
copyright = "2013-2026, Timothy Crosley" |
| 12 |
author = "Timothy Crosley" |
| 13 |
|
| 14 |
extensions = [ |
| 15 |
"myst_parser", |
| 16 |
"sphinx_immaterial", |
| 17 |
"sphinx.ext.autodoc", |
| 18 |
"sphinx.ext.intersphinx", |
| 19 |
"sphinx.ext.napoleon", |
| 20 |
"sphinx.ext.viewcode", |
| 21 |
] |
| 22 |
|
| 23 |
html_theme = "sphinx_immaterial" |
| 24 |
html_title = "isort" |
| 25 |
html_static_path = ["../art"] |
| 26 |
html_logo = "../art/logo.png" |
| 27 |
html_favicon = "../art/logo.png" |
| 28 |
|
| 29 |
myst_heading_anchors = 2 |
| 30 |
|
| 31 |
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)} |
| 32 |
# To avoid a lot of errors about problems generating autodoc for the defaults, we ignore them. |
| 33 |
autodoc_preserve_defaults = True |
| 34 |
autodoc_default_options = {"members": True, "show-inheritance": True, "undoc-members": True} |
| 35 |
|
| 36 |
html_theme_options = { |
| 37 |
"site_url": "https://isort.readthedocs.io/", |
| 38 |
"repo_url": "https://github.com/PyCQA/isort/", |
| 39 |
"repo_name": "isort", |
| 40 |
"palette": {"primary": "deep-orange", "accent": "deep-orange"}, |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
def _generate_includes(app: Sphinx) -> None: |
| 45 |
"""Create Sphinx-friendly copies of some files at build time.""" |
| 46 |
# Use absolute paths based on this file's location |
| 47 |
root_dir = Path(__file__).parent.absolute().parent |
| 48 |
gen_dir = Path(__file__).parent.absolute() / "generated" |
| 49 |
gen_dir.mkdir(parents=True, exist_ok=True) |
| 50 |
|
| 51 |
for file in ("CHANGELOG.md", "README.md"): |
| 52 |
content = (root_dir / file).read_text(encoding="utf-8") |
| 53 |
content = re.sub(r"\]\(docs/(.*?)\.md\)", r"](../\1)", content) |
| 54 |
(gen_dir / file).write_text(content, encoding="utf-8") |
| 55 |
|
| 56 |
|
| 57 |
def setup(app: Sphinx) -> None: |
| 58 |
"""Register build hooks.""" |
| 59 |
app.connect("builder-inited", _generate_includes) |