from __future__ import annotations import sys from pathlib import Path import os # Ensure local vendored toolchain modules are importable in tests. repo_root = Path(__file__).resolve().parents[1] sys.path.insert(0, str(repo_root)) vendor_path = repo_root / "vendor" if vendor_path.is_dir(): sys.path.insert(0, str(vendor_path)) # Ensure local libs (e.g., kneronnxopt) are importable in tests. libs_path = repo_root / "libs" if libs_path.is_dir(): sys.path.insert(0, str(libs_path)) # Ensure kneronnxopt package resolves to its inner module directory. kneronnxopt_path = repo_root / "libs" / "kneronnxopt" if kneronnxopt_path.is_dir(): sys.path.insert(0, str(kneronnxopt_path)) # Ensure E2E python_flow (kneron_inference) is importable in tests. e2e_flow_path = repo_root / "E2E_Simulator" / "python_flow" if e2e_flow_path.is_dir(): sys.path.insert(0, str(e2e_flow_path)) # Prefer local prebuild binaries to avoid docker-only toolchain checks in sys_flow. prebuild_path = repo_root / "toolchain" / "prebuild" if prebuild_path.is_dir(): os.environ.setdefault("USE_PREBUILD", str(prebuild_path)) prebuild_lib = prebuild_path / "lib" if prebuild_lib.is_dir(): existing_ld = os.environ.get("LD_LIBRARY_PATH", "") ld_parts = [str(prebuild_lib)] if existing_ld: ld_parts.append(existing_ld) os.environ["LD_LIBRARY_PATH"] = ":".join(ld_parts) # Force pytest/tempfile to use repo-local temp dir instead of system /tmp. repo_tmp = repo_root / ".tmp" repo_tmp.mkdir(parents=True, exist_ok=True) os.environ.setdefault("TMPDIR", str(repo_tmp)) # Avoid multiprocessing Manager sockets in restricted test environments. os.environ.setdefault("KTC_DISABLE_MP", "1")