Merge pull request #828 from murrayrm/numpydoc-28Dec2022 · python-control/python-control@508dc7f
@@ -30,7 +30,7 @@
3030# -- Project information -----------------------------------------------------
31313232project = u'Python Control Systems Library'
33-copyright = u'2020, python-control.org'
33+copyright = u'2022, python-control.org'
3434author = u'Python Control Developers'
35353636# Version information - read from the source code
@@ -56,7 +56,7 @@
5656extensions = [
5757'sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.napoleon',
5858'sphinx.ext.intersphinx', 'sphinx.ext.imgmath',
59-'sphinx.ext.autosummary', 'nbsphinx',
59+'sphinx.ext.autosummary', 'nbsphinx', 'numpydoc', 'sphinx.ext.linkcode'
6060]
61616262# scan documents for autosummary directives and generate stub pages for each.
139139#
140140# html_sidebars = {}
141141142+# -----------------------------------------------------------------------------
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
142216143217# -- Options for HTMLHelp output ---------------------------------------------
144218