utils/check-package: cleanup line reading
PATCH v2 1/1 utils/check-package: cleanup line reading
Cleanup the implementation for reading lines by having files processed in context managers and utilizing the iterable file object for line reading (instead of needing to call readlines()).
---
Changes v1 -> v2:
- This change drops the use of an fstate instance which should not have been added in this initial/first patch (of a four-patch series). (mentioned by Thomas Petazzoni)
- Only this first patch is being resubmitted as this first patch can be applied by itself and the remaining patches are in discussion.
--- utils/check-package | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
utils/check-package +12 -10
@@ -233,16 +233,18 @@ def check_file_using_lib(fname): nwarnings += warn lastline = "" - for lineno, text in enumerate(open(fname, "r", errors="surrogateescape").readlines()): - nlines += 1 - for name, cf in objects: - if cf.disable.search(lastline): - continue - warn, fail = print_warnings(cf.check_line(lineno + 1, text), name in xfail) - if fail > 0: - failed.add(name) - nwarnings += warn - lastline = text + with open(fname, "r", errors="surrogateescape") as f: + for lineno, text in enumerate(f): + nlines += 1 + for name, cf in objects: + if cf.disable.search(lastline): + continue + line_sts = cf.check_line(lineno + 1, text) + warn, fail = print_warnings(line_sts, name in xfail) + if fail > 0: + failed.add(name) + nwarnings += warn + lastline = text for name, cf in objects: warn, fail = print_warnings(cf.after(), name in xfail)
Signature · 6 lines
2.40.1.windows.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Petazzoni via buildroot
AppliedQuoted 12 lines · On Sat, 2 Sep 2023 08:47:49 -0400 James Knight <[email protected]> wrote:
Cleanup the implementation for reading lines by having files processed in context managers and utilizing the iterable file object for line reading (instead of needing to call
readlines()).Signed-off-by James Knight <[email protected]>---
Changes v1 -> v2:
- This change drops the use of anfstateinstance which should not have been added in this initial/first patch (of a four-patch series). (mentioned by Thomas Petazzoni)
- Only this first patch is being resubmitted as this first patch can be applied by itself and the remaining patches are in discussion.
Quoted 3 lines
--- utils/check-package | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
Applied to next, thanks.
Thomas
Signature · 7 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot