Changeset View
Changeset View
Standalone View
Standalone View
test/lint/check-doc.py
Show All 10 Lines | |||||
Author: @MarcoFalke | Author: @MarcoFalke | ||||
''' | ''' | ||||
from subprocess import check_output | from subprocess import check_output | ||||
from pprint import PrettyPrinter | from pprint import PrettyPrinter | ||||
import re | import re | ||||
FOLDER_SRC = 'src' | FOLDER_SRC = 'src' | ||||
FOLDER_TEST = 'src/test/' | FOLDER_TEST = 'test' | ||||
PATH_SRC = '`git rev-parse --show-toplevel`/{}'.format(FOLDER_SRC) | PATH_SRC = '`git rev-parse --show-toplevel`/{}'.format(FOLDER_SRC) | ||||
PATH_TEST = '`git rev-parse --show-toplevel`/{}'.format(FOLDER_TEST) | |||||
GREP_ARGS_REGEX = r"egrep -rIzo '((Is|Get)(Bool)?Arg(s|Set)?\((\s)*)\"\-[^\"]+?\"' {}" | REGEX_ARG = '(?:ForceSet|SoftSet|Get|Is)(?:Bool)?Args?(?:Set)?\(\s*"(-[^"]+)"' | ||||
CMD_GREP_ARGS_SRC = GREP_ARGS_REGEX.format(PATH_SRC) | REGEX_DOC = 'HelpMessageOpt\(\s*"(-[^"=]+?)(?:=|")' | ||||
CMD_GREP_ARGS_TEST = GREP_ARGS_REGEX.format(PATH_TEST) | |||||
CMD_GREP_DOCS = r"egrep -rIzo 'HelpMessageOpt\((\s)*\"\-[^\"=]+?(=|\")' {}".format( | CMD_GREP_ARGS_SRC = r"grep -rIPzo '{}' {} --exclude-dir={}".format( | ||||
PATH_SRC) | REGEX_ARG, PATH_SRC, FOLDER_TEST) | ||||
CMD_GREP_DOCS = r"grep -rIPzo '{}' {}".format(REGEX_DOC, PATH_SRC) | |||||
REGEX_ARG = re.compile( | |||||
r'(?:(?:Is|Get)(?:Bool)?Arg(?:s|Set)?\((?:\s)*)\"(\-[^\"]+?)\"') | |||||
REGEX_DOC = re.compile(r'HelpMessageOpt\((?:\s)*\"(\-[^\"=]+?)(?:=|\")') | |||||
# list unsupported, deprecated and duplicate args as they need no documentation | # list unsupported, deprecated and duplicate args as they need no documentation | ||||
SET_DOC_OPTIONAL = set(['-benchmark', | SET_DOC_OPTIONAL = set(['-benchmark', | ||||
'-blockminsize', | '-blockminsize', | ||||
'-dbcrashratio', | '-dbcrashratio', | ||||
'-debugnet', | '-debugnet', | ||||
'-forcecompactdb', | '-forcecompactdb', | ||||
# TODO remove after the may 2019 fork | # TODO remove after the may 2019 fork | ||||
'-greatwallactivationtime', | '-greatwallactivationtime', | ||||
'-h', | |||||
'-help', | '-help', | ||||
'-parkdeepreorg', | '-parkdeepreorg', | ||||
'-promiscuousmempoolflags', | '-promiscuousmempoolflags', | ||||
'-replayprotectionactivationtime', | '-replayprotectionactivationtime', | ||||
'-rpcssl', | '-rpcssl', | ||||
'-socks', | '-socks', | ||||
'-tor', | '-tor', | ||||
'-whitelistalwaysrelay']) | '-whitelistalwaysrelay']) | ||||
# list false positive unknows arguments | # list false positive unknows arguments | ||||
SET_FALSE_POSITIVE_UNKNOWNS = set(['-nodebug', | SET_FALSE_POSITIVE_UNKNOWNS = set(['-nodebug', | ||||
'-zmqpubhashblock', | '-zmqpubhashblock', | ||||
'-zmqpubhashtx', | '-zmqpubhashtx', | ||||
'-zmqpubrawblock', | '-zmqpubrawblock', | ||||
'-zmqpubrawtx']) | '-zmqpubrawtx']) | ||||
def main(): | def main(): | ||||
used = check_output(CMD_GREP_ARGS_SRC, shell=True).decode() | used = check_output(CMD_GREP_ARGS_SRC, shell=True).decode() | ||||
tested = check_output(CMD_GREP_ARGS_TEST, shell=True).decode() | |||||
docd = check_output(CMD_GREP_DOCS, shell=True).decode() | docd = check_output(CMD_GREP_DOCS, shell=True).decode() | ||||
args_used = set(re.findall(REGEX_ARG, used)) | args_used = set(re.findall(REGEX_ARG, used)) | ||||
args_used -= set(re.findall(REGEX_ARG, tested)) | |||||
args_used |= SET_FALSE_POSITIVE_UNKNOWNS | args_used |= SET_FALSE_POSITIVE_UNKNOWNS | ||||
args_docd = set(re.findall(REGEX_DOC, docd)) | args_docd = set(re.findall(REGEX_DOC, docd)) | ||||
args_need_doc = args_used - args_docd - SET_DOC_OPTIONAL | args_need_doc = args_used - args_docd - SET_DOC_OPTIONAL | ||||
args_unknown = args_docd - args_used | args_unknown = args_docd - args_used | ||||
pp = PrettyPrinter() | pp = PrettyPrinter() | ||||
print("Args used : {}".format(len(args_used))) | print("Args used : {}".format(len(args_used))) | ||||
print("Args documented : {}".format(len(args_docd))) | print("Args documented : {}".format(len(args_docd))) | ||||
Show All 9 Lines |