|
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 |
| 15 | +from tuxemon.constants.paths import LIBDIR |
17 | 16 |
|
| 17 | +CONF_DIR = Path(__file__).parent.resolve() |
| 18 | +PROJECT_ROOT = CONF_DIR.parent |
| 19 | + |
| 20 | +sys.path.insert(0, str(PROJECT_ROOT)) |
| 21 | +sys.path.append(str(CONF_DIR / "ext")) |
| 22 | +sys.path.append(str(Path(__file__).parent.resolve() / "ext")) |
18 | 23 |
|
19 | 24 | # -- Project information ----------------------------------------------------- |
20 | | -from typing import Any |
21 | 25 |
|
22 | 26 | project = 'Tuxemon' |
23 | 27 | copyright = '2015-2025, William Edwards' |
24 | 28 | author = 'William Edwards' |
25 | 29 |
|
26 | 30 | # The full version, including alpha/beta/rc tags |
| 31 | +# You could potentially get a dynamic version from your project here |
27 | 32 | release = 'alpha' |
28 | 33 |
|
29 | 34 |
|
30 | 35 | # -- General configuration --------------------------------------------------- |
31 | 36 |
|
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. |
| 37 | +# Add any Sphinx extension module names here, as strings. |
35 | 38 | extensions = [ |
36 | 39 | 'sphinx.ext.autodoc', |
37 | 40 | 'sphinx.ext.todo', |
38 | 41 | 'sphinx.ext.viewcode', |
39 | 42 | 'sphinx.ext.githubpages', |
40 | 43 | 'sphinx.ext.napoleon', |
41 | | - 'script_documenter', |
| 44 | + 'script_documenter', |
42 | 45 | ] |
43 | 46 |
|
44 | 47 | # Add any paths that contain templates here, relative to this directory. |
45 | 48 | templates_path = ['_templates'] |
46 | 49 |
|
47 | 50 | # List of patterns, relative to source directory, that match files and |
48 | 51 | # 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'] |
| 52 | +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'autogen'] |
51 | 53 |
|
52 | 54 |
|
53 | | -# -- Options for HTML output ---------------------------------------------- |
| 55 | +# -- Options for HTML output ------------------------------------------------- |
54 | 56 |
|
55 | | -# The theme to use for HTML and HTML Help pages. See the documentation for |
56 | | -# a list of builtin themes. |
57 | | -# |
| 57 | +# The theme to use for HTML and HTML Help pages. |
58 | 58 | html_theme = 'sphinx_rtd_theme' |
59 | 59 |
|
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". |
| 60 | +# Add any paths that contain custom static files (such as style sheets) here. |
63 | 61 | html_static_path = ['_static'] |
64 | 62 |
|
| 63 | + |
| 64 | +# -- Options for Autodoc and Napoleon ---------------------------------------- |
| 65 | + |
| 66 | +# Tell Autodoc how to display type hints |
65 | 67 | autodoc_typehints = "description" |
66 | 68 |
|
| 69 | +# Disable NumPy docstring parsing if you primarily use Google-style docstrings |
67 | 70 | napoleon_numpy_docstring = False |
68 | 71 |
|
| 72 | +# Define your custom Napoleon sections |
69 | 73 | napoleon_custom_sections = [ |
70 | 74 | "Script usage", |
71 | 75 | ("Script parameters", "params_style") |
72 | 76 | ] |
73 | 77 |
|
74 | 78 |
|
75 | | -# Apidoc call to generate automatic reference docs. Taken from |
76 | | -# https://github.com/readthedocs/readthedocs.org/issues/1139#issuecomment-398083449 |
| 79 | +# -- Apidoc Automation ------------------------------------------------------- |
| 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 |
91 | 98 | apidoc.main(argv) |
92 | 99 |
|
93 | 100 |
|
94 | 101 | def setup(app: Any) -> None: |
| 102 | + """Connect the run_apidoc function to the 'builder-inited' Sphinx event.""" |
95 | 103 | app.connect('builder-inited', run_apidoc) |
0 commit comments