sphinx-automodapi
sphinx-automodapi copied to clipboard
sphinx_automodapi.automodsumm doesn't resolve autodoc_mock_imports
I have a python package module that imports 3rd party modules which aren't included in the sphinx documentation. So I added these modules to mock imports in the conf.py
autodoc_mock_imports = ["abaqus", "abaqusConstants","material","section","part","assembly", "step", "interaction","mesh","load","job","optimization","sketch", "odbAccess", "connectorBehavior","pandas","numpy","matplotlib","scipy"]
While using the mock imports works with the sphinx automodule
directive without throwing an error.
.. automodule:: mymodule
I get the an error when using the module with automodapi
directive.
.. automodapi:: mymodule
Error:
Extension error (sphinx_automodapi.automodsumm):
Handler <function process_automodsumm_generation at 0x0000021867BC5510> for event 'builder-inited' threw an exception (exception: No module named 'abaqus')
I get a similar problem with automodsumm
, but also no problem with automodule
.
The error in more detail:
-
import numba
within a module leads to an error (exception: unsupported operand type(s) for *: 'itemsize' and 'int'
). - I don't get this error when importing numba in python using the same conda environment
- Numpy statements doesn't seem to be resolved when numba code is called via sphinx. (e.g. when typing
np.byte
in the debugger, justnp.byte
is returned instead ofnumpy.int8
as expected. - The error occurs using
sphinx=5.1.1
, but not usingsphinx=5.1.0
Let me know if I a minimal example would help. Would be great if anyone has an idea how to fix it on my side or how to fit it in the package.
I don't think Astropy uses autodoc_mock_imports
. We use all optional imports as local imports, so usually they don't even get triggered during doc build. And in narrative docs that need them for doctest, we use pytest-doctestplus
to skip if it is not installed.
Unfortunately, we do not have enough resources to look at this in the near future. So, if you can propose a patch or find a way to work around it, it would be greatly appreciated. Thanks!
@pllim not sure if my use case is the same, so I'll describe it here and if it's not, then I guess we can move it to a fresh issue
I am working on a python package for which 1 module uses PyTorch. This module is for supporting a specific set of operations that many users won't need, so I didn't want to install it everytime and basically created try/except
clauses which in case of ModuleNotFoundError
trigger an exception with a meaningful message.
Now for building the docs for my API it seems weird to me that PyTorch needs to be installed in the environment in which I do make html
, even if I explicitly mention "torch" in the intersphinx mapping for example.
In fact, I get this,
Extension error (sphinx_automodapi.automodsumm):
Handler <function process_automodsumm_generation at 0x141b362a0> for event 'builder-inited' threw an exception (exception: PyTorch is required to use the API related to the `XXXX` module.
Please, see installation instructions about optional dependencies.)
make: *** [Makefile:20: html] Error 2
I also tried to do autodoc_mock_imports = ["torch"]
without success
Is this the same problem?
If yes, what is the best course of action?
@HealthyPear , I am not able to answer this on top of my head and I don't have time to investigate, you could try ask the astropy-dev mailing list or on https://community.openastronomy.org/c/astropy/8 ? Sorry!