Skip to content

Detect and log missing dependencies #5229

@MikeGoldsmith

Description

@MikeGoldsmith

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions