From 927d25236ba20d4a87165ae410151dd0dcb70de7 Mon Sep 17 00:00:00 2001 From: Brigitta Sipocz Date: Wed, 13 Apr 2016 13:53:57 +0100 Subject: [PATCH] PEP8 fixes --- sphinx_automodapi/astropyautosummary.py | 3 +- sphinx_automodapi/automodapi.py | 19 ++++----- sphinx_automodapi/automodsumm.py | 51 ++++++++++++------------- sphinx_automodapi/smart_resolver.py | 13 ++++--- sphinx_automodapi/tests/test_utils.py | 2 +- sphinx_automodapi/utils.py | 1 + 6 files changed, 45 insertions(+), 44 deletions(-) diff --git a/sphinx_automodapi/astropyautosummary.py b/sphinx_automodapi/astropyautosummary.py index 96fcf2d..d82bfa2 100644 --- a/sphinx_automodapi/astropyautosummary.py +++ b/sphinx_automodapi/astropyautosummary.py @@ -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 diff --git a/sphinx_automodapi/automodapi.py b/sphinx_automodapi/automodapi.py index 6dfd9a6..627bce3 100644 --- a/sphinx_automodapi/automodapi.py +++ b/sphinx_automodapi/automodapi.py @@ -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 @@ -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='', @@ -281,8 +282,8 @@ 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) @@ -290,7 +291,7 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None, 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: diff --git a/sphinx_automodapi/automodsumm.py b/sphinx_automodapi/automodsumm.py index dee903d..3cbf908 100644 --- a/sphinx_automodapi/automodsumm.py +++ b/sphinx_automodapi/automodsumm.py @@ -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 = [] @@ -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) @@ -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 @@ -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 + ')' @@ -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] @@ -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 = [] @@ -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 @@ -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' @@ -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 @@ -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() diff --git a/sphinx_automodapi/smart_resolver.py b/sphinx_automodapi/smart_resolver.py index f01ca2f..f884ec0 100644 --- a/sphinx_automodapi/smart_resolver.py +++ b/sphinx_automodapi/smart_resolver.py @@ -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) @@ -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, diff --git a/sphinx_automodapi/tests/test_utils.py b/sphinx_automodapi/tests/test_utils.py index 8f1a9dd..154ec43 100644 --- a/sphinx_automodapi/tests/test_utils.py +++ b/sphinx_automodapi/tests/test_utils.py @@ -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 diff --git a/sphinx_automodapi/utils.py b/sphinx_automodapi/utils.py index c17214e..a61664d 100644 --- a/sphinx_automodapi/utils.py +++ b/sphinx_automodapi/utils.py @@ -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.