From: Andrea Righi Date: Wed, 31 May 2023 13:32:51 +0000 (+0200) Subject: fix a bunch of pylint warnings X-Git-Tag: v0.1~20 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=6d88d1b3d9304e680a0f4493f6466c45d53ce999;p=annotations.git fix a bunch of pylint warnings Signed-off-by: Andrea Righi --- diff --git a/Makefile b/Makefile index 317440a..aa3f97f 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ all: lint lint: flake8 pylint flake8: - flake8 annotations . + flake8 sanitize-annotations annotations . pylint: - pylint annotations kconfig + pylint sanitize-annotations annotations kconfig diff --git a/kconfig/annotations.py b/kconfig/annotations.py index 078dcf2..e20a087 100644 --- a/kconfig/annotations.py +++ b/kconfig/annotations.py @@ -117,14 +117,14 @@ class Annotation(Config): entry['note'] = "'" + m.group(1).replace("'", '') + "'" if not match: - raise Exception('syntax error') + raise SyntaxError('syntax error') self.config[conf] = entry except Exception as e: - raise Exception(str(e) + f', line = {line}') from e + raise SyntaxError(str(e) + f', line = {line}') from e continue # Invalid line - raise Exception(f'invalid line: {line}') + raise SyntaxError(f'invalid line: {line}') def _parse(self, data: str): """ @@ -162,9 +162,9 @@ class Annotation(Config): # Sanity check: Verify that all FLAVOUR_DEP flavors are valid for src, tgt in self.flavour_dep.items(): if src not in self.flavour: - raise Exception(f'Invalid source flavour in FLAVOUR_DEP: {src}') + raise SyntaxError(f'Invalid source flavour in FLAVOUR_DEP: {src}') if tgt not in self.include_flavour: - raise Exception(f'Invalid target flavour in FLAVOUR_DEP: {tgt}') + raise SyntaxError(f'Invalid target flavour in FLAVOUR_DEP: {tgt}') def _remove_entry(self, config: str): if self.config[config]: @@ -343,7 +343,7 @@ class Annotation(Config): old_val = tmp_a.config.get(conf) if old_val and 'policy' in old_val: if old_val['policy'] == old_val['policy'] | new_val['policy']: - if not 'note' in new_val: + if 'note' not in new_val: continue if 'note' in old_val and 'note' in new_val: if old_val['note'] == new_val['note']: diff --git a/sanitize-annotations b/sanitize-annotations new file mode 100755 index 0000000..2814f00 --- /dev/null +++ b/sanitize-annotations @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# +# Try to automatically sanitize an old "annotations" file, dropping all the +# deprecated flags, arbitrary enforcements rules, etc. +# +# Usage: +# $ ./sanitize-annotations debian.master/config/annotations + +import sys +import re + + +def remove_flags_and_drop_lines(file_path): + # Read the contents of the file + with open(file_path, "r", encoding="utf-8") as file: + content = file.read() + + # Check if the file has the required headers + lines = content.splitlines() + if ( + len(lines) < 2 + or lines[0].strip() != "# Menu: HEADER" + or lines[1].strip() != "# FORMAT: 4" + ): + print(f"ERROR: {file_path} doesn't have a valid header") + print("Fix the headers as explained here: " + + "https://docs.google.com/document/d/1NnGC2aknyy2TJWMsoYzhrZMr9rYMA09JQBEvC-LW_Lw/") + sys.exit(1) + + # Remove unsupported annotations + updated_content = re.sub(r"(flag|mark)<.*?>", "", content) + + # Drop lines with a single word and trailing spaces + updated_content = re.sub(r"^\w+\s*$", "", updated_content, flags=re.MULTILINE) + + # Add a space after all caps followed by 'policy' + updated_content = re.sub(r"([A-Z]+)(policy)", r"\1 \2", updated_content) + + # Add 'note' if missing + updated_content = re.sub(r"(\s+)(<.*?>)", r"\1note\2", updated_content) + + # Write the updated contents back to the file + with open(file_path, "w", encoding="utf-8") as file: + file.write(updated_content) + + +if __name__ == "__main__": + file_path = sys.argv[1] + remove_flags_and_drop_lines(file_path) diff --git a/sanitize-annotations.py b/sanitize-annotations.py deleted file mode 100755 index 1697126..0000000 --- a/sanitize-annotations.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python3 -# -# Try to automatically sanitize an old "annotations" file, dropping all the -# deprecated flags, arbitrary enforcements rules, etc. -# -# Usage: -# $ ./sanitize-annotations debian.master/config/annotations - -import sys -import re - -def remove_flags_and_drop_lines(file_path): - # Read the contents of the file - with open(file_path, 'r') as file: - content = file.read() - - # Check if the file has the required headers - lines = content.splitlines() - if len(lines) < 2 or lines[0].strip() != '# Menu: HEADER' or lines[1].strip() != '# FORMAT: 4': - print(f"ERROR: {file_path} doesn't have a valid header") - print("Fix the headers as explained here: https://docs.google.com/document/d/1NnGC2aknyy2TJWMsoYzhrZMr9rYMA09JQBEvC-LW_Lw/edit#heading=h.ug9cinnvjg89") - sys.exit(1) - - # Remove unsupported annotations - updated_content = re.sub(r'(flag|mark)<.*?>', '', content) - - # Drop lines with a single word and trailing spaces - updated_content = re.sub(r'^\w+\s*$', '', updated_content, flags=re.MULTILINE) - - # Add a space after all caps followed by 'policy' - updated_content = re.sub(r'([A-Z]+)(policy)', r'\1 \2', updated_content) - - # Add 'note' if missing - updated_content = re.sub(r'(\s+)(<.*?>)', r'\1note\2', updated_content) - - # Write the updated contents back to the file - with open(file_path, 'w') as file: - file.write(updated_content) - -if __name__ == '__main__': - file_path = sys.argv[1] - remove_flags_and_drop_lines(file_path)