Skip to content

Deps

provide.foundation.utils.deps

TODO: Add module docstring.

Classes

DependencyStatus

Status of an optional dependency.

Functions

check_optional_deps

check_optional_deps(
    *, quiet: bool = False, return_status: bool = False
) -> list[DependencyStatus] | None

Check and display optional dependency status.

Parameters:

Name Type Description Default
quiet bool

If True, don't print status (just return it)

False
return_status bool

If True, return the status list

False

Returns:

Type Description
list[DependencyStatus] | None

Optional list of dependency statuses if return_status=True

Source code in provide/foundation/utils/deps.py
def check_optional_deps(*, quiet: bool = False, return_status: bool = False) -> list[DependencyStatus] | None:
    """Check and display optional dependency status.

    Args:
        quiet: If True, don't print status (just return it)
        return_status: If True, return the status list

    Returns:
        Optional list of dependency statuses if return_status=True

    """
    deps = get_optional_dependencies()

    if not quiet:
        from provide.foundation.hub.foundation import get_foundation_logger

        log = get_foundation_logger()
        log.info("=" * 50)

        available_count = sum(1 for dep in deps if dep.available)
        total_count = len(deps)

        for dep in deps:
            status_icon = "βœ…" if dep.available else "❌"
            version_info = f" (v{dep.version})" if dep.version else ""
            log.info(f"  {status_icon} {dep.name}{version_info}")
            log.info(f"     {dep.description}")
            if not dep.available:
                log.info(f"     Install with: pip install 'provide-foundation[{dep.name}]'")

        log.info(f"πŸ“Š Summary: {available_count}/{total_count} optional dependencies available")

        if available_count == total_count:
            log.info("πŸŽ‰ All optional features are available!")
        elif available_count == 0:
            log.info("πŸ’‘ Install optional features with: pip install 'provide-foundation[all]'")
        else:
            missing = [dep.name for dep in deps if not dep.available]
            log.info(f"πŸ’‘ Missing features: {', '.join(missing)}")

    if return_status:
        return deps
    return None

get_available_features

get_available_features() -> dict[str, bool]

Get a dictionary of available optional features.

Returns:

Type Description
dict[str, bool]

Dictionary mapping feature names to availability

Source code in provide/foundation/utils/deps.py
def get_available_features() -> dict[str, bool]:
    """Get a dictionary of available optional features.

    Returns:
        Dictionary mapping feature names to availability

    """
    deps = get_optional_dependencies()
    return {dep.name: dep.available for dep in deps}

get_optional_dependencies

get_optional_dependencies() -> list[DependencyStatus]

Get status of all optional dependencies.

Returns:

Type Description
list[DependencyStatus]

List of dependency status objects

Source code in provide/foundation/utils/deps.py
def get_optional_dependencies() -> list[DependencyStatus]:
    """Get status of all optional dependencies.

    Returns:
        List of dependency status objects

    """
    return [
        _check_click(),
        _check_cryptography(),
        _check_httpx(),
        _check_mkdocs(),
        _check_opentelemetry(),
    ]

has_dependency

has_dependency(name: str) -> bool

Check if a specific optional dependency is available.

Parameters:

Name Type Description Default
name str

Name of the dependency to check

required

Returns:

Type Description
bool

True if dependency is available

Source code in provide/foundation/utils/deps.py
def has_dependency(name: str) -> bool:
    """Check if a specific optional dependency is available.

    Args:
        name: Name of the dependency to check

    Returns:
        True if dependency is available

    """
    deps = get_optional_dependencies()
    for dep in deps:
        if dep.name == name:
            return dep.available
    return False

require_dependency

require_dependency(name: str) -> None

Require a specific optional dependency, raise ImportError if missing.

Parameters:

Name Type Description Default
name str

Name of the dependency to require

required

Raises:

Type Description
ImportError

If dependency is not available

Source code in provide/foundation/utils/deps.py
def require_dependency(name: str) -> None:
    """Require a specific optional dependency, raise ImportError if missing.

    Args:
        name: Name of the dependency to require

    Raises:
        ImportError: If dependency is not available

    """
    if not has_dependency(name):
        raise ImportError(
            f"Optional dependency '{name}' is required for this feature. "
            f"Install with: pip install 'provide-foundation[{name}]'",
        )