|
9 | 9 | # import sys |
10 | 10 | # sys.path.insert(0, os.path.abspath("../sphedron")) # Adjust path to your package |
11 | 11 |
|
12 | | -import os |
13 | | -import sys |
14 | | -sys.path.insert(0, os.path.abspath('../../sphedron/')) |
15 | | -print("PATH:",os.path.abspath('../../sphedron/')) |
| 12 | +# import os |
| 13 | +# import sys |
| 14 | +# sys.path.insert(0, os.path.abspath('../../sphedron/')) |
| 15 | +# print("PATH:",os.path.abspath('../../sphedron/')) |
| 16 | + |
| 17 | +import sphedron |
| 18 | +import inspect |
| 19 | +import importlib |
16 | 20 |
|
17 | 21 | project = "Sphedron" |
18 | 22 | author = "Ayoub Ghriss" |
19 | | -# copyright = "2025, Ayoub Ghriss" |
| 23 | +copyright = "2025, Ayoub Ghriss" |
| 24 | + |
| 25 | +# add_module_names = False |
| 26 | +# typehints_fully_qualified = False # sphinx-autodoc-typehints >= 2.0 |
| 27 | + |
20 | 28 |
|
21 | 29 | # -- General configuration --------------------------------------------------- |
22 | 30 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration |
|
29 | 37 |
|
30 | 38 | extensions = [ |
31 | 39 | "sphinx.ext.autodoc", |
32 | | - "sphinx.ext.napoleon", # Parses Google/NumPy docstrings |
33 | | - "sphinx.ext.viewcode", |
34 | 40 | "sphinx.ext.autosummary", |
| 41 | + "sphinx.ext.intersphinx", |
35 | 42 | "sphinx.ext.mathjax", |
| 43 | + "sphinx.ext.napoleon", |
| 44 | + "sphinx.ext.viewcode", |
| 45 | + # 'sphinx_autodoc_typehints', |
| 46 | + # 'sphinx_copybutton', |
| 47 | + # 'nbsphinx', |
| 48 | + # 'pyg', |
36 | 49 | ] |
| 50 | + |
37 | 51 | autosummary_generate = True |
| 52 | +autosummary_generate_overwrite = True |
38 | 53 | html_theme = "sphinx_rtd_theme" |
39 | 54 | napoleon_google_docstring = True # Enable Google docstring parsing |
40 | | -napoleon_numpy_docstring = False # Disable NumPy docstrings |
| 55 | +napoleon_numpy_docstring = True # Disable NumPy docstrings |
| 56 | +# suppress_warnings = ["autodoc.import_object"] |
| 57 | +# autodoc_default_flags = { |
| 58 | +# # "members": True, |
| 59 | +# # "show-inheritance": True, |
| 60 | +# "member-order": "groupwise", # groups methods vs attributes/properties |
| 61 | +# # "undoc-members": False, |
| 62 | +# "private-members": False, |
| 63 | +# } |
| 64 | + |
41 | 65 |
|
42 | 66 | templates_path = ["_templates"] |
43 | 67 | exclude_patterns = ["build", "Thumbs.db", ".DS_Store", "tests/*"] |
44 | | -# html_static_path = ["_static"] |
| 68 | +html_static_path = ["_static"] |
| 69 | + |
| 70 | + |
| 71 | +def rst_jinja_render(app, _, source): |
| 72 | + if hasattr(app.builder, "templates"): |
| 73 | + rst_context = {"sphedron": sphedron} |
| 74 | + source[0] = app.builder.templates.render_string(source[0], rst_context) |
| 75 | + |
| 76 | + |
| 77 | +def autodoc_skip_member(app, what, name, obj, skip, options): |
| 78 | + # print(name) |
| 79 | + # if name in {"__init__", "__call__"}: |
| 80 | + # return False |
| 81 | + # Skip single-underscore private and non-magic double-underscore |
| 82 | + if name.startswith("_") and not ( |
| 83 | + name.startswith("__") and name.endswith("__") |
| 84 | + ): |
| 85 | + return True |
| 86 | + return skip |
| 87 | + |
| 88 | + # def setup(app): |
| 89 | + # app.connect("source-read", rst_jinja_render) |
| 90 | + # app.connect("autodoc-skip-member", autodoc_skip_member) |
| 91 | + # app.connect("autodoc-skip-attribute", autodoc_skip_member) |
| 92 | + |
| 93 | + # app.add_js_file('js/version_alert.js') |
| 94 | + |
| 95 | + # Do not drop type hints in signatures: |
| 96 | + # del app.events.listeners["autodoc-process-signature"] |
| 97 | + |
| 98 | + # conf.py |
| 99 | + # def _split_methods(fullname, names): |
| 100 | + # import importlib, inspect |
| 101 | + # mod, clsname = fullname.rsplit(".", 1) |
| 102 | + # cls = getattr(importlib.import_module(mod), clsname) |
| 103 | + # out = {"classmethods": [], "staticmethods": [], "instancemethods": []} |
| 104 | + # for n in names: |
| 105 | + # try: |
| 106 | + # attr = inspect.getattr_static(cls, n) |
| 107 | + # except Exception: |
| 108 | + # continue |
| 109 | + # if isinstance(attr, classmethod): |
| 110 | + # out["classmethods"].append(n) |
| 111 | + # elif isinstance(attr, staticmethod): |
| 112 | + # out["staticmethods"].append(n) |
| 113 | + # elif inspect.isfunction(attr): |
| 114 | + # out["instancemethods"].append(n) |
| 115 | + # return out |
| 116 | + |
| 117 | + # def _split_attributes(fullname, names): |
| 118 | + # import importlib, inspect |
| 119 | + # mod, clsname = fullname.rsplit(".", 1) |
| 120 | + # cls = getattr(importlib.import_module(mod), clsname) |
| 121 | + # props, data = [], [] |
| 122 | + # for n in names: |
| 123 | + # try: |
| 124 | + # attr = inspect.getattr_static(cls, n) |
| 125 | + # except Exception: |
| 126 | + # continue |
| 127 | + # (props if isinstance(attr, property) else data).append(n) |
| 128 | + # return {"properties": props, "data": data} |
| 129 | + |
| 130 | + # def _register_filters(app): |
| 131 | + # env = app.builder.templates.environment # official way to extend template env |
| 132 | + # env.filters["split_methods"] = _split_methods |
| 133 | + # env.filters["split_attributes"] = _split_attributes |
| 134 | + |
| 135 | + # def setup(app): |
| 136 | + # app.connect("builder-inited", _register_filters) # recommended event |
| 137 | + |
| 138 | + |
| 139 | +def classify(names, fullname): |
| 140 | + """Split member names into properties vs data, and instance/class/static methods.""" |
| 141 | + from sphinx.util import logging |
| 142 | + |
| 143 | + log = logging.getLogger(__name__) |
| 144 | + mod, clsname = fullname.rsplit(".", 1) |
| 145 | + log.warning(f"Classify print: {fullname, names, mod, clsname}") |
| 146 | + cls = getattr(importlib.import_module(mod), clsname) |
| 147 | + |
| 148 | + props, data = [], [] |
| 149 | + inst_meths, cls_meths, static_meths = [], [], [] |
| 150 | + |
| 151 | + for n in names or []: |
| 152 | + try: |
| 153 | + a = inspect.getattr_static(cls, n) |
| 154 | + except Exception: |
| 155 | + continue |
| 156 | + if isinstance(a, property): |
| 157 | + props.append(n) |
| 158 | + elif isinstance(a, classmethod): |
| 159 | + cls_meths.append(n) |
| 160 | + elif isinstance(a, staticmethod): |
| 161 | + static_meths.append(n) |
| 162 | + elif inspect.isfunction(a): |
| 163 | + inst_meths.append(n) |
| 164 | + else: |
| 165 | + data.append(n) |
| 166 | + |
| 167 | + return { |
| 168 | + "properties": props, |
| 169 | + "data": data, |
| 170 | + "methods": inst_meths, |
| 171 | + "classmethods": cls_meths, |
| 172 | + "staticmethods": static_meths, |
| 173 | + } |
| 174 | + |
| 175 | + |
| 176 | +def _register_filters(app): |
| 177 | + env = app.builder.templates.environment |
| 178 | + env.filters["classify"] = classify |
| 179 | + |
| 180 | + |
| 181 | +def setup(app): |
| 182 | + app.connect("builder-inited", _register_filters) |
| 183 | + app.connect("source-read", rst_jinja_render) |
| 184 | + app.connect("autodoc-skip-member", autodoc_skip_member) |
0 commit comments