check-version-history: apply "ruff format" and "ruff check --fix"
This commit is contained in:
@@ -20,17 +20,14 @@ def find_undocumented_functions(pages, ignorelist):
|
|||||||
filename = os.path.basename(page)
|
filename = os.path.basename(page)
|
||||||
pagetree = tree.parse(page)
|
pagetree = tree.parse(page)
|
||||||
|
|
||||||
assert pagetree.getroot().tag == "refentry"
|
assert pagetree.getroot().tag == 'refentry'
|
||||||
|
|
||||||
hist_section = pagetree.find("refsect1[title='History']")
|
hist_section = pagetree.find("refsect1[title='History']")
|
||||||
for func in pagetree.findall(".//funcprototype/funcdef/function"):
|
for func in pagetree.findall('.//funcprototype/funcdef/function'):
|
||||||
path = f"./refsynopsisdiv/funcsynopsis/funcprototype/funcdef/function[.='{func.text}']"
|
path = f"./refsynopsisdiv/funcsynopsis/funcprototype/funcdef/function[.='{func.text}']"
|
||||||
assert pagetree.findall(path) == [func]
|
assert pagetree.findall(path) == [func]
|
||||||
|
|
||||||
if (
|
if hist_section is None or hist_section.find(f"para/function[.='{func.text}()']") is None:
|
||||||
hist_section is None
|
|
||||||
or hist_section.find(f"para/function[.='{func.text}()']") is None
|
|
||||||
):
|
|
||||||
if func.text not in ignorelist:
|
if func.text not in ignorelist:
|
||||||
undocumented.append((filename, func.text))
|
undocumented.append((filename, func.text))
|
||||||
return undocumented
|
return undocumented
|
||||||
@@ -39,22 +36,22 @@ def find_undocumented_functions(pages, ignorelist):
|
|||||||
def construct_path(element):
|
def construct_path(element):
|
||||||
tag = element.tag
|
tag = element.tag
|
||||||
|
|
||||||
if tag == "refentry":
|
if tag == 'refentry':
|
||||||
return "."
|
return '.'
|
||||||
|
|
||||||
predicate = ""
|
predicate = ''
|
||||||
if tag == "varlistentry":
|
if tag == 'varlistentry':
|
||||||
text = "".join(element.find("term").itertext())
|
text = ''.join(element.find('term').itertext())
|
||||||
predicate = f'[term="{text}"]'
|
predicate = f'[term="{text}"]'
|
||||||
elif tag.startswith("refsect"):
|
elif tag.startswith('refsect'):
|
||||||
text = "".join(element.find("title").itertext())
|
text = ''.join(element.find('title').itertext())
|
||||||
predicate = f'[title="{text}"]'
|
predicate = f'[title="{text}"]'
|
||||||
elif tag == "variablelist":
|
elif tag == 'variablelist':
|
||||||
varlists = element.getparent().findall(tag)
|
varlists = element.getparent().findall(tag)
|
||||||
if len(varlists) > 1:
|
if len(varlists) > 1:
|
||||||
predicate = f"[{varlists.index(element)+1}]"
|
predicate = f'[{varlists.index(element) + 1}]'
|
||||||
|
|
||||||
return construct_path(element.getparent()) + "/" + tag + predicate
|
return construct_path(element.getparent()) + '/' + tag + predicate
|
||||||
|
|
||||||
|
|
||||||
def find_undocumented_commands(pages, ignorelist):
|
def find_undocumented_commands(pages, ignorelist):
|
||||||
@@ -63,23 +60,21 @@ def find_undocumented_commands(pages, ignorelist):
|
|||||||
filename = os.path.basename(page)
|
filename = os.path.basename(page)
|
||||||
|
|
||||||
pagetree = tree.parse(page)
|
pagetree = tree.parse(page)
|
||||||
if pagetree.getroot().tag != "refentry":
|
if pagetree.getroot().tag != 'refentry':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for varlistentry in pagetree.findall("*//variablelist/varlistentry"):
|
for varlistentry in pagetree.findall('*//variablelist/varlistentry'):
|
||||||
path = construct_path(varlistentry)
|
path = construct_path(varlistentry)
|
||||||
|
|
||||||
assert pagetree.findall(path) == [varlistentry]
|
assert pagetree.findall(path) == [varlistentry]
|
||||||
|
|
||||||
listitem = varlistentry.find("listitem")
|
listitem = varlistentry.find('listitem')
|
||||||
parent = listitem if listitem is not None else varlistentry
|
parent = listitem if listitem is not None else varlistentry
|
||||||
|
|
||||||
rev = parent.getchildren()[-1]
|
rev = parent.getchildren()[-1]
|
||||||
if (
|
ignored_files = tuple(entry[1] for entry in ignorelist if entry[0] == filename)
|
||||||
rev.get("href") != "version-info.xml" and
|
if rev.get('href') != 'version-info.xml' and not path.startswith(ignored_files):
|
||||||
not path.startswith(tuple(entry[1] for entry in ignorelist if entry[0] == filename))
|
undocumented.append((filename, path))
|
||||||
):
|
|
||||||
undocumented.append((filename, path))
|
|
||||||
|
|
||||||
return undocumented
|
return undocumented
|
||||||
|
|
||||||
@@ -90,54 +85,44 @@ def process_pages(pages):
|
|||||||
|
|
||||||
for page in pages:
|
for page in pages:
|
||||||
filename = os.path.basename(page)
|
filename = os.path.basename(page)
|
||||||
if filename.startswith("org.freedesktop."): # dbus
|
if filename.startswith('org.freedesktop.'): # dbus
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if (
|
if filename.startswith('sd_') or filename.startswith('sd-') or filename.startswith('udev_'):
|
||||||
filename.startswith("sd_")
|
|
||||||
or filename.startswith("sd-")
|
|
||||||
or filename.startswith("udev_")
|
|
||||||
):
|
|
||||||
function_pages.append(page)
|
function_pages.append(page)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
command_pages.append(page)
|
command_pages.append(page)
|
||||||
|
|
||||||
undocumented_commands = find_undocumented_commands(
|
undocumented_commands = find_undocumented_commands(command_pages, command_ignorelist)
|
||||||
command_pages, command_ignorelist
|
undocumented_functions = find_undocumented_functions(function_pages, function_ignorelist)
|
||||||
)
|
|
||||||
undocumented_functions = find_undocumented_functions(
|
|
||||||
function_pages, function_ignorelist
|
|
||||||
)
|
|
||||||
|
|
||||||
return undocumented_commands, undocumented_functions
|
return undocumented_commands, undocumented_functions
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == '__main__':
|
||||||
with open(os.path.join(os.path.dirname(__file__), "command_ignorelist")) as f:
|
with open(os.path.join(os.path.dirname(__file__), 'command_ignorelist')) as f:
|
||||||
command_ignorelist = []
|
command_ignorelist = []
|
||||||
for l in f.read().splitlines():
|
for line in f.read().splitlines():
|
||||||
if l.startswith("#"):
|
if line.startswith('#'):
|
||||||
continue
|
continue
|
||||||
fname, path = l.split(" ", 1)
|
fname, path = line.split(' ', 1)
|
||||||
path = path.replace("\\n", "\n")
|
path = path.replace('\\n', '\n')
|
||||||
command_ignorelist.append((fname, path))
|
command_ignorelist.append((fname, path))
|
||||||
with open(os.path.join(os.path.dirname(__file__), "function_ignorelist")) as f:
|
with open(os.path.join(os.path.dirname(__file__), 'function_ignorelist')) as f:
|
||||||
function_ignorelist = f.read().splitlines()
|
function_ignorelist = f.read().splitlines()
|
||||||
|
|
||||||
undocumented_commands, undocumented_functions = process_pages(sys.argv[1:])
|
undocumented_commands, undocumented_functions = process_pages(sys.argv[1:])
|
||||||
|
|
||||||
if undocumented_commands or undocumented_functions:
|
if undocumented_commands or undocumented_functions:
|
||||||
for filename, func in undocumented_functions:
|
for filename, func in undocumented_functions:
|
||||||
print(
|
print(f"Function {func}() in {filename} isn't documented in the History section.")
|
||||||
f"Function {func}() in {filename} isn't documented in the History section."
|
|
||||||
)
|
|
||||||
for filename, path in undocumented_commands:
|
for filename, path in undocumented_commands:
|
||||||
print(filename, path, "is undocumented")
|
print(filename, path, 'is undocumented')
|
||||||
if undocumented_commands:
|
if undocumented_commands:
|
||||||
print(
|
print(
|
||||||
"Hint: if you reorganized this part of the documentation, "
|
'Hint: if you reorganized this part of the documentation, '
|
||||||
"please update tools/commands_ignorelist."
|
'please update tools/commands_ignorelist.'
|
||||||
)
|
)
|
||||||
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user