Skip to content

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

Merged
merged 6 commits into from
May 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ matrix:
- python: 3.5
env:
- STYLE=1
- python: 3.5
env:
- DOC_DOC_TEST=1
before_install:
- source tools/travis_tools.sh
- virtualenv --python=python venv
Expand Down
2 changes: 1 addition & 1 deletion doc/source/dicom/dicom_niftiheader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ Optional Dependency Note: If pydicom is not installed, nibabel uses a generic

.. _`NIfTI Extensions Standard`: http://nifti.nimh.nih.gov/nifti-1/documentation/nifti1fields/nifti1fields_pages/extension.html

.. include:: links_names.txt
.. include:: ../links_names.txt
33 changes: 17 additions & 16 deletions doc/tools/apigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self,
rst_extension='.txt',
package_skip_patterns=None,
module_skip_patterns=None,
other_defines = True
other_defines=True
):
''' Initialize package for parsing

Expand Down Expand Up @@ -162,7 +162,7 @@ def _uri2path(self, uri):
path = path.replace('.', os.path.sep)
path = os.path.join(self.root_path, path)
# XXX maybe check for extensions as well?
if os.path.exists(path + '.py'): # file
if os.path.exists(path + '.py'): # file
path += '.py'
elif os.path.exists(os.path.join(path, '__init__.py')):
path = os.path.join(path, '__init__.py')
Expand All @@ -184,7 +184,7 @@ def _parse_module(self, uri):
if filename is None:
print(filename, 'erk')
# nothing that we could handle here.
return ([],[])
return ([], [])

f = open(filename, 'rt')
functions, classes = self._parse_lines(f)
Expand All @@ -207,7 +207,7 @@ def _parse_module_with_import(self, uri):
classes : list of str
A list of (public) class names in the module.
"""
mod = __import__(uri, fromlist=[uri])
mod = __import__(uri, fromlist=[uri.split('.')[-1]])
# find all public objects in the module.
obj_strs = [obj for obj in dir(mod) if not obj.startswith('_')]
functions = []
Expand Down Expand Up @@ -276,7 +276,7 @@ def generate_api_doc(self, uri):

# Make a shorter version of the uri that omits the package name for
# titles
uri_short = re.sub(r'^%s\.' % self.package_name,'',uri)
uri_short = re.sub(r'^%s\.' % self.package_name, '', uri)

head = '.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n'
body = ''
Expand All @@ -300,10 +300,10 @@ def generate_api_doc(self, uri):
body += '\n.. autoclass:: ' + c + '\n'
# must NOT exclude from index to keep cross-refs working
body += ' :members:\n' \
' :undoc-members:\n' \
' :show-inheritance:\n' \
'\n' \
' .. automethod:: __init__\n\n'
' :undoc-members:\n' \
' :show-inheritance:\n' \
'\n' \
' .. automethod:: __init__\n\n'
head += '.. autosummary::\n\n'
for f in classes + functions:
head += ' ' + f + '\n'
Expand Down Expand Up @@ -402,7 +402,7 @@ def discover_modules(self):
package_uri = '.'.join((root_uri, subpkg_name))
package_path = self._uri2path(package_uri)
if (package_path and
self._survives_exclude(package_uri, 'package')):
self._survives_exclude(package_uri, 'package')):
modules.append(package_uri)

return sorted(modules)
Expand All @@ -425,12 +425,12 @@ def write_modules_api(self, modules, outdir):
written_modules = []

for ulm, mods in module_by_ulm.items():
print "Generating docs for %s:" % ulm
print("Generating docs for %s:" % ulm)
document_head = []
document_body = []

for m in mods:
print " -> " + m
print(" -> " + m)
head, body = self.generate_api_doc(m)

document_head.append(head)
Expand Down Expand Up @@ -467,7 +467,7 @@ def write_api_docs(self, outdir):
os.mkdir(outdir)
# compose list of modules
modules = self.discover_modules()
self.write_modules_api(modules,outdir)
self.write_modules_api(modules, outdir)

def write_index(self, outdir, froot='gen', relative_to=None):
"""Make a reST API index file from written files
Expand All @@ -493,10 +493,11 @@ def write_index(self, outdir, froot='gen', relative_to=None):
path = os.path.join(outdir, froot+self.rst_extension)
# Path written into index is relative to rootpath
if relative_to is not None:
relpath = (outdir + os.path.sep).replace(relative_to + os.path.sep, '')
relpath = (
outdir + os.path.sep).replace(relative_to + os.path.sep, '')
else:
relpath = outdir
idx = open(path,'wt')
idx = open(path, 'wt')
w = idx.write
w('.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n')

Expand All @@ -505,5 +506,5 @@ def write_index(self, outdir, froot='gen', relative_to=None):
w("=" * len(title) + "\n\n")
w('.. toctree::\n\n')
for f in self.written_modules:
w(' %s\n' % os.path.join(relpath,f))
w(' %s\n' % os.path.join(relpath, f))
idx.close()
5 changes: 3 additions & 2 deletions doc/tools/build_modref_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# version comparison
from distutils.version import LooseVersion as V

#*****************************************************************************
# *****************************************************************************


def abort(error):
print('*WARNING* API documentation not generated: %s' % error)
Expand All @@ -36,7 +37,7 @@ def abort(error):

try:
__import__(package)
except ImportError, e:
except ImportError as e:
abort("Can not import " + package)

module = sys.modules[package]
Expand Down
2 changes: 1 addition & 1 deletion nibabel/freesurfer/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time


from .. externals.six.moves import xrange
from ..externals.six.moves import xrange
from ..openers import Opener


Expand Down