|
9 | 9 | if PROJECT_ROOT not in sys.path: |
10 | 10 | sys.path.insert(0, PROJECT_ROOT) |
11 | 11 |
|
| 12 | +# Add src to path for autodoc |
| 13 | +SRC_DIR = os.path.join(PROJECT_ROOT, "src") |
| 14 | +if SRC_DIR not in sys.path: |
| 15 | + sys.path.insert(0, SRC_DIR) |
| 16 | + |
12 | 17 | project = "FastMDAnalysis" |
13 | 18 | copyright = f"{datetime.now():%Y}, Adekunle Aina" |
14 | 19 | author = "Adekunle Aina" |
|
18 | 23 |
|
19 | 24 | extensions = [ |
20 | 25 | "sphinx.ext.autodoc", |
21 | | - "sphinx.ext.autosummary", |
| 26 | + "sphinx.ext.autosummary", |
22 | 27 | "sphinx.ext.napoleon", |
23 | 28 | "sphinx.ext.viewcode", |
24 | 29 | "sphinx.ext.intersphinx", |
|
29 | 34 | "members": True, |
30 | 35 | "undoc-members": False, |
31 | 36 | "show-inheritance": True, |
| 37 | + "special-members": "__init__", |
32 | 38 | } |
33 | 39 |
|
34 | 40 | autodoc_mock_imports = [ |
35 | 41 | "mdtraj", |
36 | | - "numpy", |
| 42 | + "numpy", |
37 | 43 | "matplotlib", |
38 | 44 | "matplotlib.pyplot", |
39 | 45 | "sklearn", |
|
42 | 48 |
|
43 | 49 | intersphinx_mapping = { |
44 | 50 | "python": ("https://docs.python.org/3", {}), |
| 51 | + "numpy": ("https://numpy.org/doc/stable/", None), |
| 52 | + "matplotlib": ("https://matplotlib.org/stable/", None), |
45 | 53 | } |
46 | 54 |
|
47 | 55 | templates_path = ["_templates"] |
|
54 | 62 | "navigation_depth": 4, |
55 | 63 | } |
56 | 64 | primary_domain = "py" |
| 65 | + |
| 66 | +# Auto-generate API documentation on build |
| 67 | +def setup(app): |
| 68 | + from sphinx.ext import apidoc |
| 69 | + |
| 70 | + def run_apidoc(_): |
| 71 | + apidoc_main = getattr(apidoc, 'main', None) |
| 72 | + if apidoc_main is None: |
| 73 | + # Fallback for older Sphinx versions |
| 74 | + from sphinx.ext.apidoc import main as apidoc_main |
| 75 | + |
| 76 | + apidoc_main([ |
| 77 | + '-f', # Force overwrite |
| 78 | + '-e', # Put each module/class on its own page |
| 79 | + '-M', # Put module documentation before submodule |
| 80 | + '-o', |
| 81 | + os.path.join(os.path.dirname(__file__)), # Output to source/ |
| 82 | + os.path.join(PROJECT_ROOT, 'src', 'fastmdanalysis') # Package path |
| 83 | + ]) |
| 84 | + |
| 85 | + app.connect('builder-inited', run_apidoc) |
0 commit comments