Skip to content

pixano_inference.ray.utils

Utility functions for Ray Serve infrastructure.

build_runtime_env(pip_packages=None, working_dir=None)

Build a Ray runtime environment configuration.

Parameters:

Name Type Description Default
pip_packages list[str] | None

Explicit list of pip packages to install in Ray workers.

None
working_dir str | None

Working directory for Ray workers.

None

Returns:

Type Description
dict | None

Runtime environment dictionary for Ray, or None if empty.

Source code in pixano_inference/ray/utils.py
def build_runtime_env(
    pip_packages: list[str] | None = None,
    working_dir: str | None = None,
) -> dict | None:
    """Build a Ray runtime environment configuration.

    Args:
        pip_packages: Explicit list of pip packages to install in Ray workers.
        working_dir: Working directory for Ray workers.

    Returns:
        Runtime environment dictionary for Ray, or None if empty.
    """
    env: dict = {}

    if pip_packages:
        env["pip"] = pip_packages

    if working_dir:
        env["working_dir"] = working_dir

    # Always set excludes to prevent Ray from packaging .git, .venv,
    # and project metadata files that cause uv to create new venvs
    # in worker processes.
    env["excludes"] = _DEFAULT_EXCLUDES

    return env if env else None