Skip to content

dependency_resolver

flavor.packaging.python.dependency_resolver

TODO: Add module docstring.

Classes

DependencyResolver

DependencyResolver(is_windows: bool = False)

Handles Python dependency resolution and tool management.

Initialize dependency resolver.

Parameters:

Name Type Description Default
is_windows bool

Whether building for Windows

False
Source code in flavor/packaging/python/dependency_resolver.py
def __init__(self, is_windows: bool = False) -> None:
    """Initialize dependency resolver.

    Args:
        is_windows: Whether building for Windows
    """
    self.is_windows = is_windows
    self.uv_manager = UVManager()
    self.pypapip = PyPaPipManager()
    self.uv_exe = "uv.exe" if is_windows else "uv"
Functions
download_uv_wheel
download_uv_wheel(dest_dir: Path) -> Path | None

Download manylinux2014-compatible UV wheel using PIP - NOT UV!

CRITICAL WARNING: This function downloads the UV BINARY itself using pip. UV CANNOT DOWNLOAD ITSELF. This is PyPA pip territory.

DO NOT CONFUSE THIS WITH UV DOWNLOAD OPERATIONS.

Parameters:

Name Type Description Default
dest_dir Path

Directory to save UV binary to

required

Returns:

Type Description
Path | None

Path to UV binary if successful, None otherwise

Retries

Up to 3 attempts with exponential backoff for network errors

Source code in flavor/packaging/python/dependency_resolver.py
@retry(
    ConnectionError,
    TimeoutError,
    OSError,
    max_attempts=3,
    base_delay=1.0,
    backoff=BackoffStrategy.EXPONENTIAL,
    jitter=True,
)
def download_uv_wheel(self, dest_dir: Path) -> Path | None:
    """Download manylinux2014-compatible UV wheel using PIP - NOT UV!

    CRITICAL WARNING: This function downloads the UV BINARY itself using pip.
    UV CANNOT DOWNLOAD ITSELF. This is PyPA pip territory.

    DO NOT CONFUSE THIS WITH UV DOWNLOAD OPERATIONS.

    Args:
        dest_dir: Directory to save UV binary to

    Returns:
        Path to UV binary if successful, None otherwise

    Retries:
        Up to 3 attempts with exponential backoff for network errors
    """
    logger.debug(f"Platform: {get_os_name()}, Architecture: {get_arch_name()}")

    # First ensure pip is available
    if not self._ensure_pip_available():
        return None

    with tempfile.TemporaryDirectory() as temp_dir:
        logger.trace(f"Created temp directory for UV download: {temp_dir}")

        # Download UV wheel using pip
        uv_wheel = self._download_uv_with_pip(temp_dir)
        if not uv_wheel:
            return self._fallback_download_uv(dest_dir)

        # Extract UV binary from wheel
        uv_path = self._extract_uv_from_wheel(uv_wheel, dest_dir)
        if uv_path:
            return uv_path

        logger.error("UV binary not found in wheel")
        return self._fallback_download_uv(dest_dir)
find_uv_command
find_uv_command(
    raise_if_not_found: bool = True,
) -> str | None

Find the UV command.

Parameters:

Name Type Description Default
raise_if_not_found bool

Whether to raise if not found

True

Returns:

Type Description
str | None

UV command path or None

Raises:

Type Description
FileNotFoundError

If UV not found and raise_if_not_found is True

Source code in flavor/packaging/python/dependency_resolver.py
def find_uv_command(self, raise_if_not_found: bool = True) -> str | None:
    """Find the UV command.

    Args:
        raise_if_not_found: Whether to raise if not found

    Returns:
        UV command path or None

    Raises:
        FileNotFoundError: If UV not found and raise_if_not_found is True
    """
    logger.trace("Searching for UV command")

    # Priority order for finding UV:
    # 1. uv executable from environment builders (if available)
    # 2. UV from PATH
    # 3. UV from current virtual environment
    # 4. UV via pipx

    # Check if UV is in PATH
    uv_path = shutil.which("uv")
    if uv_path:
        logger.debug(f"Found UV in PATH: {uv_path}")
        try:
            result = run([uv_path, "--version"], capture_output=True, timeout=10)
            if result.returncode == 0:
                logger.trace(f"UV version check successful: {result.stdout.strip()}")
                return uv_path
            else:
                logger.warning(f"UV version check failed: {result.stderr}")
        except Exception as e:
            logger.warning(f"Failed to verify UV at {uv_path}: {e}")

    # Check if UV is available via pipx
    pipx_uv = shutil.which("pipx")
    if pipx_uv:
        try:
            logger.trace("Checking if UV is available via pipx")
            result = run(["pipx", "run", "uv", "--version"], capture_output=True, timeout=15)
            if result.returncode == 0:
                logger.debug("UV found via pipx")
                return "pipx run uv"
        except Exception as e:
            logger.trace(f"pipx uv check failed: {e}")

    if raise_if_not_found:
        raise FileNotFoundError(
            "UV not found in PATH or via pipx. Please install UV: "
            "https://docs.astral.sh/uv/getting-started/installation/"
        )

    return None