autodoc with mock import

125 views
Skip to first unread message

Brad Buran

unread,
Jul 8, 2022, 2:32:03 PM7/8/22
to Enaml
I'm trying to use Sphinx to autodoc my code (psiexperiment). Some third-party libraries are  not available on Linux (e.g., tdt) so I can't have them installed when generating the documentation via readthedocs. I tried mocking them (e.g., autodoc_mock_imports = ['tdt']); however, I get the following error:

WARNING: autodoc: failed to import module 'tdt' from module 'psi.controller.engines'; the following exception was raised:
  <snip>
  File "/home/bburan/Documents/OHSU/LBHB/psiexperiment/psi/controller/engines/tdt/__init__.py", line 134, in <module>
    class TDTEngine(Engine):
  File "/home/bburan/Documents/OHSU/LBHB/psiexperiment/psi/controller/engines/tdt/__init__.py", line 161, in TDTEngine
    _project = Typed(DSPProject)
  File "/home/bburan/bin/miniconda3/envs/ohsu-psi/lib/python3.9/site-packages/atom/typed.py", line 55, in __init__
    self.set_validate_mode(Validate.Typed, kind)
TypeError: Expected object of type `type`. Got object of type `DSPProject` instead.

Here, DSPProject is imported from the tdt module. I understand the nature of the error itself (i.e., something about autodoc_mock_imports is generating a mock class that is not a type but rather a class instance (presumably of a mock class).

Is there any simple way to better generate the mockup for the DSPProject class without resorting to tricks to detect whether sphinx is running and providing a specially-mocked DSPProject class?

Brad

Chris Colbert

unread,
Jul 11, 2022, 5:28:40 PM7/11/22
to Brad Buran, Enaml
The root problem here is that mock libraries rely on duck-typing to function. Atom is the explicit opposite of duck-typing, so they are always going to be at-odds with each other.

--
You received this message because you are subscribed to the Google Groups "Enaml" group.
To unsubscribe from this group and stop receiving emails from it, send an email to enaml+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/enaml/942c9d1e-3bfc-4b00-a001-f7057a12d1d0n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages