From 7bf946dabe97ce0a12ca66fe6ec906d3743eece1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Thu, 7 May 2026 10:05:00 +0200 Subject: [PATCH] py_func/__main__: robust sys.path + diagnostic on import failure Insert str() parent dir at sys.path[0] (was appending a Path object); exception handler prints sys.executable and sys.path. --- src/testium/py_func/__main__.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/testium/py_func/__main__.py b/src/testium/py_func/__main__.py index 8ac1782..412495e 100644 --- a/src/testium/py_func/__main__.py +++ b/src/testium/py_func/__main__.py @@ -8,16 +8,20 @@ def exception_handler(typ_exc, value, trbk): print(f"Critical failure : '{value}'.") tb = traceback.format_exception(typ_exc, value, trbk) print("".join(tb)) + print(f" python : {sys.executable}") + print(f" sys.path : {sys.path}") sys.excepthook = exception_handler -p = Path(__file__) -p = p.parent / ".." -p = p.resolve() - -sys.path.append(p) +# Make the parent directory of py_func/ (= the testium package dir, which also +# contains runtime/, lua_func/, …) the first entry on sys.path so `from py_func +# import main` and `from runtime…` resolve regardless of cwd or how this script +# was invoked. str() because some importers don't play well with PathLike entries. +_pkg_parent = str((Path(__file__).resolve().parent / "..").resolve()) +if _pkg_parent not in sys.path: + sys.path.insert(0, _pkg_parent) from py_func import main if __name__ == '__main__': - main() \ No newline at end of file + main()