diff --git a/doc/ext/docscrape.py b/doc/ext/docscrape.py index 615ea11f..13bec4aa 100644 --- a/doc/ext/docscrape.py +++ b/doc/ext/docscrape.py @@ -6,7 +6,11 @@ import inspect import textwrap import re import pydoc -from StringIO import StringIO +try: + from StringIO import StringIO +except ImportError: + import io as StringIO + from warnings import warn class Reader(object): @@ -113,7 +117,7 @@ class NumpyDocString(object): return self._parsed_data[key] def __setitem__(self,key,val): - if not self._parsed_data.has_key(key): + if not key in self._parsed_data: warn("Unknown section %s" % key) else: self._parsed_data[key] = val @@ -428,7 +432,7 @@ class FunctionDoc(NumpyDocString): argspec = inspect.formatargspec(*argspec) argspec = argspec.replace('*','\*') signature = '%s%s' % (func_name, argspec) - except TypeError, e: + except TypeError as e: signature = '%s()' % func_name self['Signature'] = signature @@ -451,7 +455,7 @@ class FunctionDoc(NumpyDocString): if self._role: if not roles.has_key(self._role): - print "Warning: invalid role %s" % self._role + print("Warning: invalid role %s" % self._role) out += '.. %s:: %s\n \n\n' % (roles.get(self._role,''), func_name) diff --git a/doc/ext/numpydoc.py b/doc/ext/numpydoc.py index aa390056..e151fbb0 100644 --- a/doc/ext/numpydoc.py +++ b/doc/ext/numpydoc.py @@ -16,11 +16,18 @@ It will: """ -import os, re, pydoc +import os, re, sys, pydoc from docscrape_sphinx import get_doc_object, SphinxDocString from sphinx.util.compat import Directive import inspect + +if sys.version.startswith('3'): + u = str +else: + u = unicode + + def mangle_docstrings(app, what, name, obj, options, lines, reference_offset=[0]): @@ -29,12 +36,11 @@ def mangle_docstrings(app, what, name, obj, options, lines, if what == 'module': # Strip top title - title_re = re.compile(ur'^\s*[#*=]{4,}\n[a-z0-9 -]+\n[#*=]{4,}\s*', - re.I|re.S) + title_re = re.compile(u(r'^\s*[#*=]{4,}\n[a-z0-9 -]+\n[#*=]{4,}\s*'), re.I|re.S) lines[:] = title_re.sub(u'', u"\n".join(lines)).split(u"\n") else: doc = get_doc_object(obj, what, u"\n".join(lines), config=cfg) - lines[:] = unicode(doc).split(u"\n") + lines[:] = u(doc).split(u"\n") if app.config.numpydoc_edit_link and hasattr(obj, '__name__') and \ obj.__name__: @@ -50,7 +56,7 @@ def mangle_docstrings(app, what, name, obj, options, lines, references = [] for line in lines: line = line.strip() - m = re.match(ur'^.. \[([a-z0-9_.-])\]', line, re.I) + m = re.match(u(r'^.. \[([a-z0-9_.-])\]'), line, re.I) if m: references.append(m.group(1)) @@ -59,7 +65,7 @@ def mangle_docstrings(app, what, name, obj, options, lines, if references: for i, line in enumerate(lines): for r in references: - if re.match(ur'^\d+$', r): + if re.match(u(r'^\d+$'), r): new_r = u"R%d" % (reference_offset[0] + int(r)) else: new_r = u"%s%d" % (r, reference_offset[0]) diff --git a/doc/ext/plot2rst.py b/doc/ext/plot2rst.py index 258a6929..268ddb63 100644 --- a/doc/ext/plot2rst.py +++ b/doc/ext/plot2rst.py @@ -132,8 +132,8 @@ GALLERY_IMAGE_TEMPLATE = """ class Path(str): """Path object for manipulating directory and file paths.""" - def __init__(self, path): - super(Path, self).__init__(path) + def __new__(self, path): + return str.__new__(self, path) @property def isdir(self): @@ -203,7 +203,7 @@ def generate_examples_and_gallery(example_dir, rst_dir, cfg): rst_dir.makedirs() # we create an index.rst with all examples - gallery_index = file(rst_dir.pjoin('index'+cfg.source_suffix), 'w') + gallery_index = open(rst_dir.pjoin('index'+cfg.source_suffix), 'w') # Here we don't use an os.walk, but we recurse only twice: flat is # better than nested. @@ -244,7 +244,7 @@ def write_gallery(gallery_index, src_dir, rst_dir, cfg, depth=0): print(80*'_') return - gallery_description = file(gallery_template).read() + gallery_description = open(gallery_template).read() gallery_index.write('\n\n%s\n\n' % gallery_description) rst_dir.makedirs() diff --git a/doc/source/coverage_generator.py b/doc/source/coverage_generator.py index 1112c021..aa566acf 100755 --- a/doc/source/coverage_generator.py +++ b/doc/source/coverage_generator.py @@ -10,7 +10,10 @@ import csv try: import cStringIO as StringIO except ImportError: - import StringIO + try: + import StringIO + except: + import io as StringIO # Missing item value MISSING_STRING=":missing:`Not Implemented`" @@ -74,7 +77,7 @@ def read_table_titles(reader): break section_titles.append(row[0]) table_names[row[0]] = names - except csv.Error, e: + except csv.Error as e: sys.exit('line %d: %s' % (reader.line_num, e)) return section_titles,table_names @@ -106,7 +109,7 @@ def table_row(stream,data,lengths,num_columns=None): if num_columns is None: num_columns = len(data) stream.write("|") - for i in xrange(num_columns): + for i in range(num_columns): if len(data)-1 >= i: if len(data[i]) == 0: entry = MISSING_STRING @@ -145,12 +148,12 @@ def generate_table(reader,stream,table_name=None, break data.append([entry.expandtabs() for entry in row]) num_columns = max(num_columns,len(row)) - except csv.Error, e: + except csv.Error as e: sys.exit('line %d: %s' % (reader.line_num, e)) column_lengths = [len(MISSING_STRING)]*num_columns for row in data: - for i in xrange(len(row)): + for i in range(len(row)): column_lengths[i] = max(column_lengths[i],len(row[i])) # Output table header diff --git a/doc/tools/apigen.py b/doc/tools/apigen.py index f1a94b6a..f4b85c96 100644 --- a/doc/tools/apigen.py +++ b/doc/tools/apigen.py @@ -200,7 +200,7 @@ class ApiDocWriter(object): 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 = [] diff --git a/doc/tools/build_modref_templates.py b/doc/tools/build_modref_templates.py index d61f5f55..e83ce980 100644 --- a/doc/tools/build_modref_templates.py +++ b/doc/tools/build_modref_templates.py @@ -25,7 +25,7 @@ if __name__ == '__main__': try: __import__(package) - except ImportError, e: + except ImportError as e: abort("Can not import skimage") module = sys.modules[package]