Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/evaluate/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def _download_additional_modules(
elif import_type == "external":
url_or_filename = import_path
else:
raise ValueError("Wrong import_type")
raise ValueError(f"Wrong import_type: {import_type!r}. Expected 'library', 'internal', or 'external'.")

local_import_path = cached_path(
url_or_filename,
Expand All @@ -255,20 +255,18 @@ def _download_additional_modules(

# Check library imports
needs_to_be_installed = set()
for library_import_name, library_import_path in library_imports:
for library_import_name, _ in library_imports:
try:
lib = importlib.import_module(library_import_name) # noqa F841
importlib.import_module(library_import_name) # noqa F841
except ImportError:
library_import_name = "scikit-learn" if library_import_name == "sklearn" else library_import_name
library_import_path = "scikit-learn" if library_import_path == "sklearn" else library_import_path
library_import_name = "absl-py" if library_import_name == "absl" else library_import_name
library_import_path = "absl-py" if library_import_path == "absl" else library_import_path
needs_to_be_installed.add((library_import_name, library_import_path))
needs_to_be_installed.add(library_import_name)
if needs_to_be_installed:
missing = sorted(needs_to_be_installed)
raise ImportError(
f"To be able to use {name}, you need to install the following dependencies"
f"{[lib_name for lib_name, lib_path in needs_to_be_installed]} using 'pip install "
f"{' '.join([lib_path for lib_name, lib_path in needs_to_be_installed])}' for instance."
f"To be able to use {name}, you need to install these dependencies: "
f"{', '.join(missing)} using the command 'pip install {' '.join(missing)}'."
)
return local_imports

Expand Down