devutils/lint: fix pylint errors

This commit is contained in:
jj
2025-07-28 11:24:32 +00:00
parent b2ea2d84bd
commit 9d9d4479ae
2 changed files with 22 additions and 17 deletions

View File

@@ -1,9 +1,9 @@
# pylint: disable=missing-function-docstring,invalid-name,global-statement,missing-module-docstring
# Copyright 2025 The Helium Authors
# You can use, redistribute, and/or modify this source code under
# the terms of the GPL-3.0 license that can be found in the LICENSE file.
from third_party import unidiff
from pathlib import Path
LICENSE_HEADER_IGNORES = ["html", "license", "readme"]
@@ -12,7 +12,7 @@ series = None
def _read_text(path):
with open(patches_dir / path, "r") as f:
with open(patches_dir / path, "r", encoding="utf-8") as f:
return filter(str, f.read().splitlines())
@@ -23,13 +23,13 @@ def _init(root):
series = set(_read_text("series"))
def a_all_patches_in_series_exist(root):
def a_all_patches_in_series_exist():
for patch in series:
assert (patches_dir / patch).is_file(), \
f"{patch} is in series, but does not exist in the source tree"
def a_all_patches_in_tree_are_in_series(root):
def a_all_patches_in_tree_are_in_series():
for patch in patches_dir.rglob('*'):
if not patch.is_file() or patch == patches_dir / "series":
continue
@@ -38,13 +38,13 @@ def a_all_patches_in_tree_are_in_series(root):
f"{patch} exists in source tree, but is not included in the series"
def b_all_patches_have_meaningful_contents(root):
def b_all_patches_have_meaningful_contents():
for patch in series:
assert any(map(lambda l: l.startswith('+++ '), _read_text(patch))), \
assert any(l.startswith('+++ ') for l in _read_text(patch)), \
f"{patch} does not have any meaningful content"
def b_all_patches_have_no_trailing_whitespace(root):
def b_all_patches_have_no_trailing_whitespace():
for patch in series:
for i, line in enumerate(_read_text(patch)):
if not line.startswith('+ '):
@@ -54,7 +54,7 @@ def b_all_patches_have_no_trailing_whitespace(root):
f"{patch} contains trailing whitespace on line {i + 1}"
def c_all_new_files_have_license_header(root):
def c_all_new_files_have_license_header():
for patch in series:
if 'helium' not in patch:
continue
@@ -63,16 +63,16 @@ def c_all_new_files_have_license_header(root):
added_files = filter(lambda f: f.is_added_file, patch_set)
for file in added_files:
if any(map(lambda p: p in file.path.lower(), LICENSE_HEADER_IGNORES)):
if any(p in file.path.lower() for p in LICENSE_HEADER_IGNORES):
continue
# TODO: convert into assert once all of them are resolved
if not any(map(lambda hunk: 'terms of the GPL-3.0 license' in str(hunk), file)):
if not any('terms of the GPL-3.0 license' in str(hunk) for hunk in file):
print(
f"File {file.path} was added in {patch}, but contains no Helium license header")
def c_all_new_headers_have_correct_guard(root):
def c_all_new_headers_have_correct_guard():
for patch in series:
if 'helium' not in patch:
continue
@@ -112,5 +112,6 @@ def c_all_new_headers_have_correct_guard(root):
# TODO: convert into assert once all of them are resolved
for macro_type, value in found.items():
if value != f"+{expected[macro_type]}":
value_print = (value or '(none)').rstrip()
print(f"Patch {patch} has unexpected {macro_type} in {file.path}:")
print(f"{(value or "(none)").rstrip()}, expecting: {expected[macro_type].rstrip()}")
print(f"{value_print}, expecting: {expected[macro_type].rstrip()}")

View File

@@ -3,37 +3,41 @@
# Copyright 2025 The Helium Authors
# You can use, redistribute, and/or modify this source code under
# the terms of the GPL-3.0 license that can be found in the LICENSE file.
"""Script to run sanity checks against the Helium patchset."""
import sys
import inspect
import argparse
import _lint_tests
from pathlib import Path
import _lint_tests
def parse_args():
"""Parses the CLI arguments."""
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--tree', help='root of the source tree to check')
return parser.parse_args()
def main():
"""CLI entrypoint for executing tests"""
args = parse_args()
root_dir = (Path(__file__).parent / "..").resolve()
if args.tree:
root_dir = Path(args.tree).resolve()
_lint_tests._init(root_dir)
_lint_tests._init(root_dir) # pylint: disable=protected-access
for name, fn in inspect.getmembers(_lint_tests, inspect.isfunction):
for name, func in inspect.getmembers(_lint_tests, inspect.isfunction):
if name.startswith("_"):
continue
try:
fn(root_dir)
func()
print(f"[OK] {name}")
except Exception as e:
except Exception:
print(f"[ERR] {name}:", file=sys.stderr)
raise