astropy/astropy — pull request #453 by iguananaut (2012-11-02 14:08:21+00:00)
Title: Don't raise internal ImportErrors from import sphinx

I got a traceback this morning when trying to run Astropy's setup.py (in order to try to reproduce #452). Instead I got something unrelated:

```
Traceback (most recent call last):
File "./setup.py", line 25, in
from astropy import setup_helpers
File "/bray/sc1/root/src/astropy/astropy/astropy/setup_helpers.py", line 196, in
from sphinx.setup_command import BuildDoc
File "/bray/sc1/root/home/embray/.virtualenvs/astropy-dev-27/lib/python2.7/site-packages/sphinx/setup_command.py", line 20, in
from sphinx.application import Sphinx
File "/bray/sc1/root/home/embray/.virtualenvs/astropy-dev-27/lib/python2.7/site-packages/sphinx/application.py", line 21, in
from docutils.parsers.rst import convert_directive_function, \
File "/bray/sc1/root/home/embray/.virtualenvs/astropy-dev-27/lib/python2.7/site-packages/docutils/parsers/rst/__init__.py", line 75, in
from docutils.parsers.rst import states
File "/bray/sc1/root/home/embray/.virtualenvs/astropy-dev-27/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 108, in
import roman
ImportError: No module named roman
```

The problem is that if importing sphinx fails it should be ignored, but if any
other ImportError occurs in the *process* of importing Sphinx it is raised.
There are a couple problems with this. First of all searching for the string
`'sphinx'` in `e.args[0]` is an unreliable way to determine anything about an
ImportError (in fairness, there really is no good way prior to Python 3.3 which
finally fixed that wart).

Second of all, what actually happened here is that there's something broken
about my docutils installation. Having a broken docutils or sphinx
installation should NOT cause Astropy installation to fail, since it's not even
necessary except for building the docs. Allowing an error to be raised here
could easily lead to confusing, difficult to reproduce bug reports since it was
something broken in my setup, and nothing to do with Astropy.