0

I'm working in a project involving the Raspberry Pi and the PiFace interface module. The project is being developed in Python and I have run into a problem when trying to auto document some modules with Sphinx. We are using the pifacedigitalio library, however, even though I have installed said library on the development machine, Sphinx refuses to document the module and complains that it's throwing exceptions due to hardware not being present. The hardware isn't present because this is the development machine. For testing the software, we just use a conditional if hwpresent then skip but I actually want to document those parts through Sphinx. The error produced when doing make html is:

/home/user/current/working/docs/src.rst:10: WARNING: autodoc: failed to import module u'src.billete'; the following exception was raised:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 335, in     import_object
__import__(self.modname)
File "/home/user/current/working/src/bill.py", line 4, in  <module>
piface_obj = piface.PiFaceDigital()
  File "/usr/local/lib/python2.7/dist-packages/pifacedigitalio/core.py", line 82, in __init__
self.init_board()
  File "/usr/local/lib/python2.7/dist-packages/pifacedigitalio/core.py", line 107, in init_board
h=self.hardware_addr, b=self.bus, c=self.chip_select))
NoPiFaceDigitalDetectedError: No PiFace Digital board detected (hardware_addr=0, bus=0, chip_select=0).

Is there a way to avoid Sphinx from interpreting the code and just parse the source? I tried to modify pifacedigitalio/core.py by hand using dummy returns but Sphinx just freezes then.

mzjn
  • 48,958
  • 13
  • 128
  • 248
ctroncoso
  • 1
  • 2

1 Answers1

0

You have to put a directory in your PYTHONPATH that has Mock's of those modules before you run Sphinx. Check out their Doc's, but be warned that you shouldn't be screwing around with sys.modules yourself like they do in the example. Use mock.patch instead.

ErlVolton
  • 6,714
  • 2
  • 15
  • 26
  • I will try this later, however I'm afraid that Sphinx will just freeze, since I tried something very blunt but similar, editing directly the module files. EDIT: mock.patch looks really interesting. Will try and report. – ctroncoso Oct 15 '14 at 22:44
  • We have exactly the same problem on one of our projects. We found it easier to make a git repository with Mock modules and append it to our path instead of doing patches in conf.py However, both approaches definitely work, I promise :) – ErlVolton Oct 15 '14 at 22:45