Skip to content

binary_loader

flavor.helpers.binary_loader

TODO: Add module docstring.

Classes

BinaryLoader

BinaryLoader(manager: HelperManager)

Handles helper binary loading, building, and testing.

Initialize with reference to parent manager.

Source code in flavor/helpers/binary_loader.py
def __init__(self, manager: HelperManager) -> None:
    """Initialize with reference to parent manager."""
    self.manager = manager
Attributes
current_platform property
current_platform: str

Get current platform string.

Functions
build_helpers
build_helpers(
    language: str | None = None, force: bool = False
) -> list[Path]

Build helper binaries from source.

Parameters:

Name Type Description Default
language str | None

Language to build ("go", "rust", or None for all)

None
force bool

Force rebuild even if binaries exist

False

Returns:

Type Description
list[Path]

List of built binary paths

Source code in flavor/helpers/binary_loader.py
def build_helpers(self, language: str | None = None, force: bool = False) -> list[Path]:
    """Build helper binaries from source.

    Args:
        language: Language to build ("go", "rust", or None for all)
        force: Force rebuild even if binaries exist

    Returns:
        List of built binary paths
    """
    built_binaries = []

    if language is None or language == "go":
        built_binaries.extend(self._build_go_helpers(force))

    if language is None or language == "rust":
        built_binaries.extend(self._build_rust_helpers(force))

    return built_binaries
clean_helpers
clean_helpers(language: str | None = None) -> list[Path]

Clean built helper binaries.

Parameters:

Name Type Description Default
language str | None

Language to clean ("go", "rust", or None for all)

None

Returns:

Type Description
list[Path]

List of removed binary paths

Source code in flavor/helpers/binary_loader.py
def clean_helpers(self, language: str | None = None) -> list[Path]:
    """Clean built helper binaries.

    Args:
        language: Language to clean ("go", "rust", or None for all)

    Returns:
        List of removed binary paths
    """
    removed_paths: list[Path] = []

    if not self.manager.helpers_bin.exists():
        return removed_paths

    patterns = []
    if language is None:
        patterns = ["flavor-*"]
    elif language == "go":
        patterns = ["flavor-go-*"]
    elif language == "rust":
        patterns = ["flavor-rs-*"]

    for pattern in patterns:
        for binary_path in self.manager.helpers_bin.glob(pattern):
            if binary_path.is_file():
                logger.info(f"Removing {binary_path}")
                binary_path.unlink()
                removed_paths.append(binary_path)

    return removed_paths
get_helper
get_helper(name: str) -> Path

Get path to a helper binary.

Parameters:

Name Type Description Default
name str

Helper name (e.g., "flavor-rs-launcher")

required

Returns:

Type Description
Path

Path to the helper binary

Raises:

Type Description
FileNotFoundError

If helper not found

Source code in flavor/helpers/binary_loader.py
def get_helper(self, name: str) -> Path:
    """Get path to a helper binary.

    Args:
        name: Helper name (e.g., "flavor-rs-launcher")

    Returns:
        Path to the helper binary

    Raises:
        FileNotFoundError: If helper not found
    """
    platform_specific_names = self._generate_helper_names(name)

    for specific_name in platform_specific_names:
        found_path = self._search_helper_locations(specific_name)
        if found_path:
            return found_path

    # Not found
    bin_dir = Path(__file__).parent / "bin"
    raise FileNotFoundError(
        f"Helper '{name}' not found for platform {self.current_platform}.\n"
        f"Tried names: {platform_specific_names}\n"
        f"Searched in: {bin_dir}, {self.manager.helpers_bin}"
    )
test_helpers
test_helpers(language: str | None = None) -> dict[str, Any]

Test helper binaries.

Parameters:

Name Type Description Default
language str | None

Language to test ("go", "rust", or None for all)

None

Returns:

Type Description
dict[str, Any]

Test results dict with 'passed' and 'failed' lists

Source code in flavor/helpers/binary_loader.py
def test_helpers(self, language: str | None = None) -> dict[str, Any]:
    """Test helper binaries.

    Args:
        language: Language to test ("go", "rust", or None for all)

    Returns:
        Test results dict with 'passed' and 'failed' lists
    """
    results: dict[str, list[dict[str, Any]]] = {"passed": [], "failed": []}

    helpers = self.manager.list_helpers()

    # Filter by language if specified
    all_helpers = helpers["launchers"] + helpers["builders"]
    if language:
        all_helpers = [i for i in all_helpers if i.language == language]

    for helper in all_helpers:
        try:
            # Test with --version flag
            result = run(
                [str(helper.path), "--version"],
                capture_output=True,
                timeout=5,
            )

            if result.returncode == 0:
                results["passed"].append(
                    {
                        "name": helper.name,
                        "version": result.stdout.strip() if result.stdout else None,
                    }
                )
            else:
                results["failed"].append(
                    {
                        "name": helper.name,
                        "error": f"Exit code {result.returncode}",
                        "stderr": result.stderr[:200] if result.stderr else None,
                    }
                )
        except Exception as e:
            results["failed"].append({"name": helper.name, "error": str(e)})

    return results