Only translate ModuleNotFoundError exceptions

require_tooling_dependency() now only translates
ModuleNotFoundError when the missing module is the
requested top-level package. Other import
failures are re-raised unchanged.

This helps in situation where third-party dependency
is installed but broken for whatever reason. Previously
we would intercept it and suggest to run
pip install cuda-bench[tools], but that was already done.
This commit is contained in:
Oleksandr Pavlyk
2026-06-29 12:55:29 -05:00
parent 36769ae9c7
commit 5c41187e00
2 changed files with 45 additions and 1 deletions

View File

@@ -27,7 +27,10 @@ def require_tooling_dependency(
) -> ModuleType:
try:
return importlib.import_module(dependency.import_name)
except ImportError as exc:
except ModuleNotFoundError as exc:
top_level_package = dependency.import_name.partition(".")[0]
if exc.name != top_level_package:
raise
raise MissingToolingDependencyError(
f"{tool_name} requires {dependency.package_name!r} for "
f"{dependency.purpose}.\n\n"