8000 Fix dependencies and mocks in sphinx documentation · MorS25/python-control@d563d98 · GitHub
[go: up one dir, main page]

Skip to content

Commit d563d98

Browse files
committed
Fix dependencies and mocks in sphinx documentation
There was an error in the way the sphinx documentation was configured that prevented it from building correctly, now that absolute imports (e.g., "from control import lti") have been changed to relative imports (e.g., "from . import lti"). In particular, the directory "root/control" should not be added to sys.path. Because this directory contains an __init__.py file, it is a Python package, and packages should never be added to the path, or lots of strange things happen, particularly with relative imports. Instead, the directory "root" should be added to the path. This change was made in the conf.py file. Also, the mocks for modules were fixed so that the documentation builds even if numpy, scipy, etc are not installed. Conflicts: doc/conf.py
1 parent 1a470fa commit d563d98

File tree

6 files changed

+64
-28
lines changed

6 files changed

+64
-28
lines changed

doc/class_strings.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ Python-Control Classes
33

44
LTI System Class
55
================
6-
.. automodule:: lti
6+
.. automodule:: control.lti
77
:members:
88

99
State Space Class
1010
=================
11-
.. automodule:: statesp
11+
.. automodule:: control.statesp
1212
:members:
1313

1414
Transfer Function Class
1515
=======================
16-
.. automodule:: xferfcn
16+
.. automodule:: control.xferfcn
1717
:members:
1818

1919
FRD Class
2020
=========
21-
.. automodule:: frdata
21+
.. automodule:: control.frdata
2222
:members:

doc/conf.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,45 @@
1313

1414
import sys, os
1515

16+
# from unittest.mock import MagicMock # python3
17+
from mock import Mock as MagicMock # python2
18+
19+
class Mock(MagicMock):
20+
@classmethod
21+
def __getattr__(cls, name):
22+
return Mock()
23+
24+
MOCK_MODULES = [
25+
'matplotlib',
26+
'matplotlib.mlab',
27+
'matplotlib.pyplot',
28+
'numpy',
29+
'numpy.linalg',
30+
'numpy.linalg.linalg',
31+
'numpy.random',
32+
'numpy.testing',
33+
'pylab',
34+
'scipy',
35+
'scipy.integrate',
36+
'scipy.interpolate',
37+
'scipy.linalg',
38+
'scipy.signal',
39+
'scipy.signal.ltisys',
40+
]
41+
# sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
42+
for mod_name in MOCK_MODULES:
43+
sys.modules[mod_name] = Mock()
44+
if mod_name == 'numpy':
45+
sys.modules['numpy'].pi = 3.14
46+
47+
# disable autosummary code from numpy
48+
# (otherwise, will generate many errors, because autosummary runs twice)
49+
numpydoc_show_class_members = False
50+
1651
# If extensions (or modules to document with autodoc) are in another directory,
1752
# add these directories to sys.path here. If the directory is relative to the
1853
# documentation root, use os.path.abspath to make it absolute, like shown here.
19-
sys.path.insert(0, os.path.abspath('.'))
20-
sys.path.append(os.path.abspath('../src'))
21-
54+
sys.path.insert(0, os.path.abspath('..'))
2255

2356
# -- General configuration -----------------------------------------------------
2457

doc/creation.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ Python-control provides a number of methods for creating LTI control
55
systems.
66

77
.. module:: control
8+
89
========================== ============================================
910
:func:`ss` create state-space (SS) models
1011
:func:`tf` create transfer function (TF) models
1112
========================== ============================================
1213

1314
System creation
1415
================
15-
.. autofunction:: control.StateSpace
16+
.. autoclass:: control.StateSpace
1617
.. autofunction:: control.ss
17-
.. autofunction:: control.TransferFunction
18+
.. autoclass:: control.TransferFunction
1819
.. autofunction:: control.tf
1920

2021
Utility functions and converstions

doc/freqplot.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ Plotting routines
1212

1313
Utility functions
1414
=================
15-
.. autofunction:: freqplot.default_frequency_range
15+
.. autofunction:: control.freqplot.default_frequency_range

doc/matlab_strings.rst

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
MATLAB Compatibility Module
22
****** 2364 *********************
33

4-
.. automodule:: matlab
4+
.. automodule:: control.matlab
55
:members:
66

77
.. todo::
88
The following functions should be documented in their own modules!
99
This is only a temporary solution.
1010

11-
.. autofunction:: pzmap.pzmap
12-
.. autofunction:: freqplot.nyquist
13-
.. autofunction:: nichols.nichols
14-
.. autofunction:: statefbk.place
15-
.. autofunction:: statefbk.lqr
16-
.. autofunction:: statefbk.ctrb
17-
.. autofunction:: statefbk.obsv
18-
.. autofunction:: statefbk.gram
19-
.. autofunction:: delay.pade
20-
.. autofunction:: freqplot.gangof4
21-
.. autofunction:: ctrlutil.unwrap
22-
.. autofunction:: mateqn.lyap
23-
.. autofunction:: mateqn.dlyap
24-
.. autofunction:: mateqn.care
25-
.. autofunction:: mateqn.dare
11+
.. autofunction:: control.pzmap.pzmap
12+
.. autofunction:: control.freqplot.nyquist
13+
.. autofunction:: control.nichols.nichols
14+
.. autofunction:: control.statefbk.place
15+
.. autofunction:: control.statefbk.lqr
16+
.. autofunction:: control.statefbk.ctrb
17+
.. autofunction:: control.statefbk.obsv
18+
.. autofunction:: control.statefbk.gram
19+
.. autofunction:: control.delay.pade
20+
.. autofunction:: control.freqplot.gangof4
21+
.. autofunction:: control.ctrlutil.unwrap
22+
.. autofunction:: control.mateqn.lyap
23+
.. autofunction:: control.mateqn.dlyap
24+
.. autofunction:: control.mateqn.care
25+
.. autofunction:: control.mateqn.dare

doc/timeresp.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Time Domain Simulation
22
**********************
33

4+
.. automodule:: control.timeresp
5+
46
Time responses
57
==============
68
.. autofunction:: control.forced_response
@@ -9,5 +11,5 @@ Time responses
911

1012
Phase portraits
1113
===============
12-
.. autofunction:: phaseplot.phase_plot
13-
.. autofunction:: phaseplot.box_grid
14+
.. autofunction:: control.phaseplot.phase_plot
15+
.. autofunction:: control.phaseplot.box_grid

0 commit comments

Comments
 (0)
0