mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 15:58:17 +00:00
scripts: autopep8
This commit is contained in:
@@ -81,8 +81,8 @@ SITENAVI_PLAIN = '<p>' + SITENAVI_LINKS_PLAIN + '</p>'
|
|||||||
SITENAVI_WEB = '<p>' + SITENAVI_LINKS_WEB + '</p>'
|
SITENAVI_WEB = '<p>' + SITENAVI_LINKS_WEB + '</p>'
|
||||||
|
|
||||||
SITENAVI_SEARCH = '<table width="100%"><tbody><tr><td>' + SITENAVI_LINKS_WEB + \
|
SITENAVI_SEARCH = '<table width="100%"><tbody><tr><td>' + SITENAVI_LINKS_WEB + \
|
||||||
'</td><td style="text-align: right; max-width: 25vw"><div class="gcse-searchbox">' \
|
'</td><td style="text-align: right; max-width: 25vw"><div class="gcse-searchbox">' \
|
||||||
'</div></td></tr></tbody></table><div class="gcse-searchresults"></div>'
|
'</div></td></tr></tbody></table><div class="gcse-searchresults"></div>'
|
||||||
|
|
||||||
TEXTSTART = """
|
TEXTSTART = """
|
||||||
<div id="d1">
|
<div id="d1">
|
||||||
@@ -152,6 +152,7 @@ RE_SECTION = re.compile(r'[-A-Z .][-A-Z0-9 .()]*(?=\s+\*)')
|
|||||||
RE_STARTAG = re.compile(r'\s\*([^ \t|]+)\*(?:\s|$)')
|
RE_STARTAG = re.compile(r'\s\*([^ \t|]+)\*(?:\s|$)')
|
||||||
RE_LOCAL_ADD = re.compile(r'LOCAL ADDITIONS:\s+\*local-additions\*$')
|
RE_LOCAL_ADD = re.compile(r'LOCAL ADDITIONS:\s+\*local-additions\*$')
|
||||||
|
|
||||||
|
|
||||||
class Link(object):
|
class Link(object):
|
||||||
__slots__ = 'link_plain_same', 'link_pipe_same', \
|
__slots__ = 'link_plain_same', 'link_pipe_same', \
|
||||||
'link_plain_foreign', 'link_pipe_foreign', \
|
'link_plain_foreign', 'link_pipe_foreign', \
|
||||||
@@ -165,9 +166,10 @@ class Link(object):
|
|||||||
self.link_pipe_foreign = link_pipe_foreign
|
self.link_pipe_foreign = link_pipe_foreign
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|
||||||
|
|
||||||
class VimH2H(object):
|
class VimH2H(object):
|
||||||
def __init__(self, tags, version=None, is_web_version=True):
|
def __init__(self, tags, version=None, is_web_version=True):
|
||||||
self._urls = { }
|
self._urls = {}
|
||||||
self._version = version
|
self._version = version
|
||||||
self._is_web_version = is_web_version
|
self._is_web_version = is_web_version
|
||||||
for line in RE_NEWLINE.split(tags):
|
for line in RE_NEWLINE.split(tags):
|
||||||
@@ -183,6 +185,7 @@ class VimH2H(object):
|
|||||||
|
|
||||||
def do_add_tag(self, filename, tag):
|
def do_add_tag(self, filename, tag):
|
||||||
tag_quoted = urllib.parse.quote_plus(tag)
|
tag_quoted = urllib.parse.quote_plus(tag)
|
||||||
|
|
||||||
def mkpart1(doc):
|
def mkpart1(doc):
|
||||||
return '<a href="' + doc + '#' + tag_quoted + '" class="'
|
return '<a href="' + doc + '#' + tag_quoted + '" class="'
|
||||||
part1_same = mkpart1('')
|
part1_same = mkpart1('')
|
||||||
@@ -192,6 +195,7 @@ class VimH2H(object):
|
|||||||
doc = filename + '.html'
|
doc = filename + '.html'
|
||||||
part1_foreign = mkpart1(doc)
|
part1_foreign = mkpart1(doc)
|
||||||
part2 = '">' + html_escape[tag] + '</a>'
|
part2 = '">' + html_escape[tag] + '</a>'
|
||||||
|
|
||||||
def mklinks(cssclass):
|
def mklinks(cssclass):
|
||||||
return (part1_same + cssclass + part2,
|
return (part1_same + cssclass + part2,
|
||||||
part1_foreign + cssclass + part2)
|
part1_foreign + cssclass + part2)
|
||||||
@@ -199,9 +203,12 @@ class VimH2H(object):
|
|||||||
m = RE_LINKWORD.match(tag)
|
m = RE_LINKWORD.match(tag)
|
||||||
if m:
|
if m:
|
||||||
opt, ctrl, special = m.groups()
|
opt, ctrl, special = m.groups()
|
||||||
if opt is not None: cssclass_plain = 'o'
|
if opt is not None:
|
||||||
elif ctrl is not None: cssclass_plain = 'k'
|
cssclass_plain = 'o'
|
||||||
elif special is not None: cssclass_plain = 's'
|
elif ctrl is not None:
|
||||||
|
cssclass_plain = 'k'
|
||||||
|
elif special is not None:
|
||||||
|
cssclass_plain = 's'
|
||||||
links_plain = mklinks(cssclass_plain)
|
links_plain = mklinks(cssclass_plain)
|
||||||
links_pipe = mklinks('l')
|
links_pipe = mklinks('l')
|
||||||
self._urls[tag] = Link(
|
self._urls[tag] = Link(
|
||||||
@@ -213,18 +220,23 @@ class VimH2H(object):
|
|||||||
links = self._urls.get(tag)
|
links = self._urls.get(tag)
|
||||||
if links is not None:
|
if links is not None:
|
||||||
if links.filename == curr_filename:
|
if links.filename == curr_filename:
|
||||||
if css_class == 'l': return links.link_pipe_same
|
if css_class == 'l':
|
||||||
else: return links.link_plain_same
|
return links.link_pipe_same
|
||||||
else:
|
else:
|
||||||
if css_class == 'l': return links.link_pipe_foreign
|
return links.link_plain_same
|
||||||
else: return links.link_plain_foreign
|
else:
|
||||||
|
if css_class == 'l':
|
||||||
|
return links.link_pipe_foreign
|
||||||
|
else:
|
||||||
|
return links.link_plain_foreign
|
||||||
elif css_class is not None:
|
elif css_class is not None:
|
||||||
return '<span class="' + css_class + '">' + html_escape[tag] + \
|
return '<span class="' + css_class + '">' + html_escape[tag] + \
|
||||||
'</span>'
|
'</span>'
|
||||||
else: return html_escape[tag]
|
else:
|
||||||
|
return html_escape[tag]
|
||||||
|
|
||||||
def to_html(self, filename, contents, encoding):
|
def to_html(self, filename, contents, encoding):
|
||||||
out = [ ]
|
out = []
|
||||||
|
|
||||||
inexample = 0
|
inexample = 0
|
||||||
filename = str(filename)
|
filename = str(filename)
|
||||||
@@ -247,7 +259,8 @@ class VimH2H(object):
|
|||||||
if inexample == 2:
|
if inexample == 2:
|
||||||
if RE_EG_END.match(line):
|
if RE_EG_END.match(line):
|
||||||
inexample = 0
|
inexample = 0
|
||||||
if line[0] == '<': line = line[1:]
|
if line[0] == '<':
|
||||||
|
line = line[1:]
|
||||||
else:
|
else:
|
||||||
out.extend(('<span class="e">', html_escape[line],
|
out.extend(('<span class="e">', html_escape[line],
|
||||||
'</span>\n'))
|
'</span>\n'))
|
||||||
@@ -300,7 +313,8 @@ class VimH2H(object):
|
|||||||
if lastpos < len(line):
|
if lastpos < len(line):
|
||||||
out.append(html_escape[line[lastpos:]])
|
out.append(html_escape[line[lastpos:]])
|
||||||
out.append('\n')
|
out.append('\n')
|
||||||
if inexample == 1: inexample = 2
|
if inexample == 1:
|
||||||
|
inexample = 2
|
||||||
|
|
||||||
header = []
|
header = []
|
||||||
header.append(HEAD.format(encoding=encoding, filename=filename))
|
header.append(HEAD.format(encoding=encoding, filename=filename))
|
||||||
@@ -318,6 +332,7 @@ class VimH2H(object):
|
|||||||
header.append(TEXTSTART)
|
header.append(TEXTSTART)
|
||||||
return ''.join(chain(header, out, (FOOTER, sitenavi_footer, FOOTER2)))
|
return ''.join(chain(header, out, (FOOTER, sitenavi_footer, FOOTER2)))
|
||||||
|
|
||||||
|
|
||||||
class HtmlEscCache(dict):
|
class HtmlEscCache(dict):
|
||||||
def __missing__(self, key):
|
def __missing__(self, key):
|
||||||
r = key.replace('&', '&') \
|
r = key.replace('&', '&') \
|
||||||
@@ -326,11 +341,10 @@ class HtmlEscCache(dict):
|
|||||||
self[key] = r
|
self[key] = r
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
html_escape = HtmlEscCache()
|
html_escape = HtmlEscCache()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def slurp(filename):
|
def slurp(filename):
|
||||||
try:
|
try:
|
||||||
with open(filename, encoding='UTF-8') as f:
|
with open(filename, encoding='UTF-8') as f:
|
||||||
@@ -340,17 +354,20 @@ def slurp(filename):
|
|||||||
with open(filename, encoding='latin-1') as f:
|
with open(filename, encoding='latin-1') as f:
|
||||||
return f.read(), 'latin-1'
|
return f.read(), 'latin-1'
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
return "usage: " + sys.argv[0] + " IN_DIR OUT_DIR [BASENAMES...]"
|
return "usage: " + sys.argv[0] + " IN_DIR OUT_DIR [BASENAMES...]"
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) < 3: sys.exit(usage())
|
if len(sys.argv) < 3:
|
||||||
|
sys.exit(usage())
|
||||||
|
|
||||||
in_dir = sys.argv[1]
|
in_dir = sys.argv[1]
|
||||||
out_dir = sys.argv[2]
|
out_dir = sys.argv[2]
|
||||||
basenames = sys.argv[3:]
|
basenames = sys.argv[3:]
|
||||||
|
|
||||||
print( "Processing tags...")
|
print("Processing tags...")
|
||||||
h2h = VimH2H(slurp(os.path.join(in_dir, 'tags'))[0], is_web_version=False)
|
h2h = VimH2H(slurp(os.path.join(in_dir, 'tags'))[0], is_web_version=False)
|
||||||
|
|
||||||
if len(basenames) == 0:
|
if len(basenames) == 0:
|
||||||
@@ -358,9 +375,9 @@ def main():
|
|||||||
|
|
||||||
for basename in basenames:
|
for basename in basenames:
|
||||||
if os.path.splitext(basename)[1] != '.txt' and basename != 'tags':
|
if os.path.splitext(basename)[1] != '.txt' and basename != 'tags':
|
||||||
print( "Ignoring " + basename)
|
print("Ignoring " + basename)
|
||||||
continue
|
continue
|
||||||
print( "Processing " + basename + "...")
|
print("Processing " + basename + "...")
|
||||||
path = os.path.join(in_dir, basename)
|
path = os.path.join(in_dir, basename)
|
||||||
text, encoding = slurp(path)
|
text, encoding = slurp(path)
|
||||||
outpath = os.path.join(out_dir, basename + '.html')
|
outpath = os.path.join(out_dir, basename + '.html')
|
||||||
@@ -368,4 +385,5 @@ def main():
|
|||||||
of.write(h2h.to_html(basename, text, encoding))
|
of.write(h2h.to_html(basename, text, encoding))
|
||||||
of.close()
|
of.close()
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
@@ -62,7 +62,7 @@ CONFIG = {
|
|||||||
# String used to find the start of the generated part of the doc.
|
# String used to find the start of the generated part of the doc.
|
||||||
'section_start_token': '*api-global*',
|
'section_start_token': '*api-global*',
|
||||||
# Section ordering.
|
# Section ordering.
|
||||||
'section_order' : [
|
'section_order': [
|
||||||
'vim.c',
|
'vim.c',
|
||||||
'buffer.c',
|
'buffer.c',
|
||||||
'window.c',
|
'window.c',
|
||||||
@@ -82,12 +82,12 @@ CONFIG = {
|
|||||||
# Module name overrides (for Lua).
|
# Module name overrides (for Lua).
|
||||||
'module_override': {},
|
'module_override': {},
|
||||||
# Append the docs for these modules, do not start a new section.
|
# Append the docs for these modules, do not start a new section.
|
||||||
'append_only' : [],
|
'append_only': [],
|
||||||
},
|
},
|
||||||
'lua': {
|
'lua': {
|
||||||
'filename': 'if_lua.txt',
|
'filename': 'if_lua.txt',
|
||||||
'section_start_token': '*lua-vim*',
|
'section_start_token': '*lua-vim*',
|
||||||
'section_order' : [
|
'section_order': [
|
||||||
'vim.lua',
|
'vim.lua',
|
||||||
'shared.lua',
|
'shared.lua',
|
||||||
],
|
],
|
||||||
@@ -99,9 +99,10 @@ CONFIG = {
|
|||||||
'func_name_prefix': '',
|
'func_name_prefix': '',
|
||||||
'section_name': {},
|
'section_name': {},
|
||||||
'module_override': {
|
'module_override': {
|
||||||
'shared': 'vim', # `shared` functions are exposed on the `vim` module.
|
# `shared` functions are exposed on the `vim` module.
|
||||||
|
'shared': 'vim',
|
||||||
},
|
},
|
||||||
'append_only' : [
|
'append_only': [
|
||||||
'shared.lua',
|
'shared.lua',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -121,6 +122,7 @@ annotation_map = {
|
|||||||
# deprecated functions.
|
# deprecated functions.
|
||||||
xrefs = set()
|
xrefs = set()
|
||||||
|
|
||||||
|
|
||||||
def debug_this(s, n):
|
def debug_this(s, n):
|
||||||
o = n if isinstance(n, str) else n.toprettyxml(indent=' ', newl='\n')
|
o = n if isinstance(n, str) else n.toprettyxml(indent=' ', newl='\n')
|
||||||
name = '' if isinstance(n, str) else n.nodeName
|
name = '' if isinstance(n, str) else n.nodeName
|
||||||
@@ -191,7 +193,7 @@ def len_lastline(text):
|
|||||||
if -1 == lastnl:
|
if -1 == lastnl:
|
||||||
return len(text)
|
return len(text)
|
||||||
if '\n' == text[-1]:
|
if '\n' == text[-1]:
|
||||||
return lastnl - (1+ text.rfind('\n', 0, lastnl))
|
return lastnl - (1 + text.rfind('\n', 0, lastnl))
|
||||||
return len(text) - (1 + lastnl)
|
return len(text) - (1 + lastnl)
|
||||||
|
|
||||||
|
|
||||||
@@ -209,6 +211,7 @@ def is_inline(n):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def doc_wrap(text, prefix='', width=70, func=False, indent=None):
|
def doc_wrap(text, prefix='', width=70, func=False, indent=None):
|
||||||
"""Wraps text to `width`.
|
"""Wraps text to `width`.
|
||||||
|
|
||||||
@@ -237,8 +240,8 @@ def doc_wrap(text, prefix='', width=70, func=False, indent=None):
|
|||||||
if indent_only:
|
if indent_only:
|
||||||
prefix = indent
|
prefix = indent
|
||||||
|
|
||||||
tw = textwrap.TextWrapper(break_long_words = False,
|
tw = textwrap.TextWrapper(break_long_words=False,
|
||||||
break_on_hyphens = False,
|
break_on_hyphens=False,
|
||||||
width=width,
|
width=width,
|
||||||
initial_indent=prefix,
|
initial_indent=prefix,
|
||||||
subsequent_indent=indent)
|
subsequent_indent=indent)
|
||||||
@@ -293,6 +296,8 @@ def render_params(parent, width=62):
|
|||||||
return out.rstrip()
|
return out.rstrip()
|
||||||
|
|
||||||
# Renders a node as Vim help text, recursively traversing all descendants.
|
# Renders a node as Vim help text, recursively traversing all descendants.
|
||||||
|
|
||||||
|
|
||||||
def render_node(n, text, prefix='', indent='', width=62):
|
def render_node(n, text, prefix='', indent='', width=62):
|
||||||
text = ''
|
text = ''
|
||||||
# space_preceding = (len(text) > 0 and ' ' == text[-1][-1])
|
# space_preceding = (len(text) > 0 and ' ' == text[-1][-1])
|
||||||
@@ -317,7 +322,9 @@ def render_node(n, text, prefix='', indent='', width=62):
|
|||||||
text += ' [verbatim] {}'.format(get_text(n))
|
text += ' [verbatim] {}'.format(get_text(n))
|
||||||
elif n.nodeName == 'listitem':
|
elif n.nodeName == 'listitem':
|
||||||
for c in n.childNodes:
|
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'):
|
elif n.nodeName in ('para', 'heading'):
|
||||||
for c in n.childNodes:
|
for c in n.childNodes:
|
||||||
text += render_node(c, text, indent=indent, width=width)
|
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')))
|
n.nodeName, n.toprettyxml(indent=' ', newl='\n')))
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
def render_para(parent, indent='', width=62):
|
def render_para(parent, indent='', width=62):
|
||||||
"""Renders Doxygen <para> containing arbitrary nodes.
|
"""Renders Doxygen <para> containing arbitrary nodes.
|
||||||
|
|
||||||
@@ -407,11 +415,13 @@ def render_para(parent, indent='', width=62):
|
|||||||
if len(groups['return']) > 0:
|
if len(groups['return']) > 0:
|
||||||
chunks.append('\nReturn: ~')
|
chunks.append('\nReturn: ~')
|
||||||
for child in groups['return']:
|
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:
|
if len(groups['seealso']) > 0:
|
||||||
chunks.append('\nSee also: ~')
|
chunks.append('\nSee also: ~')
|
||||||
for child in groups['seealso']:
|
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']:
|
for child in groups['xrefs']:
|
||||||
title = get_text(get_child(child, 'xreftitle'))
|
title = get_text(get_child(child, 'xreftitle'))
|
||||||
xrefs.add(title)
|
xrefs.add(title)
|
||||||
@@ -587,6 +597,7 @@ def delete_lines_below(filename, tokenstr):
|
|||||||
with open(filename, 'wt') as fp:
|
with open(filename, 'wt') as fp:
|
||||||
fp.writelines(lines[0:i])
|
fp.writelines(lines[0:i])
|
||||||
|
|
||||||
|
|
||||||
def gen_docs(config):
|
def gen_docs(config):
|
||||||
"""Generate documentation.
|
"""Generate documentation.
|
||||||
|
|
||||||
@@ -619,7 +630,8 @@ def gen_docs(config):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
groupname = get_text(find_first(compound, 'name'))
|
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')
|
desc = find_first(minidom.parse(groupxml), 'detaileddescription')
|
||||||
if desc:
|
if desc:
|
||||||
@@ -680,12 +692,14 @@ def gen_docs(config):
|
|||||||
i = 0
|
i = 0
|
||||||
for filename in CONFIG[mode]['section_order']:
|
for filename in CONFIG[mode]['section_order']:
|
||||||
if filename not in sections:
|
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)
|
title, helptag, section_doc = sections.pop(filename)
|
||||||
i += 1
|
i += 1
|
||||||
if filename not in CONFIG[mode]['append_only']:
|
if filename not in CONFIG[mode]['append_only']:
|
||||||
docs += sep
|
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 += section_doc
|
||||||
docs += '\n\n\n'
|
docs += '\n\n\n'
|
||||||
|
|
||||||
|
@@ -63,10 +63,10 @@ fname = sys.argv[1]
|
|||||||
try:
|
try:
|
||||||
filt = sys.argv[2]
|
filt = sys.argv[2]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
filt = lambda entry: True
|
def filt(entry): return True
|
||||||
else:
|
else:
|
||||||
_filt = filt
|
_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))
|
poswidth = len(str(os.stat(fname).st_size or 1000))
|
||||||
|
|
||||||
|
@@ -97,7 +97,8 @@ def main(progname, cfname, only_static, move_all):
|
|||||||
if not generated_existed:
|
if not generated_existed:
|
||||||
lines[include_line:include_line] = [
|
lines[include_line:include_line] = [
|
||||||
'#ifdef INCLUDE_GENERATED_DECLARATIONS\n',
|
'#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',
|
'#endif\n',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user