fix(services): name the build a compiled service is missing

A service shipped as .so/.pyd failed with a bare ModuleNotFoundError. Report the build this interpreter needs, with its version and platform.
This commit is contained in:
imSp4rky
2026-09-05 22:13:25 -06:00
parent 2f28aa8e64
commit e845e9ba28
2 changed files with 50 additions and 1 deletions
@@ -0,0 +1,30 @@
from __future__ import annotations
from importlib.machinery import EXTENSION_SUFFIXES
from pathlib import Path
from unshackle.core.services import compiled_import_hint
def _service(tmp_path: Path, *files: str) -> Path:
(tmp_path / "EXAMPLE").mkdir()
init = tmp_path / "EXAMPLE" / "__init__.py"
init.write_text("from .example import EXAMPLE\n")
for name in files:
(init.parent / name).touch()
return init
def test_hint_names_the_file_this_python_needs(tmp_path: Path) -> None:
init = _service(tmp_path, "example.cp999-win_amd64.pyd", "example.cpython-999-x86_64-linux-gnu.so")
assert f"needs example{EXTENSION_SUFFIXES[0]}" in compiled_import_hint("EXAMPLE.example", init)
def test_no_hint_when_this_python_can_load_it(tmp_path: Path) -> None:
init = _service(tmp_path, f"example{EXTENSION_SUFFIXES[0]}")
assert compiled_import_hint("EXAMPLE.example", init) == ""
def test_no_hint_for_a_pure_python_service(tmp_path: Path) -> None:
init = _service(tmp_path)
assert compiled_import_hint("EXAMPLE.example", init) == ""