|
4 | 4 | # list see the documentation: |
5 | 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html |
6 | 6 |
|
7 | | -# -- Path setup -------------------------------------------------------------- |
8 | | - |
9 | | -# If extensions (or modules to document with autodoc) are in another directory, |
10 | | -# add these directories to sys.path here. If the directory is relative to the |
11 | | -# documentation root, use os.path.abspath to make it absolute, like shown here. |
| 7 | +# -- Path setup for importing project paths ------------------------------------ |
| 8 | +# |
| 9 | +# The documentation must be able to import the main project package (tuxemon) |
| 10 | +# for extensions like autodoc and apidoc to work correctly. |
12 | 11 | # |
13 | | -import os |
14 | 12 | import sys |
15 | | -sys.path.append(os.path.abspath("./ext")) |
16 | | -sys.path.insert(0, os.path.abspath('../')) |
| 13 | +from pathlib import Path |
| 14 | +from typing import Any |
17 | 15 |
|
| 16 | +CONF_DIR = Path(__file__).parent.resolve() |
| 17 | +PROJECT_ROOT = CONF_DIR.parent |
| 18 | + |
| 19 | +sys.path.insert(0, str(PROJECT_ROOT)) |
| 20 | +sys.path.append(str(CONF_DIR / "ext")) |
| 21 | +sys.path.append(str(Path(__file__).parent.resolve() / "ext")) |
18 | 22 |
|
19 | 23 | # -- Project information ----------------------------------------------------- |
20 | | -from typing import Any |
21 | 24 |
|
22 | | -project = 'Tuxemon' |
23 | | -copyright = '2015-2025, William Edwards' |
24 | | -author = 'William Edwards' |
| 25 | +project = "Tuxemon" |
| 26 | +copyright = "2015-2025, William Edwards" |
| 27 | +author = "William Edwards" |
25 | 28 |
|
26 | 29 | # The full version, including alpha/beta/rc tags |
27 | | -release = 'alpha' |
| 30 | +# You could potentially get a dynamic version from your project here |
| 31 | +release = "alpha" |
28 | 32 |
|
29 | 33 |
|
30 | 34 | # -- General configuration --------------------------------------------------- |
31 | 35 |
|
32 | | -# Add any Sphinx extension module names here, as strings. They can be |
33 | | -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
34 | | -# ones. |
| 36 | +# Add any Sphinx extension module names here, as strings. |
35 | 37 | extensions = [ |
36 | | - 'sphinx.ext.autodoc', |
37 | | - 'sphinx.ext.todo', |
38 | | - 'sphinx.ext.viewcode', |
39 | | - 'sphinx.ext.githubpages', |
40 | | - 'sphinx.ext.napoleon', |
41 | | - 'script_documenter', |
| 38 | + "sphinx.ext.autodoc", |
| 39 | + "sphinx.ext.todo", |
| 40 | + "sphinx.ext.viewcode", |
| 41 | + "sphinx.ext.githubpages", |
| 42 | + "sphinx.ext.napoleon", |
| 43 | + "script_documenter", |
42 | 44 | ] |
43 | 45 |
|
44 | 46 | # Add any paths that contain templates here, relative to this directory. |
45 | | -templates_path = ['_templates'] |
| 47 | +templates_path = ["_templates"] |
46 | 48 |
|
47 | 49 | # List of patterns, relative to source directory, that match files and |
48 | 50 | # directories to ignore when looking for source files. |
49 | | -# This pattern also affects html_static_path and html_extra_path. |
50 | | -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] |
| 51 | +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "autogen"] |
51 | 52 |
|
52 | 53 |
|
53 | | -# -- Options for HTML output ---------------------------------------------- |
| 54 | +# -- Options for HTML output ------------------------------------------------- |
54 | 55 |
|
55 | | -# The theme to use for HTML and HTML Help pages. See the documentation for |
56 | | -# a list of builtin themes. |
57 | | -# |
58 | | -html_theme = 'sphinx_rtd_theme' |
| 56 | +# The theme to use for HTML and HTML Help pages. |
| 57 | +html_theme = "sphinx_rtd_theme" |
59 | 58 |
|
60 | | -# Add any paths that contain custom static files (such as style sheets) here, |
61 | | -# relative to this directory. They are copied after the builtin static files, |
62 | | -# so a file named "default.css" will overwrite the builtin "default.css". |
63 | | -html_static_path = ['_static'] |
| 59 | +# Add any paths that contain custom static files (such as style sheets) here. |
| 60 | +html_static_path = ["_static"] |
64 | 61 |
|
| 62 | + |
| 63 | +# -- Options for Autodoc and Napoleon ---------------------------------------- |
| 64 | + |
| 65 | +# Tell Autodoc how to display type hints |
65 | 66 | autodoc_typehints = "description" |
66 | 67 |
|
| 68 | +# Disable NumPy docstring parsing if you primarily use Google-style docstrings |
67 | 69 | napoleon_numpy_docstring = False |
68 | 70 |
|
| 71 | +# Define your custom Napoleon sections |
69 | 72 | napoleon_custom_sections = [ |
70 | 73 | "Script usage", |
71 | | - ("Script parameters", "params_style") |
| 74 | + ("Script parameters", "params_style"), |
72 | 75 | ] |
73 | 76 |
|
74 | 77 |
|
75 | | -# Apidoc call to generate automatic reference docs. Taken from |
76 | | -# https://github.com/readthedocs/readthedocs.org/issues/1139#issuecomment-398083449 |
| 78 | +# -- Apidoc Automation ------------------------------------------------------- |
| 79 | + |
| 80 | + |
77 | 81 | def run_apidoc(_: Any) -> None: |
| 82 | + """ |
| 83 | + Automatically runs sphinx-apidoc before the Sphinx build process begins. |
| 84 | + This generates API reference files for all your project's modules. |
| 85 | + """ |
78 | 86 | ignore_paths: list[str] = [] |
79 | 87 |
|
80 | 88 | argv = [ |
81 | | - "-f", |
82 | | - "-e", |
83 | | - "-M", |
84 | | - "-o", |
85 | | - "autogen", |
86 | | - ".." |
| 89 | + "-f", # Force overwrite output files |
| 90 | + "-e", # Put documentation for each module on its own page |
| 91 | + "-M", # Look for module files instead of package files |
| 92 | + "-o", # Output directory |
| 93 | + "autogen", # Name of the directory to store the generated files |
| 94 | + str(PROJECT_ROOT), # Use the repo root so apidoc scans everything |
87 | 95 | ] + ignore_paths |
88 | 96 |
|
89 | | - # Sphinx 1.7+ |
90 | 97 | from sphinx.ext import apidoc |
| 98 | + |
91 | 99 | apidoc.main(argv) |
92 | 100 |
|
93 | 101 |
|
94 | 102 | def setup(app: Any) -> None: |
95 | | - app.connect('builder-inited', run_apidoc) |
| 103 | + """Connect the run_apidoc function to the 'builder-inited' Sphinx event.""" |
| 104 | + app.connect("builder-inited", run_apidoc) |
0 commit comments