faster linux build
This commit is contained in:
+19
-2
@@ -22,8 +22,25 @@ import pytest
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
SRC_ROOT = REPO_ROOT / "src"
|
||||
if str(SRC_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(SRC_ROOT))
|
||||
BUILD_ROOT = REPO_ROOT / "build"
|
||||
EXAMPLES_ROOT = REPO_ROOT / "examples"
|
||||
|
||||
# Establish import precedence once, here, before any test module is imported. The
|
||||
# test modules insert the same directories, but all of those inserts are guarded
|
||||
# by `if path not in sys.path`, so once the paths are present the guards turn
|
||||
# them into no-ops and this order sticks.
|
||||
#
|
||||
# Order matters and is not incidental:
|
||||
# * examples/ must win over build/ because `build/gui` is also a package named
|
||||
# `gui`; with build/ first, `import gui.viewer2d` silently resolves to the
|
||||
# build tooling and fails.
|
||||
# * build/ must precede site-packages so `wheel`, `common` and `release` mean
|
||||
# the repository's build tooling, not the unrelated PyPI `wheel` package.
|
||||
# * src/ provides the checkout's `orisys`.
|
||||
# Insert in reverse priority (each insert goes to the front).
|
||||
for _path in (SRC_ROOT, BUILD_ROOT, EXAMPLES_ROOT):
|
||||
if str(_path) not in sys.path:
|
||||
sys.path.insert(0, str(_path))
|
||||
|
||||
from orisys import Sensor
|
||||
from orisys import configs as orisys_configs
|
||||
|
||||
@@ -93,6 +93,32 @@ def test_fixtures_are_registered_with_pytest(request):
|
||||
)
|
||||
|
||||
|
||||
def test_import_precedence_is_correct():
|
||||
"""examples/ must beat build/ for `gui`; build/ must beat site-packages.
|
||||
|
||||
Regression guard: build/gui is a package named `gui`, so if build/ precedes
|
||||
examples/ on sys.path then `import gui.viewer2d` resolves to the build
|
||||
tooling and tests/test_qt_viewer_backend.py fails at collection.
|
||||
"""
|
||||
import common
|
||||
import gui
|
||||
import wheel
|
||||
|
||||
examples_gui = (REPO_ROOT / "examples" / "gui").resolve()
|
||||
build_root = (REPO_ROOT / "build").resolve()
|
||||
|
||||
assert Path(gui.__file__).resolve().parent == examples_gui, (
|
||||
f"`gui` resolved to {gui.__file__} instead of {examples_gui}; "
|
||||
"examples/ must precede build/ on sys.path"
|
||||
)
|
||||
for module in (common, wheel):
|
||||
resolved = Path(module.__file__).resolve()
|
||||
assert build_root in resolved.parents, (
|
||||
f"`{module.__name__}` resolved to {resolved}, outside {build_root}; "
|
||||
"build/ must precede site-packages on sys.path"
|
||||
)
|
||||
|
||||
|
||||
def test_tests_run_against_checkout_not_stale_install():
|
||||
"""Fail loudly when an old orisys in site-packages shadows src/orisys."""
|
||||
src_pkg = (REPO_ROOT / "src" / "orisys").resolve()
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
"""Every third-party import in src/orisys must be excluded from the Nuitka compile.
|
||||
|
||||
Omitting one means Nuitka tries to follow it into the compiled extension: compile
|
||||
time explodes, and the wheel's contents start depending on whatever happens to be
|
||||
installed in the *build* environment rather than on what is declared. ``torch``,
|
||||
``torchvision`` and ``pyvkfft`` were imported by the package but missing from the
|
||||
exclusion list; this test keeps that list complete.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
BUILD_ROOT = REPO_ROOT / "build"
|
||||
if str(BUILD_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(BUILD_ROOT))
|
||||
|
||||
from wheel.compile import NUITKA_INCLUDE_PACKAGES, NUITKA_NOFOLLOW_IMPORTS # noqa: E402
|
||||
|
||||
PACKAGE_ROOT = REPO_ROOT / "src" / "orisys"
|
||||
FIRST_PARTY = {"orisys", "orisys_blend"}
|
||||
|
||||
|
||||
def _third_party_imports() -> dict[str, set[str]]:
|
||||
"""Top-level third-party import names -> the files that import them."""
|
||||
stdlib = set(sys.stdlib_module_names)
|
||||
found: dict[str, set[str]] = {}
|
||||
|
||||
for path in sorted(PACKAGE_ROOT.rglob("*.py")):
|
||||
try:
|
||||
tree = ast.parse(path.read_text(encoding="utf-8", errors="ignore"))
|
||||
except SyntaxError:
|
||||
continue
|
||||
for node in ast.walk(tree):
|
||||
names: list[str] = []
|
||||
if isinstance(node, ast.Import):
|
||||
names = [alias.name for alias in node.names]
|
||||
elif isinstance(node, ast.ImportFrom) and node.module and node.level == 0:
|
||||
names = [node.module]
|
||||
for name in names:
|
||||
top = name.split(".")[0]
|
||||
if top in stdlib or top in FIRST_PARTY:
|
||||
continue
|
||||
found.setdefault(top, set()).add(path.relative_to(REPO_ROOT).as_posix())
|
||||
return found
|
||||
|
||||
|
||||
def test_every_third_party_import_is_nofollowed():
|
||||
found = _third_party_imports()
|
||||
assert found, "expected to find third-party imports in src/orisys"
|
||||
|
||||
missing = sorted(set(found) - set(NUITKA_NOFOLLOW_IMPORTS))
|
||||
assert not missing, (
|
||||
"these third-party modules are imported by src/orisys but missing from "
|
||||
"build/wheel/compile.py::NUITKA_NOFOLLOW_IMPORTS:\n "
|
||||
+ "\n ".join(f"{name} (imported by {sorted(found[name])})" for name in missing)
|
||||
+ "\nNuitka will try to follow them into the compiled module; add them to "
|
||||
"the exclusion list so they resolve from the user's environment at runtime."
|
||||
)
|
||||
|
||||
|
||||
def test_included_packages_are_first_party_or_subpackages():
|
||||
assert "orisys" in NUITKA_INCLUDE_PACKAGES
|
||||
for name in NUITKA_INCLUDE_PACKAGES:
|
||||
assert name == "orisys" or name.startswith("orisys."), name
|
||||
|
||||
|
||||
def test_nofollow_list_has_no_duplicates():
|
||||
assert len(NUITKA_NOFOLLOW_IMPORTS) == len(set(NUITKA_NOFOLLOW_IMPORTS))
|
||||
Reference in New Issue
Block a user