diff --git a/sphinx_automodapi/autodoc_enhancements.py b/sphinx_automodapi/autodoc_enhancements.py index ee63814..9a1b64f 100644 --- a/sphinx_automodapi/autodoc_enhancements.py +++ b/sphinx_automodapi/autodoc_enhancements.py @@ -43,13 +43,16 @@ def type_object_attrgetter(obj, attr, *defargs): of autodoc. """ - if attr in obj.__dict__ and isinstance(obj.__dict__[attr], property): - # Note, this should only be used for properties--for any other type of - # descriptor (classmethod, for example) this can mess up existing - # expectcations of what getattr(cls, ...) returns - return obj.__dict__[attr] - else: - return getattr(obj, attr, *defargs) + for base in obj.__mro__: + if attr in base.__dict__: + if isinstance(base.__dict__[attr], property): + # Note, this should only be used for properties--for any other + # type of descriptor (classmethod, for example) this can mess + # up existing expectations of what getattr(cls, ...) returns + return base.__dict__[attr] + break + + return getattr(obj, attr, *defargs) def setup(app): diff --git a/sphinx_automodapi/automodapi.py b/sphinx_automodapi/automodapi.py index db7c4c0..19b628d 100644 --- a/sphinx_automodapi/automodapi.py +++ b/sphinx_automodapi/automodapi.py @@ -85,6 +85,11 @@ from .utils import find_mod_objs +if sys.version_info[0] == 3: + text_type = str +else: + text_type = unicode + automod_templ_modheader = """ {modname} {pkgormod} @@ -296,7 +301,7 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None, if app.config.automodapi_writereprocessed: # sometimes they are unicode, sometimes not, depending on how # sphinx has processed things - if isinstance(newsourcestr, unicode): + if isinstance(newsourcestr, text_type): ustr = newsourcestr else: ustr = newsourcestr.decode(app.config.source_encoding) @@ -304,10 +309,16 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None, if docname is None: with open(os.path.join(app.srcdir, 'unknown.automodapi'), 'a') as f: f.write('\n**NEW DOC**\n\n') - f.write(ustr.encode('utf8')) + f.write(ustr) else: - with open(os.path.join(app.srcdir, docname + '.automodapi'), 'w') as f: - f.write(ustr.encode('utf8')) + env = app.builder.env + # Determine the filename associated with this doc (specifically + # the extension) + filename = docname + os.path.splitext(env.doc2path(docname))[1] + filename += '.automodapi' + + with open(os.path.join(app.srcdir, filename), 'w') as f: + f.write(ustr) return newsourcestr else: @@ -330,8 +341,11 @@ def _mod_info(modname, toskip=[], onlylocals=True): break # find_mod_objs has already imported modname + # TODO: There is probably a cleaner way to do this, though this is pretty + # reliable for all Python versions for most cases that we care about. pkg = sys.modules[modname] - ispkg = '__init__.' in os.path.split(pkg.__name__)[1] + ispkg = (hasattr(pkg, '__file__') and isinstance(pkg.__file__, str) and + os.path.split(pkg.__file__)[1].startswith('__init__.py')) return ispkg, hascls, hasfunc diff --git a/sphinx_automodapi/automodsumm.py b/sphinx_automodapi/automodsumm.py index 9a43680..4d0e596 100644 --- a/sphinx_automodapi/automodsumm.py +++ b/sphinx_automodapi/automodsumm.py @@ -172,18 +172,23 @@ def run(self): self.content = cont - #for some reason, even though ``currentmodule`` is substituted in, sphinx - #doesn't necessarily recognize this fact. So we just force it - #internally, and that seems to fix things + # for some reason, even though ``currentmodule`` is substituted in, + # sphinx doesn't necessarily recognize this fact. So we just force + # it internally, and that seems to fix things env.temp_data['py:module'] = modname - #can't use super because Sphinx/docutils has trouble - #return super(Autosummary,self).run() + # can't use super because Sphinx/docutils has trouble return + # super(Autosummary,self).run() nodelist.extend(Autosummary.run(self)) + return self.warnings + nodelist finally: # has_content = False for the Automodsumm self.content = [] + def get_items(self, names): + self.genopt['imported-members'] = True + return Autosummary.get_items(self, names) + #<-------------------automod-diagram stuff------------------------------------> class Automoddiagram(InheritanceDiagram): @@ -220,10 +225,12 @@ def run(self): #<---------------------automodsumm generation stuff---------------------------> def process_automodsumm_generation(app): env = app.builder.env - ext = app.config.source_suffix - filestosearch = [x + ext for x in env.found_docs - if os.path.isfile(env.doc2path(x))]\ + filestosearch = [] + for docname in env.found_docs: + filename = env.doc2path(docname) + if os.path.isfile(filename): + filestosearch.append(docname + os.path.splitext(filename)[1]) liness = [] for sfn in filestosearch: @@ -238,10 +245,11 @@ def process_automodsumm_generation(app): f.write('\n') for sfn, lines in zip(filestosearch, liness): + suffix = os.path.splitext(sfn)[1] if len(lines) > 0: generate_automodsumm_docs(lines, sfn, builder=app.builder, warn=app.warn, info=app.info, - suffix=app.config.source_suffix, + suffix=suffix, base_path=app.srcdir) #_automodsummrex = re.compile(r'^(\s*)\.\. automodsumm::\s*([A-Za-z0-9_.]+)\s*' @@ -281,6 +289,7 @@ def automodsumm_to_autosummary_lines(fn, app): """ + fullfn = os.path.join(app.builder.env.srcdir, fn) with open(fullfn) as fr: @@ -288,7 +297,8 @@ def automodsumm_to_autosummary_lines(fn, app): from astropy_helpers.sphinx.ext.automodapi import automodapi_replace # Must do the automodapi on the source to get the automodsumm # that might be in there - filestr = automodapi_replace(fr.read(), app, True, fn, False) + docname = os.path.splitext(fn)[0] + filestr = automodapi_replace(fr.read(), app, True, docname, False) else: filestr = fr.read() @@ -353,6 +363,9 @@ def automodsumm_to_autosummary_lines(fn, app): continue newlines.append(allindent + nm) + # add one newline at the end of the autosummary block + newlines.append('') + return newlines diff --git a/sphinx_automodapi/tests/test_automodsumm.py b/sphinx_automodapi/tests/test_automodsumm.py index cd8afa3..aec7039 100644 --- a/sphinx_automodapi/tests/test_automodsumm.py +++ b/sphinx_automodapi/tests/test_automodsumm.py @@ -66,7 +66,8 @@ def warn(self, msg, loc): automodsumm_to_autosummary_lines generate_automodsumm_docs process_automodsumm_generation - setup""" + setup +""" def test_ams_to_asmry(tmpdir): @@ -97,7 +98,8 @@ def test_ams_to_asmry(tmpdir): .. autosummary:: :p: - pilot""" + pilot +""" def test_ams_cython(tmpdir, cython_testpackage):