-
Notifications
You must be signed in to change notification settings - Fork 262
ENH: allow building docs with Python 3 #450
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
Conversation
The AppVeyor failure is unrelated (an md5 sum mismatch for the h5py package) |
Known issue with appveyor: ContinuumIO/anaconda-issues#71 |
mod = __import__(uri, fromlist=[uri]) | ||
except ImportError: | ||
# fix ImportError for submodules in Python 3 | ||
mod = __import__(uri, fromlist=[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will only import the base package module, so nibabel
when uri='nibabel.parrec'
. At least for me, you need fromlist=['']
to get the submodule, which I think is what we want. That seems to work for Python 2 and Python 3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fromlist=['']
works fine on Python 3 for me, but with Python 2.7 I get the following error:
Generating docs for nibabel.freesurfer:
-> nibabel.freesurfer
Traceback (most recent call last):
File "tools/build_modref_templates.py", line 73, in <module>
docwriter.write_api_docs(outdir)
File "/media/Data1/src_repositories/my_git/nibabel_grl/doc/tools/apigen.py", line 470, in write_api_docs
self.write_modules_api(modules, outdir)
File "/media/Data1/src_repositories/my_git/nibabel_grl/doc/tools/apigen.py", line 434, in write_modules_api
head, body = self.generate_api_doc(m)
File "/media/Data1/src_repositories/my_git/nibabel_grl/doc/tools/apigen.py", line 273, in generate_api_doc
functions, classes = self._parse_module_with_import(uri)
File "/media/Data1/src_repositories/my_git/nibabel_grl/doc/tools/apigen.py", line 210, in _parse_module_with_import
mod = __import__(uri, fromlist=[''])
File "/home/lee8rx/anaconda/lib/python2.7/site-packages/nibabel/freesurfer/__init__.py", line 4, in <module>
from .io import read_geometry, read_morph_data, write_morph_data, \
File "/home/lee8rx/anaconda/lib/python2.7/site-packages/nibabel/freesurfer/io.py", line 8, in <module>
from .. externals.six.moves import xrange
ImportError: No module named externals.six.moves
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a typo in the import line - extra space between the ..
and externals.six.moves
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strange. I still get the same error without the space. However, If I replace the relative imports like ..
with absolute imports from nibabel.
then it works fine for me. That doesn't really make sense, though, because the same sorts of relative imports are working fine from other files such as the ones in /benchmarks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm - that's odd. Sckit-image has a version of apigen.py
- this is what they are doing : https://github.com/scikit-image/scikit-image/blob/master/doc/tools/apigen.py#L203
Would you mind adding a Python 3 version of the doc build and test to .travis.yml
?
Current coverage is 93.77%
@@ master #450 diff @@
==========================================
Files 147 147
Lines 19181 19179 -2
Methods 0 0
Messages 0 0
Branches 2029 2029
==========================================
- Hits 17986 17984 -2
Misses 796 796
Partials 399 399
|
The skimage solution is working on this laptop for python 3. I can rebase/merge a couple of the commits if this passes CI. |
The fix was copied from scikit-image's version of apigen.py
I squashed one of the commits, using the scikit-image solution for The last commit here fixes the following warning during the documentation build:
However, I don't think any of the links from that file are actually being used in |
Great - thanks. There's still a PEP style failure - but fine to merge after that's fixed... |
fixed the PEP8. Travis is happy now |
Thanks for doing that - merging. |
The third commit fixes ImportErrors such as the following when building with Python 3: