Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #478 from bsipocz/sphinx_automodapi_011
Browse files Browse the repository at this point in the history
Update sphinx-automodapi to v0.11
  • Loading branch information
bsipocz committed May 29, 2019
2 parents 61e27b7 + 6a9a99f commit c49e1d6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -10,6 +10,8 @@ astropy-helpers Changelog

- Allow Python dev versions to pass the python version check. [#476]

- Updated bundled version of sphinx-automodapi to v0.11. [#478]


2.0.9 (2019-02-22)
------------------
Expand Down
2 changes: 1 addition & 1 deletion astropy_helpers/extern/automodapi/__init__.py
@@ -1 +1 @@
__version__ = '0.10'
__version__ = '0.11'
24 changes: 18 additions & 6 deletions astropy_helpers/extern/automodapi/automodapi.py
Expand Up @@ -14,9 +14,10 @@
This includes variables, for which a possible docstring after the
variable definition will be shown.
* ``:no-inheritance-diagram:``
If present, the inheritance diagram will not be shown even if
the module/package has classes.
* ``:inheritance-diagram:`` / ``:no-inheritance-diagram:``
Specify whether or not to show the inheritance diagram for classes. This
overrides the default global configuration set in
``automodapi_inheritance_diagram``.
* ``:skip: str``
This option results in the
Expand Down Expand Up @@ -57,7 +58,13 @@
allows the user to overrride the global setting.
This extension also adds three sphinx configuration options:
This extension also adds four sphinx configuration options:
* ``automodapi_inheritance_diagram``
Should be a boolean that indicates whether to show inheritance diagrams
by default. This can be overriden on a case by case basis with
``:inheritance-diagram:`` and ``:no-inheritance-diagram:``. Defaults to
``True``.
* ``automodapi_toctreedirnm``
This must be a string that specifies the name of the directory the
Expand Down Expand Up @@ -204,7 +211,7 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
doc_path = '.'
else:
doc_path = os.path.join(app.srcdir, docname)
toctreestr += os.path.relpath(api_dir, os.path.dirname(doc_path))
toctreestr += os.path.relpath(api_dir, os.path.dirname(doc_path)).replace(os.sep, '/')
else:
toctreestr = ''

Expand All @@ -220,7 +227,9 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,

# initialize default options
toskip = []
inhdiag = maindocstr = top_head = True
inhdiag = app.config.automodapi_inheritance_diagram
maindocstr = True
top_head = True
hds = '-^'
allowedpkgnms = []
allowothers = False
Expand All @@ -231,6 +240,8 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
for opname, args in _automodapiargsrex.findall(spl[grp * 3 + 2]):
if opname == 'skip':
toskip.append(args.strip())
elif opname == 'inheritance-diagram':
inhdiag = True
elif opname == 'no-inheritance-diagram':
inhdiag = False
elif opname == 'no-main-docstr':
Expand Down Expand Up @@ -419,6 +430,7 @@ def setup(app):

app.connect('source-read', process_automodapi)

app.add_config_value('automodapi_inheritance_diagram', True, True)
app.add_config_value('automodapi_toctreedirnm', 'api', True)
app.add_config_value('automodapi_writereprocessed', False, True)

Expand Down
17 changes: 11 additions & 6 deletions astropy_helpers/extern/automodapi/automodsumm.py
Expand Up @@ -581,6 +581,10 @@ def get_members_class(obj, typ, include_public=[],
continue
if typ is None or documenter.objtype == typ:
items.append(name)
elif typ == 'attribute' and documenter.objtype == 'property':
# In Sphinx 2.0 and above, properties have a separate
# objtype, but we treat them the same here.
items.append(name)
public = [x for x in items
if x in include_public or not x.startswith('_')]
return public, items
Expand Down Expand Up @@ -642,24 +646,25 @@ def get_members_class(obj, typ, include_public=[],
# astropy/config/logging_helper.py) then the reference file is set
# to ../config/references.txt
if '.' in mod_name:
mod_name_dir = mod_name.replace('.', '/').split('/', 1)[1]
mod_name_dir = mod_name.split('.', 1)[1].replace('.', os.sep)
else:
mod_name_dir = mod_name
if not os.path.isdir(os.path.join(base_path, mod_name_dir)) \
and os.path.isdir(os.path.join(base_path, mod_name_dir.rsplit('/', 1)[0])):
mod_name_dir = mod_name_dir.rsplit('/', 1)[0]

if (not os.path.isdir(os.path.join(base_path, mod_name_dir))
and os.path.isdir(os.path.join(base_path, mod_name_dir.rsplit(os.sep, 1)[0]))):
mod_name_dir = mod_name_dir.rsplit(os.sep, 1)[0]

# We then have to check whether it exists, and if so, we pass it
# to the template.
if os.path.exists(os.path.join(base_path, mod_name_dir, 'references.txt')):
# An important subtlety here is that the path we pass in has
# to be relative to the file being generated, so we have to
# figure out the right number of '..'s
ndirsback = path.replace(base_path, '').count('/')
ndirsback = path.replace(base_path, '').count(os.sep)
ref_file_rel_segments = ['..'] * ndirsback
ref_file_rel_segments.append(mod_name_dir)
ref_file_rel_segments.append('references.txt')
ns['referencefile'] = os.path.join(*ref_file_rel_segments)
ns['referencefile'] = os.path.join(*ref_file_rel_segments).replace(os.sep, '/')

rendered = template.render(**ns)
f.write(cleanup_whitespace(rendered))
Expand Down
2 changes: 1 addition & 1 deletion astropy_helpers/extern/automodapi/smart_resolver.py
Expand Up @@ -73,7 +73,7 @@ def missing_reference_handler(app, env, node, contnode):
if (reftarget not in mapping and
prefix in inventory):

if reftarget in inventory[prefix]['py:class']:
if 'py:class' in inventory[prefix] and reftarget in inventory[prefix]['py:class']:
newtarget = inventory[prefix]['py:class'][reftarget][2]
if not node['refexplicit'] and \
'~' not in node.rawsource:
Expand Down

0 comments on commit c49e1d6

Please sign in to comment.