mirror of
https://github.com/esphome/esphome.git
synced 2026-09-26 22:40:21 +00:00
Raise the actionable ninja message when the package itself is missing
This commit is contained in:
@@ -208,7 +208,13 @@ def _find_ninja() -> Path:
|
||||
"""
|
||||
if binary := shutil.which("ninja"):
|
||||
return Path(binary)
|
||||
import ninja
|
||||
try:
|
||||
import ninja
|
||||
except ImportError as err:
|
||||
raise EsphomeError(
|
||||
"ninja not found on PATH or in the ninja package; reinstall the "
|
||||
"esphome Python environment"
|
||||
) from err
|
||||
|
||||
binary = Path(ninja.BIN_DIR) / ("ninja.exe" if os.name == "nt" else "ninja")
|
||||
if not binary.is_file():
|
||||
|
||||
@@ -237,6 +237,16 @@ def test_find_ninja_falls_back_to_wheel(tmp_path: Path) -> None:
|
||||
assert framework._find_ninja() == tmp_path / binary_name
|
||||
|
||||
|
||||
def test_find_ninja_package_not_installed() -> None:
|
||||
"""A missing ninja package raises the actionable message, not ImportError."""
|
||||
with (
|
||||
patch("shutil.which", return_value=None),
|
||||
patch.dict(sys.modules, {"ninja": None}),
|
||||
pytest.raises(EsphomeError, match="ninja not found"),
|
||||
):
|
||||
framework._find_ninja()
|
||||
|
||||
|
||||
def test_find_ninja_missing_everywhere(tmp_path: Path) -> None:
|
||||
wheel = MagicMock(BIN_DIR=str(tmp_path))
|
||||
with (
|
||||
|
||||
Reference in New Issue
Block a user