Merge pull request #10648 from blueyed/autopep8

ci: py: flake8 fixes
This commit is contained in:
Daniel Hahler 2019-07-30 07:32:47 +02:00 committed by GitHub
commit 35ec60f73a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 398 additions and 345 deletions

2
.flake8 Normal file
View File

@ -0,0 +1,2 @@
[flake8]
max-line-length = 88

View File

@ -516,6 +516,7 @@ if(NOT BUSTED_OUTPUT_TYPE)
endif()
find_program(LUACHECK_PRG luacheck)
find_program(FLAKE8_PRG flake8)
find_program(GPERF_PRG gperf)
include(InstallHelpers)
@ -667,6 +668,15 @@ else()
COMMENT "lualint: LUACHECK_PRG not defined")
endif()
if(FLAKE8_PRG)
add_custom_target(pylint
COMMAND ${FLAKE8_PRG} contrib/ scripts/ src/ test/
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
else()
add_custom_target(pylint false
COMMENT "flake8: FLAKE8_PRG not defined")
endif()
set(CPACK_PACKAGE_NAME "Neovim")
set(CPACK_PACKAGE_VENDOR "neovim.io")
set(CPACK_PACKAGE_VERSION ${NVIM_VERSION_MEDIUM})

View File

@ -138,6 +138,9 @@ functionaltest-lua: | nvim
lualint: | build/.ran-cmake deps
$(BUILD_CMD) -C build lualint
pylint: | build/.ran-cmake deps
$(BUILD_CMD) -C build pylint
unittest: | nvim
+$(BUILD_CMD) -C build unittest
@ -179,6 +182,6 @@ appimage:
appimage-%:
bash scripts/genappimage.sh $*
lint: check-single-includes clint lualint
lint: check-single-includes clint lualint pylint
.PHONY: test lualint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage checkprefix
.PHONY: test lualint pylint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage checkprefix

View File

@ -4,6 +4,7 @@ set -e
set -o pipefail
if [[ "${CI_TARGET}" == lint ]]; then
python -m pip -q install --user --upgrade flake8
exit
fi

View File

@ -9,26 +9,24 @@ source "${CI_DIR}/common/build.sh"
source "${CI_DIR}/common/suite.sh"
enter_suite 'clint'
run_test 'make clint-full' clint
exit_suite --continue
enter_suite 'lualint'
run_test 'make lualint' lualint
exit_suite --continue
enter_suite 'pylint'
run_test 'make pylint' pylint
exit_suite --continue
enter_suite single-includes
CLICOLOR_FORCE=1 run_test_wd \
--allow-hang \
10s \
'make check-single-includes' \
'csi_clean' \
single-includes
exit_suite --continue
end_tests

View File

@ -22,8 +22,6 @@ def main(argv):
args = argparser.parse_args(argv)
with args.file:
include_dirs = []
iwyu = Popen(['include-what-you-use', '-xc'] + args.iwyu_args + ['/dev/stdin'],
stdin=PIPE, stdout=PIPE, stderr=PIPE)

View File

@ -86,7 +86,7 @@ SITENAVI_SEARCH = '<table width="100%"><tbody><tr><td>' + SITENAVI_LINKS_WEB + \
TEXTSTART = """
<div id="d1">
<pre id="sp"> </pre>
<pre id="sp">""" + (" " * 80) + """</pre>
<div id="d2">
<pre>
"""
@ -152,6 +152,7 @@ RE_SECTION = re.compile(r'[-A-Z .][-A-Z0-9 .()]*(?=\s+\*)')
RE_STARTAG = re.compile(r'\s\*([^ \t|]+)\*(?:\s|$)')
RE_LOCAL_ADD = re.compile(r'LOCAL ADDITIONS:\s+\*local-additions\*$')
class Link(object):
__slots__ = 'link_plain_same', 'link_pipe_same', \
'link_plain_foreign', 'link_pipe_foreign', \
@ -165,6 +166,7 @@ class Link(object):
self.link_pipe_foreign = link_pipe_foreign
self.filename = filename
class VimH2H(object):
def __init__(self, tags, version=None, is_web_version=True):
self._urls = {}
@ -183,6 +185,7 @@ class VimH2H(object):
def do_add_tag(self, filename, tag):
tag_quoted = urllib.parse.quote_plus(tag)
def mkpart1(doc):
return '<a href="' + doc + '#' + tag_quoted + '" class="'
part1_same = mkpart1('')
@ -192,6 +195,7 @@ class VimH2H(object):
doc = filename + '.html'
part1_foreign = mkpart1(doc)
part2 = '">' + html_escape[tag] + '</a>'
def mklinks(cssclass):
return (part1_same + cssclass + part2,
part1_foreign + cssclass + part2)
@ -199,9 +203,12 @@ class VimH2H(object):
m = RE_LINKWORD.match(tag)
if m:
opt, ctrl, special = m.groups()
if opt is not None: cssclass_plain = 'o'
elif ctrl is not None: cssclass_plain = 'k'
elif special is not None: cssclass_plain = 's'
if opt is not None:
cssclass_plain = 'o'
elif ctrl is not None:
cssclass_plain = 'k'
elif special is not None:
cssclass_plain = 's'
links_plain = mklinks(cssclass_plain)
links_pipe = mklinks('l')
self._urls[tag] = Link(
@ -213,15 +220,20 @@ class VimH2H(object):
links = self._urls.get(tag)
if links is not None:
if links.filename == curr_filename:
if css_class == 'l': return links.link_pipe_same
else: return links.link_plain_same
if css_class == 'l':
return links.link_pipe_same
else:
if css_class == 'l': return links.link_pipe_foreign
else: return links.link_plain_foreign
return links.link_plain_same
else:
if css_class == 'l':
return links.link_pipe_foreign
else:
return links.link_plain_foreign
elif css_class is not None:
return '<span class="' + css_class + '">' + html_escape[tag] + \
'</span>'
else: return html_escape[tag]
else:
return html_escape[tag]
def to_html(self, filename, contents, encoding):
out = []
@ -247,7 +259,8 @@ class VimH2H(object):
if inexample == 2:
if RE_EG_END.match(line):
inexample = 0
if line[0] == '<': line = line[1:]
if line[0] == '<':
line = line[1:]
else:
out.extend(('<span class="e">', html_escape[line],
'</span>\n'))
@ -300,7 +313,8 @@ class VimH2H(object):
if lastpos < len(line):
out.append(html_escape[line[lastpos:]])
out.append('\n')
if inexample == 1: inexample = 2
if inexample == 1:
inexample = 2
header = []
header.append(HEAD.format(encoding=encoding, filename=filename))
@ -318,6 +332,7 @@ class VimH2H(object):
header.append(TEXTSTART)
return ''.join(chain(header, out, (FOOTER, sitenavi_footer, FOOTER2)))
class HtmlEscCache(dict):
def __missing__(self, key):
r = key.replace('&', '&amp;') \
@ -326,11 +341,10 @@ class HtmlEscCache(dict):
self[key] = r
return r
html_escape = HtmlEscCache()
def slurp(filename):
try:
with open(filename, encoding='UTF-8') as f:
@ -340,11 +354,14 @@ def slurp(filename):
with open(filename, encoding='latin-1') as f:
return f.read(), 'latin-1'
def usage():
return "usage: " + sys.argv[0] + " IN_DIR OUT_DIR [BASENAMES...]"
def main():
if len(sys.argv) < 3: sys.exit(usage())
if len(sys.argv) < 3:
sys.exit(usage())
in_dir = sys.argv[1]
out_dir = sys.argv[2]
@ -368,4 +385,5 @@ def main():
of.write(h2h.to_html(basename, text, encoding))
of.close()
main()

View File

@ -36,7 +36,6 @@ import shutil
import textwrap
import subprocess
import collections
import pprint
from xml.dom import minidom
@ -99,7 +98,8 @@ CONFIG = {
'func_name_prefix': '',
'section_name': {},
'module_override': {
'shared': 'vim', # `shared` functions are exposed on the `vim` module.
# `shared` functions are exposed on the `vim` module.
'shared': 'vim',
},
'append_only': [
'shared.lua',
@ -121,6 +121,7 @@ annotation_map = {
# deprecated functions.
xrefs = set()
def debug_this(s, n):
o = n if isinstance(n, str) else n.toprettyxml(indent=' ', newl='\n')
name = '' if isinstance(n, str) else n.nodeName
@ -209,6 +210,7 @@ def is_inline(n):
return False
return True
def doc_wrap(text, prefix='', width=70, func=False, indent=None):
"""Wraps text to `width`.
@ -292,8 +294,9 @@ def render_params(parent, width=62):
out += '{}{}\n'.format(name, desc)
return out.rstrip()
# Renders a node as Vim help text, recursively traversing all descendants.
def render_node(n, text, prefix='', indent='', width=62):
"""Renders a node as Vim help text, recursively traversing all descendants."""
text = ''
# space_preceding = (len(text) > 0 and ' ' == text[-1][-1])
# text += (int(not space_preceding) * ' ')
@ -317,7 +320,11 @@ def render_node(n, text, prefix='', indent='', width=62):
text += ' [verbatim] {}'.format(get_text(n))
elif n.nodeName == 'listitem':
for c in n.childNodes:
text += indent + prefix + render_node(c, text, indent=indent+(' ' * len(prefix)), width=width)
text += (
indent
+ prefix
+ render_node(c, text, indent=indent + (' ' * len(prefix)), width=width)
)
elif n.nodeName in ('para', 'heading'):
for c in n.childNodes:
text += render_node(c, text, indent=indent, width=width)
@ -356,6 +363,7 @@ def render_node(n, text, prefix='', indent='', width=62):
n.nodeName, n.toprettyxml(indent=' ', newl='\n')))
return text
def render_para(parent, indent='', width=62):
"""Renders Doxygen <para> containing arbitrary nodes.
@ -407,11 +415,13 @@ def render_para(parent, indent='', width=62):
if len(groups['return']) > 0:
chunks.append('\nReturn: ~')
for child in groups['return']:
chunks.append(render_node(child, chunks[-1][-1], indent=indent, width=width))
chunks.append(render_node(
child, chunks[-1][-1], indent=indent, width=width))
if len(groups['seealso']) > 0:
chunks.append('\nSee also: ~')
for child in groups['seealso']:
chunks.append(render_node(child, chunks[-1][-1], indent=indent, width=width))
chunks.append(render_node(
child, chunks[-1][-1], indent=indent, width=width))
for child in groups['xrefs']:
title = get_text(get_child(child, 'xreftitle'))
xrefs.add(title)
@ -587,6 +597,7 @@ def delete_lines_below(filename, tokenstr):
with open(filename, 'wt') as fp:
fp.writelines(lines[0:i])
def gen_docs(config):
"""Generate documentation.
@ -619,7 +630,8 @@ def gen_docs(config):
continue
groupname = get_text(find_first(compound, 'name'))
groupxml = os.path.join(base, '%s.xml' % compound.getAttribute('refid'))
groupxml = os.path.join(base, '%s.xml' %
compound.getAttribute('refid'))
desc = find_first(minidom.parse(groupxml), 'detaileddescription')
if desc:
@ -680,12 +692,15 @@ def gen_docs(config):
i = 0
for filename in CONFIG[mode]['section_order']:
if filename not in sections:
raise RuntimeError('found new module "{}"; update the "section_order" map'.format(filename))
raise RuntimeError(
'found new module "{}"; update the "section_order" map'.format(
filename))
title, helptag, section_doc = sections.pop(filename)
i += 1
if filename not in CONFIG[mode]['append_only']:
docs += sep
docs += '\n%s%s' % (title, helptag.rjust(text_width - len(title)))
docs += '\n%s%s' % (title,
helptag.rjust(text_width - len(title)))
docs += section_doc
docs += '\n\n\n'

View File

@ -63,10 +63,10 @@ fname = sys.argv[1]
try:
filt = sys.argv[2]
except IndexError:
filt = lambda entry: True
def filt(entry): return True
else:
_filt = filt
filt = lambda entry: eval(_filt, globals(), {'entry': entry})
def filt(entry): return eval(_filt, globals(), {'entry': entry})
poswidth = len(str(os.stat(fname).st_size or 1000))

View File

@ -97,7 +97,8 @@ def main(progname, cfname, only_static, move_all):
if not generated_existed:
lines[include_line:include_line] = [
'#ifdef INCLUDE_GENERATED_DECLARATIONS\n',
'# include "{0}.generated.h"\n'.format(os.path.relpath(fname, relname)),
'# include "{0}.generated.h"\n'.format(
os.path.relpath(fname, relname)),
'#endif\n',
]

View File

@ -2610,9 +2610,13 @@ def CheckBraces(filename, clean_lines, linenum, error):
'Brace starting function body must be placed on its own line')
else:
func_start_linenum = end_linenum + 1
while not clean_lines.lines[func_start_linenum] == '{':
attrline = Match(r'^((?!# *define).*?)(?:FUNC_ATTR|FUNC_API|REAL_FATTR)_\w+(?:\(\d+(, \d+)*\))?',
clean_lines.lines[func_start_linenum])
while not clean_lines.lines[func_start_linenum] == "{":
attrline = Match(
r'^((?!# *define).*?)'
r'(?:FUNC_ATTR|FUNC_API|REAL_FATTR)_\w+'
r'(?:\(\d+(, \d+)*\))?',
clean_lines.lines[func_start_linenum],
)
if attrline:
if len(attrline.group(1)) != 2:
error(filename, func_start_linenum,
@ -3182,7 +3186,8 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
r'|li_(?:next|prev|tv))\b', line)
if match:
error(filename, linenum, 'runtime/deprecated', 4,
'Accessing list_T internals directly is prohibited (hint: see commit d46e37cb4c71)')
'Accessing list_T internals directly is prohibited '
'(hint: see commit d46e37cb4c71)')
# Check for suspicious usage of "if" like
# } if (a == b) {

View File

@ -8,6 +8,7 @@ import locale
import io
import sys
def set_output_encoding(enc=None):
"""Set the encoding of stdout and stderr
@ -29,6 +30,7 @@ def set_output_encoding(enc=None):
writer = io.open(fo.fileno(), mode='w', newline='', **kw)
write = writer.write # save the original write() function
enc = locale.getpreferredencoding()
def convwrite(s):
if isinstance(s, bytes):
write(s.decode(enc)) # convert to unistr