From f4e8cfa7d33f12e7ce1ba05c49bdf8984feaeb3c Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Mon, 11 Dec 2023 14:42:43 +0100 Subject: [PATCH] annotations: coding style fixes No functional changes, just some python / shell coding style fixes. Signed-off-by: Andrea Righi --- annotations | 1 - build-deb.sh | 6 +++--- kconfig/annotations.py | 9 +++++---- kconfig/run.py | 31 +++++++++++++++++++++---------- kconfig/sanitize.py | 15 +++++++++------ kconfig/version.py | 2 +- tests/test_todo_note.py | 1 - 7 files changed, 39 insertions(+), 26 deletions(-) diff --git a/annotations b/annotations index bddfe40..34d70da 100755 --- a/annotations +++ b/annotations @@ -5,7 +5,6 @@ # distribution without installing it in the system. import os -import sys from kconfig import run diff --git a/build-deb.sh b/build-deb.sh index 28e1d32..9107ddf 100755 --- a/build-deb.sh +++ b/build-deb.sh @@ -12,9 +12,9 @@ fi # Create upsteam tag deb_tag=$(dpkg-parsechangelog -S version | cut -d- -f1) -git tag upstream/${deb_tag} +git tag "upstream/${deb_tag}" -gbp buildpackage --git-ignore-branch $* +gbp buildpackage --git-ignore-branch "$@" # Undo packaging changes -git tag -d upstream/${deb_tag} +git tag -d "upstream/${deb_tag}" diff --git a/kconfig/annotations.py b/kconfig/annotations.py index 9b7152e..98121d9 100644 --- a/kconfig/annotations.py +++ b/kconfig/annotations.py @@ -166,10 +166,10 @@ class Annotation(Config): # Return an error if architectures are not defined if not self.arch: - raise SyntaxError(f"ARCH not defined in annotations") + raise SyntaxError("ARCH not defined in annotations") # Return an error if flavours are not defined if not self.flavour: - raise SyntaxError(f"FLAVOUR not defined in annotations") + raise SyntaxError("FLAVOUR not defined in annotations") # Parse body self._parse_body(data) @@ -224,7 +224,7 @@ class Annotation(Config): # format. try: self._legacy_parse(data) - except SyntaxError as e: + except SyntaxError: self._json_parse(data, is_included=False) def _remove_entry(self, config: str): @@ -305,7 +305,8 @@ class Annotation(Config): if val != old_val and "note" in self.config[conf]: self.config[conf]["note"] = "TODO: update note" print( - f"WARNING: {conf} changed from {old_val} to {val}, updating note" + f"WARNING: {conf} changed from {old_val} to {val}, " + "updating note" ) self.config[conf]["policy"][flavour] = val else: diff --git a/kconfig/run.py b/kconfig/run.py index 0f35772..5171dfc 100644 --- a/kconfig/run.py +++ b/kconfig/run.py @@ -6,10 +6,10 @@ import sys sys.dont_write_bytecode = True -import os -import argparse -import json -from signal import signal, SIGPIPE, SIG_DFL +import os # noqa: E402 Import not at top of file +import argparse # noqa: E402 Import not at top of file +import json # noqa: E402 Import not at top of file +from signal import signal, SIGPIPE, SIG_DFL # noqa: E402 Import not at top of file try: from argcomplete import autocomplete @@ -19,9 +19,18 @@ except ModuleNotFoundError: pass -from kconfig.annotations import Annotation, KConfig -from kconfig.utils import autodetect_annotations, arg_fail -from kconfig.version import VERSION, ANNOTATIONS_FORMAT_VERSION +from kconfig.annotations import ( # noqa: E402 Import not at top of file + Annotation, + KConfig, +) +from kconfig.utils import ( # noqa: E402 Import not at top of file + autodetect_annotations, + arg_fail, +) +from kconfig.version import ( # noqa: E402 Import not at top of file + VERSION, + ANNOTATIONS_FORMAT_VERSION, +) SKIP_CONFIGS = ( @@ -116,7 +125,8 @@ def make_parser(): action="store", metavar="FILE", dest="update_file", - help="Import a partial .config into annotations (only resync configs specified in FILE)", + help="Import a partial .config into annotations " + "(only resync configs specified in FILE)", ) ga.add_argument( "--check", @@ -154,7 +164,7 @@ def export_result(data): policy = data["config"][key]["policy"] if "note" in data["config"][key]: note = data["config"][key]["note"] - out += f' "{key}": {{"policy": {json.dumps(policy)}, "note": {json.dumps(note)}}},\n' + out += f' "{key}": {{"policy": {json.dumps(policy)}, "note": {json.dumps(note)}}},\n' # noqa: E501 Line too long else: out += f' "{key}": {{"policy": {json.dumps(policy)}}},\n' out = out.rstrip(",\n") @@ -330,7 +340,8 @@ def do_check(args): if ret: if os.path.exists(".git"): print( - f"check-config: {num} config options have been changed, review them with `git diff`" + f"check-config: {num} config options have been changed, " + "review them with `git diff`" ) else: print(f"check-config: {num} config options have changed") diff --git a/kconfig/sanitize.py b/kconfig/sanitize.py index f03b300..3a7da3e 100644 --- a/kconfig/sanitize.py +++ b/kconfig/sanitize.py @@ -7,12 +7,15 @@ import sys sys.dont_write_bytecode = True # pylint: disable=E0402 -import re -import argparse -from argcomplete import autocomplete - -from kconfig.utils import autodetect_annotations, arg_fail -from kconfig.version import VERSION +import re # noqa: E402 Import not at top of file +import argparse # noqa: E402 Import not at top of file +from argcomplete import autocomplete # noqa: E402 Import not at top of file + +from kconfig.utils import ( # noqa: E402 Import not at top of file + autodetect_annotations, + arg_fail, +) +from kconfig.version import VERSION # noqa: E402 Import not at top of file def make_parser(): diff --git a/kconfig/version.py b/kconfig/version.py index da64538..833ffa3 100644 --- a/kconfig/version.py +++ b/kconfig/version.py @@ -6,5 +6,5 @@ VERSION = "0.1" ANNOTATIONS_FORMAT_VERSION = 5 -if __name__ == '__main__': +if __name__ == "__main__": print(VERSION) diff --git a/tests/test_todo_note.py b/tests/test_todo_note.py index 61e5611..30b8c12 100644 --- a/tests/test_todo_note.py +++ b/tests/test_todo_note.py @@ -1,5 +1,4 @@ import unittest -import json from tests import utils -- 2.31.1