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 <[email protected]>
---
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
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#193499):
https://lists.openembedded.org/g/openembedded-core/message/193499
Mute This Topic: https://lists.openembedded.org/mt/103639917/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-