|
30 | 30 | # -- Project information ----------------------------------------------------- |
31 | 31 |
|
32 | 32 | project = u'Python Control Systems Library' |
33 | | -copyright = u'2020, python-control.org' |
| 33 | +copyright = u'2022, python-control.org' |
34 | 34 | author = u'Python Control Developers' |
35 | 35 |
|
36 | 36 | # Version information - read from the source code |
|
56 | 56 | extensions = [ |
57 | 57 | 'sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.napoleon', |
58 | 58 | 'sphinx.ext.intersphinx', 'sphinx.ext.imgmath', |
59 | | - 'sphinx.ext.autosummary', 'nbsphinx', |
| 59 | + 'sphinx.ext.autosummary', 'nbsphinx', 'numpydoc', 'sphinx.ext.linkcode' |
60 | 60 | ] |
61 | 61 |
|
62 | 62 | # scan documents for autosummary directives and generate stub pages for each. |
|
139 | 139 | # |
140 | 140 | # html_sidebars = {} |
141 | 141 |
|
| 142 | +# ----------------------------------------------------------------------------- |
| 143 | +# Source code links (from numpy) |
| 144 | +# ----------------------------------------------------------------------------- |
| 145 | + |
| 146 | +import inspect |
| 147 | +from os.path import relpath, dirname |
| 148 | + |
| 149 | +def linkcode_resolve(domain, info): |
| 150 | + """ |
| 151 | + Determine the URL corresponding to Python object |
| 152 | + """ |
| 153 | + if domain != 'py': |
| 154 | + return None |
| 155 | + |
| 156 | + modname = info['module'] |
| 157 | + fullname = info['fullname'] |
| 158 | + |
| 159 | + submod = sys.modules.get(modname) |
| 160 | + if submod is None: |
| 161 | + return None |
| 162 | + |
| 163 | + obj = submod |
| 164 | + for part in fullname.split('.'): |
| 165 | + try: |
| 166 | + obj = getattr(obj, part) |
| 167 | + except Exception: |
| 168 | + return None |
| 169 | + |
| 170 | + # strip decorators, which would resolve to the source of the decorator |
| 171 | + # possibly an upstream bug in getsourcefile, bpo-1764286 |
| 172 | + try: |
| 173 | + unwrap = inspect.unwrap |
| 174 | + except AttributeError: |
| 175 | + pass |
| 176 | + else: |
| 177 | + obj = unwrap(obj) |
| 178 | + |
| 179 | + # Get the filename for the function |
| 180 | + try: |
| 181 | + fn = inspect.getsourcefile(obj) |
| 182 | + except Exception: |
| 183 | + fn = None |
| 184 | + if not fn: |
| 185 | + return None |
| 186 | + |
| 187 | + # Ignore re-exports as their source files are not within the numpy repo |
| 188 | + module = inspect.getmodule(obj) |
| 189 | + if module is not None and not module.__name__.startswith("control"): |
| 190 | + return None |
| 191 | + |
| 192 | + try: |
| 193 | + source, lineno = inspect.getsourcelines(obj) |
| 194 | + except Exception: |
| 195 | + lineno = None |
| 196 | + |
| 197 | + fn = relpath(fn, start=dirname(control.__file__)) |
| 198 | + |
| 199 | + if lineno: |
| 200 | + linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1) |
| 201 | + else: |
| 202 | + linespec = "" |
| 203 | + |
| 204 | + base_url = "https://github.com/python-control/python-control/blob/" |
| 205 | + if 'dev' in control.__version__ or 'post' in control.__version__: |
| 206 | + return base_url + "main/control/%s%s" % (fn, linespec) |
| 207 | + else: |
| 208 | + return base_url + "%s/control/%s%s" % ( |
| 209 | + control.__version__, fn, linespec) |
| 210 | + |
| 211 | +# Don't automaticall show all members of class in Methods & Attributes section |
| 212 | +numpydoc_show_class_members = False |
| 213 | + |
| 214 | +# Don't create a Sphinx TOC for the lists of class methods and attributes |
| 215 | +numpydoc_class_members_toctree = False |
142 | 216 |
|
143 | 217 | # -- Options for HTMLHelp output --------------------------------------------- |
144 | 218 |
|
|
0 commit comments