Skip to content

livery.workshop._entry

livery.workshop._entry

The workspace entry contract: the emitted setup.sh at the root.

One choke point owns machine readiness. The script ensures uv at the lock's pinned version, syncs the venv against the lock, records the sync receipt, and emits the environment: sourced by a shell it enters that shell, and setup.sh github persists the emission into GITHUB_ENV/GITHUB_PATH so every later CI step calls the runner bare. A GitLab job sources setup.sh gitlab, and its shell keeps the emission for the job's later lines. The script sets the variables the workspace's extensions declare before its sync, and on a CI job of either kind places each one that names {place} in the job's own directory. Between entries the per-command reconcile (livery.workshop._reconcile) keeps the venv following the lock.

The script is a generated artifact like the CI workflows: emitted by livery.workshop._ci_generate.generate, written by fm sync, judged by the drift check. POSIX only; a Windows CI leg runs it under the runner's bash, and a pwsh spelling is deferred to the tool-store port.

Functions:

Name Description
locked_uv_version

The uv version the workspace lock pins, or "".

installer_url

The uv installer URL, versioned when a pin exists.

entry_script

The emitted setup.sh body for root, header not included.

native_members

The distribution names of the job-built members uv installs, in path order.

locked_uv_version

locked_uv_version(root: Path) -> str

The uv version the workspace lock pins, or "".

uv rides the dev group, so uv.lock pins it exactly. A workspace without a lock, or whose lock does not carry uv, has no pin to derive and answers "": the emitters then leave the bootstrap unpinned rather than inventing a version.

Source code in packages/workshop/src/livery/workshop/_entry.py
def locked_uv_version(root: Path) -> str:
    """The uv version the workspace lock pins, or "".

    uv rides the dev group, so ``uv.lock`` pins it exactly. A
    workspace without a lock, or whose lock does not carry uv, has no
    pin to derive and answers "": the emitters then leave the
    bootstrap unpinned rather than inventing a version.
    """
    lock = root / "uv.lock"
    if not lock.is_file():
        return ""
    try:
        parsed = tomllib.loads(lock.read_text("utf-8"))
    except (tomllib.TOMLDecodeError, UnicodeDecodeError):
        return ""
    for package in parsed.get("package", []):
        if isinstance(package, dict) and package.get("name") == "uv":
            return str(package.get("version", ""))
    return ""

installer_url

installer_url(pin: str) -> str

The uv installer URL, versioned when a pin exists.

Source code in packages/workshop/src/livery/workshop/_entry.py
def installer_url(pin: str) -> str:
    """The uv installer URL, versioned when a *pin* exists."""
    if pin:
        return f"https://astral.sh/uv/{pin}/install.sh"
    return "https://astral.sh/uv/install.sh"

entry_script

entry_script(root: Path) -> str

The emitted setup.sh body for root, header not included.

The variables the extensions of root's set declare are rendered from their declarations: each one's line, and in each CI branch the check that the job names a directory of its own, once for each variable that names {place}.

Raises:

Type Description
Failed

when two of the extensions declare one variable, naming both.

Source code in packages/workshop/src/livery/workshop/_entry.py
def entry_script(root: Path) -> str:
    """The emitted ``setup.sh`` body for *root*, header not included.

    The variables the extensions of *root*'s set declare are rendered
    from their declarations: each one's line, and in each CI branch the
    check that the job names a directory of its own, once for each
    variable that names ``{place}``.

    Raises:
        Failed: when two of the extensions declare one variable, naming
            both.
    """
    from livery.footman import directory_variable
    from livery.workshop._variables import workspace_variables

    pin = locked_uv_version(root)
    skipped = " ".join(f"--no-install-package {name}" for name in native_members(root))
    variables = workspace_variables(root)
    return (
        _SCRIPT.replace("__PROG__", footman.prog())
        .replace("__INSTALLER__", installer_url(pin))
        .replace("__DATA_DIR_VAR__", directory_variable("DATA_DIR"))
        .replace("__UV_PIN__", pin)
        .replace("__NATIVE_SKIP__", skipped)
        .replace("__GITHUB_PLACE__", _job_place("github", variables))
        # A shell branch takes no empty body: one that places nothing
        # does nothing.
        .replace("__GITLAB_PLACE__", _job_place("gitlab", variables) or "    :\n")
        .replace("__DECLARED__", _declared_lines(variables))
    )

native_members

native_members(root: Path) -> tuple[str, ...]

The distribution names of the job-built members uv installs, in path order.

A member a job of the release point builds before the wave, the workspace's job-built-members answer, carries native code its install builds against the store's tools, so the entry installs it after the tools are in the environment; every other member installs in the first sync. A job-built member the uv workspace does not hold is no uv install and is left out.

Source code in packages/workshop/src/livery/workshop/_entry.py
def native_members(root: Path) -> tuple[str, ...]:
    """The distribution names of the job-built members uv installs, in path order.

    A member a job of the release point builds before the wave, the
    workspace's ``job-built-members`` answer, carries native code its
    install builds against the store's tools, so the entry installs it
    after the tools are in the environment; every other member installs
    in the first sync. A job-built member the uv workspace does not hold
    is no uv install and is left out.
    """
    from livery.workshop._identity import roster
    from livery.workshop._queries import JOB_BUILT_MEMBERS, answer

    if not (root / "packages").is_dir():
        return ()
    built = answer(root, JOB_BUILT_MEMBERS)
    # The roster's dev entry marks a member of the uv workspace.
    return tuple(
        entry["name"]
        for entry in roster(root)
        if "dev" in entry and f"packages/{entry['dir']}" in built
    )