-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
autosummary doesn’t report correct module on ImportError #7989
Comments
On my local, the reason of the failure is not shown. How did you get this warning? At present, autosummary tries to import the target object in many ways.
For example, the extension tries to import the following modules for the above document:
During this trial, many exceptions like |
I assume it’s happening here: sphinx/sphinx/ext/autosummary/generate.py Lines 406 to 411 in 9fd9ede
I’m sorry my supposedly reproducible example doesn’t work properly … I’ll see if I can find a working one |
I am experiencing this as well while trying to debug readthedocs/readthedocs.org#8326. I'm very deep into the debugging now, but basically this error shown in the logs:
is actually caused by this:
unrolling the traceback:
Hope I can provide a better reproducer. |
Here is a simpler reproducer: https://github.com/astrojuanlu/sphinx-autosummary-tracebacks (.venv) $ pip install -r requirements.txt
(.venv) $ python -c "import test_pkg.A; print(test_pkg.A)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/juanlu/Projects/RTD/tmp/sphinx-autosummary-tracebacks/.venv/lib/python3.7/site-packages/test_pkg.py", line 7, in <module>
import attr # Do not install to surface problem
ModuleNotFoundError: No module named 'attr'
(.venv) $ make html
Running Sphinx v4.1.1
loading pickled environment... done
[autosummary] generating autosummary for: index.rst
WARNING: [autosummary] failed to import 'test_pkg.A': no module named test_pkg.A
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
no targets are out of date.
build succeeded, 1 warning.
The HTML pages are in build/html.
(.venv) $ python -m sphinx -W -b html source/ build/html
Running Sphinx v4.1.1
[autosummary] generating autosummary for: index.rst
Warning, treated as error:
[autosummary] failed to import 'test_pkg.A': no module named test_pkg.A The error (both with and without |
I think the main issue for the "wrong" (not so helpful) error message is, that most of the ImportErrors in the autosummary code are just thrown away. E.g., in the code snippet above there is:
I guess here should not be a pass, but something like storing the exception message into a variable. And if autosummary fails, use that variable value instead of the generic "no module named" |
I added a pull request which implements my suggestion to collect the import errors: #9555 |
Describe the bug
Import warnings in autosummary mention the same class twice instead of mentioning what actually caused the problem.
To Reproduce
Steps to reproduce the behavior:
create a module
a.py
that imports a nonexistant moduleb.py
document something in module
a
using autosummary:.. autosummary:: a.AClass
Actual behavior
Expected behavior
Environment info
The text was updated successfully, but these errors were encountered: