Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v2 1/1] utils/check-package: cleanup line reading
@ 2023-09-02 12:47 James Knight
  2023-09-02 15:48 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 2+ messages in thread
From: James Knight @ 2023-09-02 12:47 UTC (permalink / raw)
  To: buildroot; +Cc: James Knight, Thomas Petazzoni, Ricardo Martincoski

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 <james.d.knight@live.com>
---
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(-)

diff --git a/utils/check-package b/utils/check-package
index 3de3a72e0c..105902303e 100755
--- a/utils/check-package
+++ b/utils/check-package
@@ -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)
-- 
2.40.1.windows.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-02 15:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-02 12:47 [Buildroot] [PATCH v2 1/1] utils/check-package: cleanup line reading James Knight
2023-09-02 15:48 ` Thomas Petazzoni via buildroot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox