Skip to content

Commit 508dc7f

Browse files
authored
Merge pull request python-control#828 from murrayrm/numpydoc-28Dec2022
update docs to use use numpydoc + linkcode
2 parents 49b0077 + ad7ce5f commit 508dc7f

File tree

8 files changed

+96
-21
lines changed

8 files changed

+96
-21
lines changed

control/descfcn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ def describing_function_plot(
236236
given by the first value of the tuple and frequency given by the
237237
second value.
238238
239-
Example
240-
-------
239+
Examples
240+
--------
241241
>>> H_simple = ct.tf([8], [1, 2, 2, 1])
242242
>>> F_saturation = ct.descfcn.saturation_nonlinearity(1)
243243
>>> amp = np.linspace(1, 4, 10)

control/freqplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,8 @@ def nyquist_plot(
589589
if `return_contour` is Tue. To obtain the Nyquist curve values,
590590
evaluate system(s) along contour.
591591
592-
Additional Parameters
593-
---------------------
592+
Other Parameters
593+
----------------
594594
arrows : int or 1D/2D array of floats, optional
595595
Specify the number of arrows to plot on the Nyquist curve. If an
596596
integer is passed. that number of equally spaced arrows will be

control/iosys.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,10 @@ def input_output_response(
16181618
number of states in the system, the initial condition will be padded
16191619
with zeros.
16201620
1621+
t_eval : array-list, optional
1622+
List of times at which the time response should be computed.
1623+
Defaults to ``T``.
1624+
16211625
return_x : bool, optional
16221626
If True, return the state vector when assigning to a tuple (default =
16231627
False). See :func:`forced_response` for more details.
@@ -2725,8 +2729,8 @@ def interconnect(syslist, connections=None, inplist=None, outlist=None,
27252729
generated and if `True` then warnings are always generated.
27262730
27272731
2728-
Example
2729-
-------
2732+
Examples
2733+
--------
27302734
>>> P = control.LinearIOSystem(
27312735
>>> control.rss(2, 2, 2, strictly_proper=True), name='P')
27322736
>>> C = control.LinearIOSystem(control.rss(2, 2, 2), name='C')
@@ -2926,8 +2930,8 @@ def summing_junction(
29262930
Linear input/output system object with no states and only a direct
29272931
term that implements the summing junction.
29282932
2929-
Example
2930-
-------
2933+
Examples
2934+
--------
29312935
>>> P = control.tf2io(ct.tf(1, [1, 0]), inputs='u', outputs='y')
29322936
>>> C = control.tf2io(ct.tf(10, [1, 1]), inputs='e', outputs='u')
29332937
>>> sumblk = control.summing_junction(inputs=['r', '-y'], output='e')

control/lti.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,12 @@ def damp(sys, doprint=True):
304304
poles: array
305305
Pole locations
306306
307-
Algorithm
308-
---------
307+
See Also
308+
--------
309+
pole
310+
311+
Notes
312+
-----
309313
If the system is continuous,
310314
wn = abs(poles)
311315
Z = -real(poles)/poles.
@@ -320,9 +324,6 @@ def damp(sys, doprint=True):
320324
wn = abs(s)
321325
Z = -real(s)/wn.
322326
323-
See Also
324-
--------
325-
pole
326327
"""
327328
wn, damping, poles = sys.damp()
328329
if doprint:

control/sisotool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def rootlocus_pid_designer(plant, gain='P', sign=+1, input_signal='r',
285285
Whether to create Sisotool interactive plot.
286286
287287
Returns
288-
----------
288+
-------
289289
closedloop : class:`StateSpace` system
290290
The closed-loop system using initial gains.
291291

control/statefbk.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ def place(A, B, p):
126126
--------
127127
place_varga, acker
128128
129-
Notes
130-
-----
131-
The return type for 2D arrays depends on the default class set for
132-
state space operations. See :func:`~control.use_numpy_matrix`.
133129
"""
134130
from scipy.signal import place_poles
135131

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ classes.pdf: classes.fig; fig2dev -Lpdf $< $@
2020

2121
# Catch-all target: route all unknown targets to Sphinx using the new
2222
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
23-
html pdf: Makefile $(FIGS)
23+
html pdf clean: Makefile $(FIGS)
2424
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

doc/conf.py

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# -- Project information -----------------------------------------------------
3131

3232
project = u'Python Control Systems Library'
33-
copyright = u'2020, python-control.org'
33+
copyright = u'2022, python-control.org'
3434
author = u'Python Control Developers'
3535

3636
# Version information - read from the source code
@@ -56,7 +56,7 @@
5656
extensions = [
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
]
6161

6262
# scan documents for autosummary directives and generate stub pages for each.
@@ -139,6 +139,80 @@
139139
#
140140
# html_sidebars = {}
141141

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
142216

143217
# -- Options for HTMLHelp output ---------------------------------------------
144218

0 commit comments

Comments
 (0)