Isolated Tier 1 bootstrapper for pinned livery-workshop jobs.
Tier 1 jobs (govern holding FORGE_ADMIN_TOKEN and publish
holding PYPI_TOKEN / OIDC) never run setup.sh, never install
non-privileged workspace members from packages/*/, never import
tasks.py, and never fold .repo.env. Instead they launch
uv run --isolated --no-project with either the pinned external
livery-workshop==<version> from uv.lock (consumer repositories)
or the CODEOWNERS-guarded transitive editable closure of
livery-workshop (self-hosting repositories such as livery), and
invoke the target entry module under python3 -I.
Functions:
Attributes:
DRIVER_DIST
module-attribute
DRIVER_DIST = 'livery-workshop'
isolated_command
Build the uv run --isolated --no-project argv for Tier 1 module.
Consumer repositories install livery-workshop==<locked-version>
from the locked index (never installing packages/*/).
Self-hosting repositories install only livery-workshop and its
transitive editable dependencies (all guarded in CODEOWNERS).
An explicit workshop_version overrides uv.lock (for
release.yml --workshop recovery runs).
Source code in packages/workshop/src/livery/workshop/_isolated.py
| def isolated_command(
root: Path,
module: str,
args: Sequence[str] = (),
*,
workshop_version: str = "",
) -> list[str]:
"""Build the ``uv run --isolated --no-project`` argv for Tier 1 *module*.
Consumer repositories install ``livery-workshop==<locked-version>``
from the locked index (never installing ``packages/*/``).
Self-hosting repositories install only ``livery-workshop`` and its
transitive editable dependencies (all guarded in ``CODEOWNERS``).
An explicit *workshop_version* overrides ``uv.lock`` (for
``release.yml --workshop`` recovery runs).
"""
cmd = ["uv", "run", "--isolated", "--no-project"]
if workshop_version:
cmd.extend(["--with", f"{DRIVER_DIST}=={workshop_version}"])
else:
packages = _lock_packages(root / "uv.lock")
driver = next(
(entry for entry in packages if entry.get("name") == DRIVER_DIST),
None,
)
if driver is None:
raise RuntimeError(
f"uv.lock names no {DRIVER_DIST} entry; cannot run isolated {module}"
)
source = driver.get("source")
if isinstance(source, dict) and "editable" in source:
for rel_path in _editable_closure(packages, DRIVER_DIST):
cmd.extend(["--with", f"./{rel_path}"])
else:
version = str(driver.get("version") or "").strip()
if not version:
raise RuntimeError(
f"uv.lock entry for {DRIVER_DIST} carries no version"
)
registry = (
str(source.get("registry") or "").strip()
if isinstance(source, dict)
else ""
)
if registry and registry.rstrip("/") != _PYPI_SIMPLE:
cmd.extend(["--extra-index-url", registry])
cmd.extend(["--with", f"{DRIVER_DIST}=={version}"])
cmd.extend(["--", "python3", "-I", "-m", module, *args])
return cmd
|
isolated_shell_launcher
Render a self-contained stdlib python3 -I -c command for CI YAML.
Reads uv.lock with stdlib tomllib under python3 -I (so
nothing in the checkout directory or PYTHONPATH can shadow
stdlib or execute before uv starts) and launches module in an
isolated ephemeral environment with python3 -I -m <module>.
Source code in packages/workshop/src/livery/workshop/_isolated.py
| def isolated_shell_launcher(
module: str,
args: Sequence[str] = (),
*,
workshop_env: str = "",
) -> str:
"""Render a self-contained stdlib ``python3 -I -c`` command for CI YAML.
Reads ``uv.lock`` with stdlib ``tomllib`` under ``python3 -I`` (so
nothing in the checkout directory or ``PYTHONPATH`` can shadow
stdlib or execute before ``uv`` starts) and launches *module* in an
isolated ephemeral environment with ``python3 -I -m <module>``.
"""
# Keep the bootstrap snippet pure stdlib and single-quoted safe.
args_repr = ", ".join(repr(arg) for arg in args)
script = (
"import os, pathlib, subprocess, sys, tomllib\n"
f"mod = {module!r}\n"
f"extra = [{args_repr}]\n"
f"pin = os.environ.get({workshop_env!r}, '').strip()"
f" if {bool(workshop_env)!r} else ''\n"
"cmd = ['uv', 'run', '--isolated', '--no-project']\n"
"if pin:\n"
f" cmd += ['--with', f'{DRIVER_DIST}=={{pin}}']\n"
"else:\n"
" pkgs = [p for p in tomllib.loads("
"pathlib.Path('uv.lock').read_text('utf-8')).get('package', [])"
" if isinstance(p, dict)]\n"
" by = {p['name']: p for p in pkgs if 'name' in p}\n"
f" drv = by.get({DRIVER_DIST!r})\n"
" if drv is None:\n"
f" sys.exit('uv.lock names no {DRIVER_DIST} entry')\n"
" src = drv.get('source') or {}\n"
" if 'editable' in src:\n"
" seen, order = set(), []\n"
" def walk(n):\n"
" if n in seen: return\n"
" seen.add(n)\n"
" e = by.get(n)\n"
" if not e or 'editable' not in (e.get('source') or {}): return\n"
" for d in e.get('dependencies') or ():\n"
" if isinstance(d, dict) and 'name' in d: walk(d['name'])\n"
" order.append(e['source']['editable'])\n"
f" walk({DRIVER_DIST!r})\n"
" for p in order: cmd += ['--with', f'./{p}']\n"
" else:\n"
" reg = str(src.get('registry') or '').strip()\n"
f" if reg and reg.rstrip('/') != {_PYPI_SIMPLE!r}:\n"
" cmd += ['--extra-index-url', reg]\n"
f" cmd += ['--with', f'{DRIVER_DIST}=={{drv[\"version\"]}}']\n"
"cmd += ['--', 'python3', '-I', '-m', mod] + extra\n"
"sys.exit(subprocess.call(cmd))\n"
)
return script
|