No need to add this into this PR, but it might be nice to define an exception specifically for dependency errors, e.g.
class MissingDependencyError(ConfigurationError):
"""Raised when an optional dependency is not installed."""
def __init__(
self,
package: str,
feature: str | None = None,
install_name: str | None = None,
extras: str | None = None,
) -> None:
self.package = package
self.feature = feature
self.install_name = install_name or package
self.extras = extras
if extras:
install_cmd = f"pip install '{self.install_name}[{extras}]'"
else:
install_cmd = f"pip install {self.install_name}"
if feature:
message = (
f"{feature} requires '{package}'. "
f"Install it with: {install_cmd}"
)
else:
message = (
f"'{package}' is required but not installed. "
f"Install it with: {install_cmd}"
)
super().__init__(message)
Originally posted by @herin049 in #5216 (comment)
No need to add this into this PR, but it might be nice to define an exception specifically for dependency errors, e.g.
Originally posted by @herin049 in #5216 (comment)