Skip to content
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

autodoc tries to import classes as modules? #3768

Closed
amueller opened this issue May 18, 2017 · 14 comments
Closed

autodoc tries to import classes as modules? #3768

amueller opened this issue May 18, 2017 · 14 comments

Comments

@amueller
Copy link

amueller commented May 18, 2017

After updating sphinx and numpydoc, I get

WARNING: /home/andy/checkout/scikit-learn/doc/modules/generated/sklearn.preprocessing.RobustScaler.rst:92: (WARNING/2) autodoc: failed to import method 'RobustScaler.__init__' from module 'sklearn.preprocessing.data.RobustScaler'; the following exception was raised:
Traceback (most recent call last):
  File "/home/andy/anaconda3/lib/python3.5/site-packages/sphinx/ext/autodoc.py", line 658, in import_object
    __import__(self.modname)
ImportError: No module named 'sklearn.preprocessing.data.RobustScaler'; 'sklearn.preprocessing.data' is not a package

for every class in the package.

It looks like the modname is wrong as it is the class and not the module. I'm not sure what should be imported at this point, though. The class? Importing a method doesn't seem to make a lot of sense...

@tk0miya
Copy link
Member

tk0miya commented May 19, 2017

Could you share your project to reproduce the error?
It would be nice if you provide small reproducible examples :-)

Thanks,

@amueller
Copy link
Author

amueller commented May 19, 2017 via email

@tk0miya
Copy link
Member

tk0miya commented May 23, 2017

Hmm.. scikit-learn's doc is too large and complex to investigate...
I failed to do that today.

@tk0miya tk0miya modified the milestones: 1.6.3, 1.6.2 May 23, 2017
@goosemania
Copy link
Contributor

@amueller , I suggest to test your case with this recently merged fix #3780 . It is very small in terms of the changes to the code but it has a huge impact on how import works in certain cases. Hopefully it covers your case as well.

@amueller
Copy link
Author

Thanks for looking into it. I'll have a look next week when I'm back from vacation ;)

@amueller
Copy link
Author

amueller commented Jun 3, 2017

The issue is still present on master.

@amueller
Copy link
Author

amueller commented Jun 3, 2017

I stripped down the sklearn build:
https:/amueller/sphinx-debug

you need to add the doc folder to the pythonpath so the blablub.py is found as a module.

I get

WARNING: /home/andy/checkout/sphinx-debug/doc/modules/generated/blablub.BaseEstimator.rst:28: (WARNING/2) autodoc: failed to import method 'BaseEstimator.__init__' from module 'blablub.BaseEstimator'; the following exception was raised:
Traceback (most recent call last):
  File "/home/andy/checkout/sphinx/sphinx/ext/autodoc.py", line 657, in import_object
    __import__(self.modname)

@tk0miya
Copy link
Member

tk0miya commented Jun 4, 2017

Yes, autodoc imports the target module internally on generating document.

It seems your example surely raises ImportError, but the error reason is different with first case. Is this intended?

WARNING: /docs/sphinx-debug/doc/modules/classes.rst:1: (WARNING/2) autodoc: failed to import module 'blablub'; the following exception was raised:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/sphinx/ext/autodoc.py", line 658, in import_object
    __import__(self.modname)
ImportError: No module named 'blablub'

The message on first case is here:

ImportError: No module named 'sklearn.preprocessing.data.RobustScaler'; 'sklearn.preprocessing.data' is not a package

@amueller
Copy link
Author

amueller commented Jun 4, 2017

@tk0miya as I said, you need to add the doc path to the python path for the module to be found. Not sure how to autodoc a module that's not installed.

@amueller
Copy link
Author

amueller commented Jun 7, 2017

anything I can do to make reproducing this easier? solving this will make our release process much easier, currently it prevents us from using stock packages for building our docs.

@tk0miya
Copy link
Member

tk0miya commented Jun 11, 2017

Not sure how to autodoc a module that's not installed.

Please add your library's path to sys.path in conf.py like following:

import os
import sys

sys.path.insert(0, os.path.abspath("."))

@amueller
Copy link
Author

amueller commented Jun 11, 2017

done, not that that's any different from export PYTHONPATH=`pwd`

@jschueller
Copy link
Contributor

maybe it was fixed by numpy/numpydoc#93 ?

@amueller
Copy link
Author

@jschueller indeed it seems to be fixed on numpydoc master. Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants