Hi all,
I’m experimenting with setting up Sphinx to create documentation, and this works fine until I try to use it on modules that import pymel.core.
Line in module:
import pymel.core as pmc
Error when running “make html” in sphinx directory:
C:\mayalib\Doc\index.rst:17: WARNING: autodoc: failed to import module u'test'; the following exception was raised:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\sphinx\ext\autodoc.py", line 335, in import_object
__import__(self.modname)
File "C:\mayalib\pylib est.py", line 1, in <module>
import pymel.core as pmc
ImportError: No module named pymel.core
(and then no documentation for the module is generated)
I’ve experimented with Rob Galanakis’ solution from here
i.e. added
import mock
for mod in ['maya.cmds', 'pymel.core']:
sys.modules[mod] = mock.MagicMock()
in the conf.py file for sphinx, right below the import statements, but no go. Tested mock in vanilla python interpreter, works fine.
Google didn’t turn up any other ideas, and I’m kind of out of options. Does anyone know how to make this work?
This happens because pymel isn’t available to the system installation of Python. If you look inside of the build script for Sphinx, you’ll notice that it calls “python” to build and locate libraries. If you modify this to instead use “mayapy” (or the full path thereof) it should work better.
[QUOTE=marcuso;26608]This happens because pymel isn’t available to the system installation of Python. If you look inside of the build script for Sphinx, you’ll notice that it calls “python” to build and locate libraries. If you modify this to instead use “mayapy” (or the full path thereof) it should work better.[/QUOTE]
Thanks for the reply! Where do I find an editable version of the build script? I did look in C:\Python27\Scripts, but the sphinx-build.exe there is compiled so I can’t change it.
I actually figured out last night how to do this with mock. All I had to do was add ‘pymel’ to the mocked modules in conf.py, like so:
import mock
for mod in ['pymel', 'pymel.core']:
sys.modules[mod] = mock.Mock()
I sort of prefer doing this to changing sphinx to use mayapy, since it leaves sphinx closer to its original state, but honestly that’s just a gut feeling. Do you have strong opinions about which solution is better?
for sphynx, probably not a big deal either way since you arent really getting anything out it “being in maya”, quicker anyways