Skip to content

pypapip_manager

flavor.packaging.python.pypapip_manager

This module handles all pip-specific operations with proper platform support and manylinux2014 compatibility for maximum Linux distribution coverage.

Classes

PyPaPipManager

PyPaPipManager(python_version: str = '3.11')

Dedicated PyPA pip command management.

Handles all pip-specific operations with proper platform support and manylinux2014 compatibility for Linux.

CRITICAL: This class contains essential PyPA functionality for: - Platform-specific wheel selection (manylinux2014 for Linux compatibility) - Proper dependency resolution that uv pip cannot handle - Binary wheel downloading for cross-platform builds - Correct Python version targeting

DO NOT REPLACE pip commands with uv pip - they have different capabilities!

Initialize the pip manager.

Parameters:

Name Type Description Default
python_version str

Target Python version for pip operations

'3.11'
Source code in flavor/packaging/python/pypapip_manager.py
def __init__(self, python_version: str = "3.11") -> None:
    """
    Initialize the pip manager.

    Args:
        python_version: Target Python version for pip operations
    """
    self.python_version = python_version
Functions
build_wheel_from_source
build_wheel_from_source(
    python_exe: Path,
    source_path: Path,
    wheel_dir: Path,
    no_deps: bool = True,
) -> None

Build wheel from source directory.

Parameters:

Name Type Description Default
python_exe Path

Path to Python executable

required
source_path Path

Path to source directory with setup.py or pyproject.toml

required
wheel_dir Path

Directory to place built wheel

required
no_deps bool

Whether to build without dependencies

True
Source code in flavor/packaging/python/pypapip_manager.py
def build_wheel_from_source(
    self, python_exe: Path, source_path: Path, wheel_dir: Path, no_deps: bool = True
) -> None:
    """
    Build wheel from source directory.

    Args:
        python_exe: Path to Python executable
        source_path: Path to source directory with setup.py or pyproject.toml
        wheel_dir: Directory to place built wheel
        no_deps: Whether to build without dependencies
    """
    logger.info(f"🔨📦 Building wheel from source: {source_path.name}")

    wheel_cmd = self._get_pypapip_wheel_cmd(
        python_exe=python_exe,
        wheel_dir=wheel_dir,
        source=source_path,
        no_deps=no_deps,
    )

    logger.debug("💻 Building wheel", command=" ".join(wheel_cmd))
    result = run(wheel_cmd, check=True, capture_output=True)

    if result.stdout:
        # Look for the wheel filename in output
        for line in result.stdout.strip().split("\n"):
            if ".whl" in line:
                logger.info("📦🏗️✅ Built wheel", wheel=line.strip())
                break
download_wheels_for_packages
download_wheels_for_packages(
    python_exe: Path, packages: list[str], dest_dir: Path
) -> None

Download wheels for specified packages.

Parameters:

Name Type Description Default
python_exe Path

Path to Python executable

required
packages list[str]

List of package names/requirements

required
dest_dir Path

Directory to download wheels to

required
Retries

Up to 3 attempts with exponential backoff for network errors

Source code in flavor/packaging/python/pypapip_manager.py
@retry(
    ConnectionError,
    TimeoutError,
    OSError,
    max_attempts=3,
    base_delay=1.0,
    backoff=BackoffStrategy.EXPONENTIAL,
    jitter=True,
)
def download_wheels_for_packages(self, python_exe: Path, packages: list[str], dest_dir: Path) -> None:
    """
    Download wheels for specified packages.

    Args:
        python_exe: Path to Python executable
        packages: List of package names/requirements
        dest_dir: Directory to download wheels to

    Retries:
        Up to 3 attempts with exponential backoff for network errors
    """
    if not packages:
        logger.debug("No packages to download")
        return

    logger.info(f"🌐📥 Downloading wheels for {len(packages)} packages")

    download_cmd = self._get_pypapip_download_cmd(
        python_exe=python_exe,
        dest_dir=dest_dir,
        packages=packages,
        binary_only=True,
    )

    logger.debug("💻 Downloading packages", command=" ".join(download_cmd))
    result = run(download_cmd, check=False, capture_output=True)

    if result.returncode != 0:
        error_msg = f"Failed to download required packages: {result.stderr}"
        logger.error(error_msg)
        raise RuntimeError(error_msg)
download_wheels_from_requirements
download_wheels_from_requirements(
    python_exe: Path,
    requirements_file: Path,
    dest_dir: Path,
) -> None

Download wheels for packages listed in requirements file.

Parameters:

Name Type Description Default
python_exe Path

Path to Python executable

required
requirements_file Path

Path to requirements.txt file

required
dest_dir Path

Directory to download wheels to

required
Retries

Up to 3 attempts with exponential backoff for network errors

Source code in flavor/packaging/python/pypapip_manager.py
@retry(
    ConnectionError,
    TimeoutError,
    OSError,
    max_attempts=3,
    base_delay=1.0,
    backoff=BackoffStrategy.EXPONENTIAL,
    jitter=True,
)
def download_wheels_from_requirements(
    self, python_exe: Path, requirements_file: Path, dest_dir: Path
) -> None:
    """
    Download wheels for packages listed in requirements file.

    Args:
        python_exe: Path to Python executable
        requirements_file: Path to requirements.txt file
        dest_dir: Directory to download wheels to

    Retries:
        Up to 3 attempts with exponential backoff for network errors
    """
    logger.info("🌐📥 Downloading wheels from requirements file")

    download_cmd = self._get_pypapip_download_cmd(
        python_exe=python_exe,
        dest_dir=dest_dir,
        requirements_file=requirements_file,
        binary_only=True,
    )

    logger.debug("💻 Downloading requirements", command=" ".join(download_cmd))
    result = run(download_cmd, check=False, capture_output=True)

    if result.returncode != 0:
        error_msg = f"Failed to download required wheels: {result.stderr}"
        logger.error(error_msg)
        raise RuntimeError(error_msg)
    else:
        logger.info("✅ Successfully downloaded all wheels")
install_packages
install_packages(
    python_exe: Path, packages: list[str]
) -> None

Install packages using pip.

Parameters:

Name Type Description Default
python_exe Path

Path to Python executable

required
packages list[str]

List of package names/requirements to install

required
Source code in flavor/packaging/python/pypapip_manager.py
def install_packages(self, python_exe: Path, packages: list[str]) -> None:
    """
    Install packages using pip.

    Args:
        python_exe: Path to Python executable
        packages: List of package names/requirements to install
    """
    if not packages:
        logger.debug("No packages to install")
        return

    logger.info(f"📦📥 Installing {len(packages)} packages")

    install_cmd = self._get_pypapip_install_cmd(python_exe, packages)

    logger.debug("💻 Installing packages", command=" ".join(install_cmd))
    run(install_cmd, check=True, capture_output=True)

    logger.info("✅ Successfully installed packages")