Sphinx: how to exclude import in a car module?

I have a Raspberry Pi project written in Python that uses the RPi.GPIO module. All work on the code is done in a Windows window in which RPi.GPIO will not be installed, and every time I try to run autodoc it crashes, stating that it cannot import RPi.GPIO.

D:\cube\docs\ledcube.rst:4: WARNING: autodoc: failed to import module u'ledcube'
; the following exception was raised:
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\sphinx-1.2b1-py2.7.egg\sphinx\ext\autodoc.
py", line 326, in import_object
    __import__(self.modname)
  File "D:\cube\ledcube.py", line 2, in <module>
    import RPi.GPIO as GPIO
ImportError: No module named RPi.GPIO

How to get around this?

+14
source share
3 answers

There is no way to tell the Sphinx to exclude certain imports. When using autodoc, all documented modules must be purely imported.

, . , , : http://blog.rtwilson.com/how-to-make-your-sphinx-documentation-compile-with-readthedocs-when-youre-using - . ( conf.py):

import mock

MOCK_MODULES = ['numpy', 'matplotlib', 'matplotlib.pyplot']
for mod_name in MOCK_MODULES:
    sys.modules[mod_name] = mock.Mock()

, python-mock, : sudo apt-get install python-mock

1.3, . , autodoc_mock_imports autodoc_mock_imports autodoc_mock_imports.

+21

, , (, read_reg() examplemod, FPGA SPI).

import mox as mox 
import examplemod
m = mox.Mox()
m.StubOutWithMock(examplemod, 'read_reg')

, python-mox: sudo apt-get install python-mox

: sphinx python,

+3

: "import RPi.GPIO" . / (, ). , sphinx .

But the ridicule solution is better, here is the link: http://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_mock_imports

Just add the following line to conf.py (RPi and serial are two examples):

autodoc_mock_imports = ["RPi", 'serial']
0
source

All Articles