|
|
@ -1,12 +1,13 @@
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
from os.path import basename, dirname, join, splitext
|
|
|
|
from os.path import basename, dirname, exists, join, splitext
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
SCRIPT_PATH = sys.argv[1] if len(sys.argv) > 1 else 'scripts'
|
|
|
|
SCRIPT_PATH = sys.argv[1] if len(sys.argv) > 1 else 'scripts'
|
|
|
|
|
|
|
|
DOCS_PATH = join(SCRIPT_PATH, 'docs')
|
|
|
|
IS_GITHUB_ACTIONS = bool(os.environ.get('GITHUB_ACTIONS'))
|
|
|
|
IS_GITHUB_ACTIONS = bool(os.environ.get('GITHUB_ACTIONS'))
|
|
|
|
|
|
|
|
|
|
|
|
def expected_cmd(path):
|
|
|
|
def get_cmd(path):
|
|
|
|
"""Get the command from the name of a script."""
|
|
|
|
"""Get the command from the name of a script."""
|
|
|
|
dname, fname = basename(dirname(path)), splitext(basename(path))[0]
|
|
|
|
dname, fname = basename(dirname(path)), splitext(basename(path))[0]
|
|
|
|
if dname in ('devel', 'fix', 'gui', 'modtools'):
|
|
|
|
if dname in ('devel', 'fix', 'gui', 'modtools'):
|
|
|
@ -14,16 +15,6 @@ def expected_cmd(path):
|
|
|
|
return fname
|
|
|
|
return fname
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_ls(fname, line):
|
|
|
|
|
|
|
|
"""Check length & existence of leading comment for "ls" builtin command."""
|
|
|
|
|
|
|
|
line = line.strip()
|
|
|
|
|
|
|
|
comment = '--' if fname.endswith('.lua') else '#'
|
|
|
|
|
|
|
|
if '[====[' in line or not line.startswith(comment):
|
|
|
|
|
|
|
|
print_error('missing leading comment (requred for `ls`)', fname)
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def print_error(message, filename, line=None):
|
|
|
|
def print_error(message, filename, line=None):
|
|
|
|
if not isinstance(line, int):
|
|
|
|
if not isinstance(line, int):
|
|
|
|
line = 1
|
|
|
|
line = 1
|
|
|
@ -32,48 +23,42 @@ def print_error(message, filename, line=None):
|
|
|
|
print('::error file=%s,line=%i::%s' % (filename, line, message))
|
|
|
|
print('::error file=%s,line=%i::%s' % (filename, line, message))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_ls(docfile, lines):
|
|
|
|
|
|
|
|
"""Check length & existence of first sentence for "ls" builtin command."""
|
|
|
|
|
|
|
|
# TODO
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_file(fname):
|
|
|
|
def check_file(fname):
|
|
|
|
errors, doclines = 0, []
|
|
|
|
errors, doc_start_line = 0, None
|
|
|
|
tok1, tok2 = ('=begin', '=end') if fname.endswith('.rb') else \
|
|
|
|
docfile = join(DOCS_PATH, get_cmd(fname)+'.rst')
|
|
|
|
('[====[', ']====]')
|
|
|
|
if not exists(docfile):
|
|
|
|
doc_start_line = None
|
|
|
|
print_error('missing documentation file: {!r}'.format(docfile), fname)
|
|
|
|
with open(fname, errors='ignore') as f:
|
|
|
|
return 1
|
|
|
|
|
|
|
|
with open(docfile, errors='ignore') as f:
|
|
|
|
lines = f.readlines()
|
|
|
|
lines = f.readlines()
|
|
|
|
if not lines:
|
|
|
|
if not lines:
|
|
|
|
print_error('empty file', fname)
|
|
|
|
print_error('empty documentation file', docfile)
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
errors += check_ls(fname, lines[0])
|
|
|
|
|
|
|
|
for i, l in enumerate(lines):
|
|
|
|
for i, l in enumerate(lines):
|
|
|
|
if doclines or l.strip().endswith(tok1):
|
|
|
|
l = l.strip()
|
|
|
|
if not doclines:
|
|
|
|
if l and not doc_start_line and doc_start_line != 0:
|
|
|
|
doc_start_line = i + 1
|
|
|
|
doc_start_line = i
|
|
|
|
doclines.append(l.rstrip())
|
|
|
|
doc_end_line = i
|
|
|
|
if l.startswith(tok2):
|
|
|
|
lines[i] = l
|
|
|
|
break
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
if doclines:
|
|
|
|
|
|
|
|
print_error('docs start but do not end', fname, doc_start_line)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
print_error('no documentation found', fname)
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not doclines:
|
|
|
|
|
|
|
|
print_error('missing or malformed documentation', fname)
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
title, underline = [d for d in doclines
|
|
|
|
errors += check_ls(docfile, lines)
|
|
|
|
if d and '=begin' not in d and '[====[' not in d][:2]
|
|
|
|
title, underline = lines[doc_start_line:doc_start_line+2]
|
|
|
|
title_line = doc_start_line + doclines.index(title)
|
|
|
|
|
|
|
|
expected_underline = '=' * len(title)
|
|
|
|
expected_underline = '=' * len(title)
|
|
|
|
if underline != expected_underline:
|
|
|
|
if underline != expected_underline:
|
|
|
|
print_error('title/underline mismatch: expected {!r}, got {!r}'.format(
|
|
|
|
print_error('title/underline mismatch: expected {!r}, got {!r}'.format(
|
|
|
|
expected_underline, underline),
|
|
|
|
expected_underline, underline),
|
|
|
|
fname, title_line + 1)
|
|
|
|
docfile, doc_start_line+1)
|
|
|
|
errors += 1
|
|
|
|
errors += 1
|
|
|
|
if title != expected_cmd(fname):
|
|
|
|
if title != get_cmd(fname):
|
|
|
|
print_error('expected script title {!r}, got {!r}'.format(
|
|
|
|
print_error('expected script title {!r}, got {!r}'.format(
|
|
|
|
expected_cmd(fname), title),
|
|
|
|
get_cmd(fname), title),
|
|
|
|
fname, title_line)
|
|
|
|
docfile, doc_start_line)
|
|
|
|
errors += 1
|
|
|
|
errors += 1
|
|
|
|
return errors
|
|
|
|
return errors
|
|
|
|
|
|
|
|
|
|
|
|