Skip to content

Error when generating WCS documentation #117

Closed

Description

@astrofrog

When build the latest docs, I get the following error:

Traceback (most recent call last):wcsprm                                        
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
ImportError: No module named _wcs

/Users/tom/tmp/astropy/docs/wcs/api_wcsprm.rst:14: WARNING: autodoc can't import/find class 'astropy.wcs._wcs.Tabprm', it reported error: "No module named _wcs", please check your spelling and sys.path

Activity

  1. ghost assigned on Dec 29, 2011
  2. eteq commented on Dec 30, 2011

    @eteq
    Member

    Odd, I do not see this error (either on Ubuntu 11.04 nor OS X 10.6 w/ py2.7) - the docs build without any problem.

  3. astrofrog commented on Dec 30, 2011

    @astrofrog
    MemberAuthor

    I'm using Sphinx 1.1.2. I just tested with a clean master, and it still occurs. The error occurs because of this autoclass statement:

    .. autoclass:: astropy.wcs._wcs.Tabprm
    

    which expects the built C extension. But even after running python setup.py build or python setup.py install I can't get that error to go away, maybe because we now include the astropy source directory in the tree correctly? (https://github.com/astropy/astropy/blob/master/docs/conf.py#L24) - and that source directory doesn't contain the built c extensions.

  4. mdboom commented on Dec 30, 2011

    @mdboom
    Contributor

    Are you installing astropy into a virtualenv, perhaps? The sphinx-build being used to build the docs must be able to import the installed astropy. What I generally do is install sphinx into my virtualenv or add my virtualenv to PYTHONPATH to get around this limitation.

  5. astrofrog commented on Dec 30, 2011

    @astrofrog
    MemberAuthor

    I'm not using a virtualenv. Just to make sure I understand, the following line in conf.py should force the source directory to be used instead of the installed astropy:

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

    If I change the line to:

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

    as it used to be (which was wrong), then the installed version is used and I don't see this error anymore. Do your PYTHONPATH edits override the above setting and place the installed astropy first in the path, in front of the source directory?

  6. eteq commented on Dec 30, 2011

    @eteq
    Member

    Are you building the docs by doing python setup.py build_sphinx, or make html in the docs directory?

  7. astrofrog commented on Dec 30, 2011

    @astrofrog
    MemberAuthor

    I'm using the latter

  8. eteq commented on Dec 30, 2011

    @eteq
    Member

    Maybe try the former? it should do exactly the same thing as doing python setup.py build followed by the make html thing... but maybe its getting confused about which directory you're in?

    You might also try uninstalling the system-installed version (or setup.py develop link) and seeing if you can get it built that way - if it builds there but doesn't with the install, then at least we know its got to do with the installed version instead of the actual building process...

  9. astrofrog commented on Dec 30, 2011

    @astrofrog
    MemberAuthor

    If I remove any installed version, clone a clean copy of the master branch in the upstream repository, and run:

    python setup.py build_sphinx
    

    I get:

    $ python setup.py build_sphinx
    Freezing version number to astropy/version.py
    ------------------------------------------------------------
    The legacy package 'vo' was found.
    To install astropy's compatibility layer instead, uninstall
    'vo' and then reinstall astropy.
    ------------------------------------------------------------
    ------------------------------------------------------------
    The legacy package 'pywcs' was found.
    To install astropy's compatibility layer instead, uninstall
    'pywcs' and then reinstall astropy.
    ------------------------------------------------------------
    running build_sphinx
    creating docs/_static
    creating docs/_build
    creating docs/_build/doctrees
    creating docs/_build/html
    Running Sphinx v1.1.2
    loading pickled environment... not yet created
    loading intersphinx inventory from http://docs.python.org/objects.inv...
    loading intersphinx inventory from http://docs.scipy.org/doc/scipy/reference/objects.inv...
    loading intersphinx inventory from http://docs.scipy.org/doc/numpy/objects.inv...
    loading intersphinx inventory from http://matplotlib.sourceforge.net/objects.inv...
    building [html]: all source files
    updating environment: 45 added, 0 changed, 0 removed
    Traceback (most recent call last):wcsprm                                                                                                                              
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 321, in import_object
        __import__(self.modname)
    ImportError: No module named _wcs
    reading sources... [100%] wcs/relax                                                                                                                                   
    /Users/tom/dropbox/code/development/astropy/docs/wcs/api_wcsprm.rst:14: WARNING: autodoc can't import/find class 'astropy.wcs._wcs.Tabprm', it reported error: "No module named _wcs", please check your spelling and sys.path
    looking for now-outdated files... none found
    pickling environment... done
    checking consistency... done
    preparing documents... done
    WARNING: dot command 'dot' cannot be run (needed for graphviz output), check the graphviz_dot setting                                                                 
    writing output... [100%] wcs/relax                                                                                                                                    
    writing additional files... (19 module code pages) _modules/index
     genindex py-modindex np-modindex search
    copying images... [100%] development/workflow/pull_button.png                                                                                                         
    copying static files... done
    dumping search index... done
    dumping object inventory... done
    build succeeded, 2 warnings.
    

    (note that the error is still there). Am I doing something wrong?

  10. eteq commented on Jan 2, 2012

    @eteq
    Member

    I was able to reproduce it by starting a fresh clone, and I think I understand what's happening: when building, the docs inject .. into sys.modules, as @astrofrog pointed out... but if you start fresh and only do python setup.py build (or anything that triggers the build), the C extensions get put into `build/lib.platformstuff/...``, and the docs only see the normal source tree, which does not include the built versions.

    These was working for me (and presumably @mdboom) because I use python setup.py develop, which puts the compiled code inside the source directory... but we definitely want it to work the way you tried to do it. I think the solution is to inject ../build/lib.whatever into sys.modules (after ..), but I'm not sure what the best way is to figure out what the lib directory is. Does anyone know if there's some stdlib or setuptools function that can tell you this?

  11. astrofrog commented on Jan 2, 2012

    @astrofrog
    MemberAuthor

    I think adding the lib library from build will be a bit messy, as the build directory can contain several lib directories (from different python versions). The cleanest way is probably just to not inject anything into sys.modules, and to just require astropy be installed in order to build the docs. One could always consider adding .. to sys.modules, but at the end, rather than at the start, so that it is only used as a last resort, and would not include compiled C extensions.

  12. eteq commented on Jan 2, 2012

    @eteq
    Member

    Well, my thought was that there's always only one build/lib.whateverdirectory for any given python version/platform... and the information is all in the platform stdlib module, so it shouldn't be that hard to make sure that only the appropriate build//lib directory is added. I was just wondering if anyone knew of a "standard" way to do it (perhaps @iguananaut or @mdboom?). It might just be hidden somewhere in distutils, in which case we might as well use it.

    I, at least, find it frustrating to use the as-installed version for building the doc. I know some projects do this, but I sometimes want to build docs for a different version than the one I have installed (or even for a package I don't necessarily want to install at all), which is then impossible. I've also built the wrong docs many times by not doing setup.py install first -- that's particularly annoying if you're doing make html because you have to always go back to the source dir or have two consoles open. If we put .. first, followed by build/lib.whatever, I think that's the least error-prone way.

  13. eteq commented on Jan 3, 2012

    @eteq
    Member

    I did a few tests after finding distutils.util.get_platform... see eteq/astropy@4bedaf8 - that does what I was suggesting above...

    However, it reveals another problem: because we do import astropy in setup.py, it still imports the in-source version if I do python setup.py build_sphinx, although it now works perfectly if you do make html inside the docs directory. We could add some extra bits to make setup.py use the build version of astropy (if it's present) to get around this, or play around with imports in the build_sphinx command (which is already customized for us). Alternatively, we could do as @astrofrog suggests, and put .. (and perhaps the get_platform thing I did in the above commit) at the end...

  14. phn commented on Jan 3, 2012

    @phn
    Contributor

    I was wondering whether using something like Tox is better than attempting to add too many modifications to sys.path and other variables.

    One issue with Tox is that it creates the "sdist" archive and then tries to build the entire package, after copying the "sdist" to an isolated virtualenv. This means that testing only the documentation build may not be possible.

    Tox also has a commands option that can run arbitrary commands. So, for example one can say

    commands=python -c "import astropy; astropy.test()"
    

    to run tests using py.test shipped with astropy.

    I am not an expert, so can't think of potential problems.

  15. taldcroft commented on Jan 3, 2012

    @taldcroft
    Member

    I haven't tested with astropy just now, but in the past I got around this problem with

    python setup.py build_ext --inplace
    

    That builds the compiled extensions within the source dir.

  16. mdboom commented on Jan 3, 2012

    @mdboom
    Contributor

    @phn: I haven't spent much time with Tox, but building docs without first building the code is impossible by design anyway, so I wouldn't worry about being about to build docs separately from anything else.

    @eteq: It would be nice to simplify this, but there's a problem with being too magical here since we don't (currently) control how and where Sphinx was installed and building in place is such a problem with multiple branches of astropy or multiple versions of python.

    The doc build works by running a Makefile which calls sphinx-build in the shell. This sphinx-build may or may not be the same Python that was invoked by python setup.py build_sphinx. So one could build astropy in place and still fail because Sphinx expects the C extensions to be compiled for a different version of Python.

    I think I fall on @astrofrog's suggestion that you kind of need to know what you're doing and we should inject anything into sys.path. The docs should just clearly say "install astropy, and make sure it is importable from the same environment as Sphinx is installed in".

    However, if we want something more automated, there may be a way to leverage setuptools and ensure Sphinx installed in the current Python environment, then set the SPHINXBUILD environment variable to point to that specific installation of the sphinx-build script, then add build/platform to the path (don't rely on --inplace, it's too broken when using multiple versions of Python), and then use the makefile to build the docs.

  17. mdboom commented on Jan 3, 2012

    @mdboom
    Contributor

    Scratch my comment about build_sphinx failing if using a different python interpreter from the one where sphinx is installed. build_sphinx doesn't use the Makefile -- I've been seeing problems for an unrelated reason. I suppose I'm ok with adding build/platform to sys.path in that case -- and we can do it from our custom build_sphinx command and leave the raw make html invocation alone.

  18. eteq commented on Jan 4, 2012

    @eteq
    Member

    @taldcroft - build_ext --inplace I think does the same thing as develop in terms of building - so that works, but I don't think we want to do that if we want to try to be using the standard as-built version.

    @mdboom - just so I understand, in your second post you're suggesting have it first try the installed version, and then falling back on build/platform, or the other way around?

  19. astrofrog commented on Jan 4, 2012

    @astrofrog
    MemberAuthor

    I agree with @mdboom that we can do the magic for the build_sphinx command, and that the make html should just use the installed version (so we should remove the sys.path command from conf.py).

  20. mdboom commented on Jan 4, 2012

    @mdboom
    Contributor

    @eteq: I wasn't clear... but I was suggesting that build_sphinx would use the version in build/platform and that make html would do nothing magical (i.e. just use whatever Python paths the user may have already set up).

  21. eteq commented on Jan 5, 2012

    @eteq
    Member

    Ah, now that I get it, that sounds like a good plan to me as well.

    I can go ahead and do this as part of #115, or we can have a separate pull request to address this and I can rebase #115 against that - either way is fine with me.

  22. eteq commented on Feb 14, 2012

    @eteq
    Member

    This should be closed when #171 is closed.

  23. astrofrog commented on Apr 18, 2012

    @astrofrog
    MemberAuthor

    Now that #187 has been merged in, I think this issue can be closed. I no longer see the WCS error I originally reported in this issue. @eteq - can you confirm this can be closed?

  24. eteq commented on Apr 18, 2012

    @eteq
    Member

    Yep, this is now fixed (at least, it's no longer the docs' fault if wcs doesn't build! :)

  25. added a commit that references this issue on Nov 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions