Nick
Nick

Reputation: 783

Sphinx Autodoc not importing properly

As the title says I am using Sphinx to generate documentation for a python library and using the auto doc functions.

The problem I am having is that the autodoc importer does not properly import the libraries.

Traceback (most recent call last):rs/user                                                                                                                                                         
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
  File "/Users/prggmr/Work/chevy/gt/software/gt/lib/decorators.py", line 4, in <module>
    import response
  File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
    from lib.helpers import gtJSONEncoder
  File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 3, in <module>
    from gt import Model, EMAIL_FROM, EMAIL_HOST
  File "/Users/prggmr/Work/chevy/gt/software/gt/gt.py", line 114, in <module>
    from modules.user import views
  File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/views.py", line 5, in <module>
    from lib import response
ImportError: cannot import name response
Traceback (most recent call last):json                                                                                                                                                            
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
  File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 2, in <module>
    import response
  File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
    from lib.helpers import gtJSONEncoder
ImportError: cannot import name gtJSONEncoder
Traceback (most recent call last):messages                                                                                                                                                        
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
ImportError: No module named helper
Traceback (most recent call last):request                                                                                                                                                         
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
  File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 2, in <module>
    import response
  File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
    from lib.helpers import gtJSONEncoder
ImportError: cannot import name gtJSONEncoder
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
  File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 2, in <module>
    import response
  File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
    from lib.helpers import gtJSONEncoder
ImportError: cannot import name gtJSONEncoder
Traceback (most recent call last):ser                                                                                                                                                             
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
  File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/models.py", line 6, in <module>
    import gt
  File "/Users/prggmr/Work/chevy/gt/software/gt/gt.py", line 114, in <module>
    from modules.user import views
  File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/views.py", line 7, in <module>
    from lib.decorators import valid_user
  File "/Users/prggmr/Work/chevy/gt/software/gt/lib/decorators.py", line 7, in <module>
    from gt.modules.user.models import get_user_account, is_login_valid
ImportError: No module named modules.user.models
Traceback (most recent call last):ser                                                                                                                                                             
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
  File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/views.py", line 2, in <module>
    from gt import app, TEMPLATES_PATH
  File "/Users/prggmr/Work/chevy/gt/software/gt/gt.py", line 114, in <module>
    from modules.user import views
ImportError: cannot import name views

I have tripled checked that the paths are correct and I am including them on the system path.

The thing that really gets me about this is that I can run the application just perfectly and all unit tests are passing with over 95% code coverage ... yet sphinx cannot import it.

Upvotes: 1

Views: 1631

Answers (1)

Alex Morega
Alex Morega

Reputation: 4228

That looks like an import loop. Try to organize your imports so that they don't depend on each other in a circle.

Alternatively, you can try to reorder them. Perhaps in helpers.py move line 3 to the bottom of the file, or something similar.

Upvotes: 2

Related Questions