Skip to content

Commit

Permalink
Merge pull request astropy/astropy-helpers#226 from bsipocz/pep8_and_…
Browse files Browse the repository at this point in the history
…container_travis

Cleanup PR
  • Loading branch information
astrofrog committed Jun 3, 2016
2 parents 9968476 + 927d252 commit aa132cd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 44 deletions.
3 changes: 2 additions & 1 deletion sphinx_automodapi/astropyautosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def get_items(self, names):
``[(name, signature, summary_string, real_name), ...]``.
"""
from sphinx.ext.autosummary import (get_import_prefixes_from_env,
import_by_name, get_documenter, mangle_signature)
import_by_name, get_documenter,
mangle_signature)

env = self.state.document.settings.env

Expand Down
19 changes: 10 additions & 9 deletions sphinx_automodapi/automodapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
else:
unknownops.append(opname)

#join all the allowedpkgnms
# join all the allowedpkgnms
if len(allowedpkgnms) == 0:
allowedpkgnms = ''
onlylocals = True
Expand Down Expand Up @@ -268,11 +268,12 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
else:
automodline = ''
if top_head:
newstrs.append(automod_templ_modheader.format(modname=modnm,
modhds=h1 * len(modnm),
pkgormod='Package' if ispkg else 'Module',
pkgormodhds=h1 * (8 if ispkg else 7),
automoduleline=automodline))
newstrs.append(automod_templ_modheader.format(
modname=modnm,
modhds=h1 * len(modnm),
pkgormod='Package' if ispkg else 'Module',
pkgormodhds=h1 * (8 if ispkg else 7),
automoduleline=automodline))
else:
newstrs.append(automod_templ_modheader.format(
modname='',
Expand All @@ -281,16 +282,16 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
pkgormodhds='',
automoduleline=automodline))

#construct the options for the class/function sections
#start out indented at 4 spaces, but need to keep the indentation.
# construct the options for the class/function sections
# start out indented at 4 spaces, but need to keep the indentation.
clsfuncoptions = []
if toctreestr:
clsfuncoptions.append(toctreestr)
if toskip:
clsfuncoptions.append(':skip: ' + ','.join(toskip))
if allowedpkgnms:
clsfuncoptions.append(allowedpkgnms)
if hascls: # This makes no sense unless there are classes.
if hascls: # This makes no sense unless there are classes.
if inherited_members is True:
clsfuncoptions.append(':inherited-members:')
if inherited_members is False:
Expand Down
51 changes: 24 additions & 27 deletions sphinx_automodapi/automodsumm.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def run(self):
skipnames.append(lnm)
if len(option_skipnames) > 0:
self.warn('Tried to skip objects {objs} in module {mod}, '
'but they were not present. Ignoring.'.format(
objs=option_skipnames, mod=modname))
'but they were not present. Ignoring.'
.format(objs=option_skipnames, mod=modname))

if funconly and not clsonly:
cont = []
Expand Down Expand Up @@ -205,7 +205,7 @@ def get_items(self, names):
return Autosummary.get_items(self, names)


#<-------------------automod-diagram stuff------------------------------------>
# <-------------------automod-diagram stuff----------------------------------->
class Automoddiagram(InheritanceDiagram):

option_spec = dict(InheritanceDiagram.option_spec)
Expand Down Expand Up @@ -237,7 +237,7 @@ def run(self):
self.arguments = oldargs


#<---------------------automodsumm generation stuff--------------------------->
# <---------------------automodsumm generation stuff-------------------------->
def process_automodsumm_generation(app):
env = app.builder.env

Expand All @@ -262,14 +262,13 @@ def process_automodsumm_generation(app):
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=suffix,
base_path=app.srcdir,
inherited_members=app.config.automodsumm_inherited_members)

#_automodsummrex = re.compile(r'^(\s*)\.\. automodsumm::\s*([A-Za-z0-9_.]+)\s*'
# r'\n\1(\s*)(\S|$)', re.MULTILINE)
generate_automodsumm_docs(
lines, sfn, builder=app.builder, warn=app.warn, info=app.info,
suffix=suffix, base_path=app.srcdir,
inherited_members=app.config.automodsumm_inherited_members)

# _automodsummrex = re.compile(r'^(\s*)\.\. automodsumm::\s*([A-Za-z0-9_.]+)\s*'
# r'\n\1(\s*)(\S|$)', re.MULTILINE)
_lineendrex = r'(?:\n|$)'
_hdrex = r'^\n?(\s*)\.\. automodsumm::\s*(\S+)\s*' + _lineendrex
_oprex1 = r'(?:\1(\s+)\S.*' + _lineendrex + ')'
Expand Down Expand Up @@ -319,7 +318,7 @@ def automodsumm_to_autosummary_lines(fn, app):
filestr = fr.read()

spl = _automodsummrex.split(filestr)
#0th entry is the stuff before the first automodsumm line
# 0th entry is the stuff before the first automodsumm line
indent1s = spl[1::5]
mods = spl[2::5]
opssecs = spl[3::5]
Expand All @@ -330,12 +329,12 @@ def automodsumm_to_autosummary_lines(fn, app):
# entries for all the public objects
newlines = []

#loop over all automodsumms in this document
# loop over all automodsumms in this document
for i, (i1, i2, modnm, ops, rem) in enumerate(zip(indent1s, indent2s, mods,
opssecs, remainders)):
opssecs, remainders)):
allindent = i1 + ('' if i2 is None else i2)

#filter out functions-only and classes-only options if present
# filter out functions-only and classes-only options if present
oplines = ops.split('\n')
toskip = []
allowedpkgnms = []
Expand Down Expand Up @@ -407,13 +406,12 @@ def generate_automodsumm_docs(lines, srcfn, suffix='.rst', warn=None,

from .utils import find_autosummary_in_lines_for_automodsumm as find_autosummary_in_lines


if info is None:
info = _simple_info
if warn is None:
warn = _simple_warn

#info('[automodsumm] generating automodsumm for: ' + srcfn)
# info('[automodsumm] generating automodsumm for: ' + srcfn)

# Create our own templating environment - here we use Astropy's
# templates rather than the default autosummary templates, in order to
Expand All @@ -431,7 +429,7 @@ def generate_automodsumm_docs(lines, srcfn, suffix='.rst', warn=None,
template_env = SandboxedEnvironment(loader=template_loader)

# read
#items = find_autosummary_in_files(sources)
# items = find_autosummary_in_files(sources)
items = find_autosummary_in_lines(lines, filename=srcfn)
if len(items) > 0:
msg = '[automodsumm] {1}: found {0} automodsumm entries to generate'
Expand Down Expand Up @@ -544,11 +542,11 @@ def get_members_class(obj, typ, include_public=[],
if doc.objtype == 'module':
ns['members'] = get_members_mod(obj, None)
ns['functions'], ns['all_functions'] = \
get_members_mod(obj, 'function')
get_members_mod(obj, 'function')
ns['classes'], ns['all_classes'] = \
get_members_mod(obj, 'class')
get_members_mod(obj, 'class')
ns['exceptions'], ns['all_exceptions'] = \
get_members_mod(obj, 'exception')
get_members_mod(obj, 'exception')
elif doc.objtype == 'class':
if inherited_mem is not None:
# option set in this specifc directive
Expand All @@ -561,12 +559,11 @@ def get_members_class(obj, typ, include_public=[],
ns['members'] = get_members_class(obj, None,
include_base=include_base)
ns['methods'], ns['all_methods'] = \
get_members_class(obj, 'method',
api_class_methods,
include_base=include_base)
get_members_class(obj, 'method', api_class_methods,
include_base=include_base)
ns['attributes'], ns['all_attributes'] = \
get_members_class(obj, 'attribute',
include_base=include_base)
get_members_class(obj, 'attribute',
include_base=include_base)
ns['methods'].sort()
ns['attributes'].sort()

Expand Down
13 changes: 7 additions & 6 deletions sphinx_automodapi/smart_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,20 @@ def missing_reference_handler(app, env, node, contnode):
reftarget = front
suffix = '.' + suffix

if (reftype in ('class', ) and '.' in reftarget
and reftarget not in mapping):
if (reftype in ('class', ) and '.' in reftarget and
reftarget not in mapping):

if '.' in front:
reftarget, _ = front.rsplit('.', 1)
suffix = '.' + suffix
reftarget = reftarget + suffix
prefix = reftarget.rsplit('.')[0]
inventory = env.intersphinx_named_inventory
if (reftarget not in mapping and
prefix in env.intersphinx_named_inventory):
prefix in inventory):

if reftarget in env.intersphinx_named_inventory[prefix]['py:class']:
newtarget = env.intersphinx_named_inventory[prefix]['py:class'][reftarget][2]
if reftarget in inventory[prefix]['py:class']:
newtarget = inventory[prefix]['py:class'][reftarget][2]
if not node['refexplicit'] and \
'~' not in node.rawsource:
contnode = literal(text=reftarget)
Expand All @@ -76,7 +77,7 @@ def missing_reference_handler(app, env, node, contnode):

if reftarget in mapping:
newtarget = mapping[reftarget] + suffix
if not node['refexplicit'] and not '~' in node.rawsource:
if not node['refexplicit'] and '~' not in node.rawsource:
contnode = literal(text=newtarget)
newnode = env.domains['py'].resolve_xref(
env, node['refdoc'], app.builder, 'class', newtarget,
Expand Down
2 changes: 1 addition & 1 deletion sphinx_automodapi/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#namedtuple is needed for find_mod_objs so it can have a non-local module
# namedtuple is needed for find_mod_objs so it can have a non-local module

import sys
from collections import namedtuple
Expand Down
1 change: 1 addition & 0 deletions sphinx_automodapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from sphinx.ext.autosummary.generate import find_autosummary_in_docstring


def find_mod_objs(modname, onlylocals=False):
""" Returns all the public attributes of a module referenced by name.
Expand Down

0 comments on commit aa132cd

Please sign in to comment.