public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
* [PATCH] oeqa parselogs.py: load ignore files from sys.path
@ 2024-01-10 13:03 Mikko Rapeli
  2024-01-10 14:01 ` [OE-core] " Ross Burton
  2024-02-27 14:34 ` Richard Purdie
  0 siblings, 2 replies; 5+ messages in thread
From: Mikko Rapeli @ 2024-01-10 13:03 UTC (permalink / raw)
  To: openembedded-core; +Cc: Mikko Rapeli

python import.resources open_text() loads files from the module paths
but this requires layers to set "addpylib ${LAYERDIR}/lib oeqa"
which is not needed to find the plain .py test files to run the tests.
Also an empty __init__.py file in a layer will break the resource file
loading completely as only that path with __init__.py file will
be used to search the resource files. Then open_text() is marked
as deprecated from python 3.11 onwards
https://docs.python.org/3/library/importlib.resources.html

So replace open_text() by iterating over sys.path to find the ignore
files. This works since paths like ${LAYERDIR}/lib/oeqa/runtime/cases are
already in sys.path. Add debug prints for found and not found files
while at it.

Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org>
---
 meta/lib/oeqa/runtime/cases/parselogs.py | 29 +++++++++++-------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/meta/lib/oeqa/runtime/cases/parselogs.py b/meta/lib/oeqa/runtime/cases/parselogs.py
index 6966923c94..47583dbb5d 100644
--- a/meta/lib/oeqa/runtime/cases/parselogs.py
+++ b/meta/lib/oeqa/runtime/cases/parselogs.py
@@ -6,27 +6,19 @@
 
 import collections
 import os
+import pathlib
 import sys
 
 from shutil import rmtree
 from oeqa.runtime.case import OERuntimeTestCase
 from oeqa.core.decorator.depends import OETestDepends
 
-# importlib.resources.open_text in Python <3.10 doesn't search all directories
-# when a package is split across multiple directories. Until we can rely on
-# 3.10+, reimplement the searching logic.
-if sys.version_info < (3, 10):
-    def _open_text(package, resource):
-        import importlib, pathlib
-        module = importlib.import_module(package)
-        for path in module.__path__:
-            candidate = pathlib.Path(path) / resource
-            if candidate.exists():
-                return candidate.open(encoding='utf-8')
-        raise FileNotFoundError
-else:
-    from importlib.resources import open_text as _open_text
-
+def open_syspath_text(resource):
+    for path in sys.path:
+        candidate = pathlib.Path(path) / resource
+        if candidate.exists():
+            return candidate.open(encoding='utf-8')
+    raise FileNotFoundError
 
 class ParseLogsTest(OERuntimeTestCase):
 
@@ -61,11 +53,16 @@ class ParseLogsTest(OERuntimeTestCase):
         for candidate in ["common", cls.td.get("TARGET_ARCH")] + cls.td.get("MACHINEOVERRIDES").split(":"):
             try:
                 name = f"parselogs-ignores-{candidate}.txt"
-                for line in _open_text("oeqa.runtime.cases", name):
+                print_once = True
+                for line in open_syspath_text(name):
+                    if print_once:
+                        bb.debug(1, "parselogs: ignore file %s found" % (name))
+                        print_once = False
                     line = line.strip()
                     if line and not line.startswith("#"):
                         cls.ignore_errors.append(line.casefold())
             except FileNotFoundError:
+                bb.debug(1, "parselogs: ignore file %s not found" % (name))
                 pass
 
     # Go through the log locations provided and if it's a folder
-- 
2.34.1



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

end of thread, other threads:[~2024-02-27 14:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-10 13:03 [PATCH] oeqa parselogs.py: load ignore files from sys.path Mikko Rapeli
2024-01-10 14:01 ` [OE-core] " Ross Burton
2024-01-10 14:23   ` Mikko Rapeli
     [not found]   ` <17A9026E670466F3.1780@lists.openembedded.org>
2024-01-19  7:27     ` Mikko Rapeli
2024-02-27 14:34 ` Richard Purdie

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