left4me/l4d2host/l4d2host/steam_install.py
mwiegand 49992b3a26
refactor(repo): uv workspace + hatchling + layout restructure
Migrate from pip-install-e + setuptools to a uv workspace with a
committed uv.lock for deterministic deps. Switch both members to
hatchling, and move package sources into nested standard layout
(l4d2host/l4d2host/, l4d2web/l4d2web/) so builds work from a
read-only source tree — setuptools wrote egg-info to source under
the old layout, which broke uv sync on the root-owned /opt/left4me/src.

Local dev install: `pip install -e ./l4d2host -e ./l4d2web` -> `uv sync`.
.envrc switches from `layout python python3.13` to `use uv`. Python
pinned to 3.13 via .python-version.

l4d2web now declares its cross-dep on l4d2host explicitly via
[tool.uv.sources] (workspace = true). l4d2web/alembic.ini and
l4d2web/alembic/ stay at the project root (standard alembic layout).

Test fixes:
- tests/__init__.py added to both test dirs so pytest doesn't shadow
  l4d2host as a namespace package via outer-dir walk.
- 3 CWD-relative paths in tests (l4d2web/static/css/{tokens,layout}.css
  and js/sse.js) anchored to Path(__file__) so they survive layout
  changes.
- Two test_install.py tests now monkeypatch HOME to tmp_path so they
  stop silently mutating ~/.steam/sdk32 on every run.

628 tests pass under sandboxed `uv run pytest`.

Per docs/superpowers/plans/2026-05-15-uv-workspace-execution.md;
prereq for the ckn-bw bundle's uv-sync action (queued).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-15 22:04:29 +02:00

102 lines
3.3 KiB
Python

import shutil
from pathlib import Path
from typing import Callable
from l4d2host.paths import get_left4me_root
from l4d2host.process import run_command
from l4d2host.logging import emit_step
def _resolve_steamcmd_siblings(steamcmd: str) -> tuple[Path, Path] | None:
resolved = shutil.which(steamcmd)
base = Path(resolved).resolve() if resolved else Path(steamcmd)
if base.is_symlink():
base = base.resolve()
parent = base.parent
linux32 = parent / "linux32"
linux64 = parent / "linux64"
if linux32.is_dir() and linux64.is_dir():
return linux32, linux64
return None
def _set_symlink(link: Path, target: Path, on_stderr: Callable[[str], None] | None) -> None:
if link.is_symlink():
try:
current = link.resolve()
except OSError:
current = None
if current == target.resolve():
return
link.unlink()
elif link.exists():
if on_stderr is not None:
on_stderr(f"refusing to replace non-symlink at {link}")
return
link.symlink_to(target)
def _ensure_steam_sdk_symlinks(
install_dir: Path,
steamcmd: str,
*,
on_stdout: Callable[[str], None] | None,
on_stderr: Callable[[str], None] | None,
passthrough: bool,
) -> None:
emit_step("ensuring steam sdk symlinks...", on_stdout, passthrough)
siblings = _resolve_steamcmd_siblings(steamcmd)
if siblings is not None:
sdk32_target, sdk64_target = siblings
else:
fallback = install_dir / "bin"
sdk32_target, sdk64_target = fallback, fallback
steam_dir = Path.home() / ".steam"
steam_dir.mkdir(parents=True, exist_ok=True)
_set_symlink(steam_dir / "sdk32", sdk32_target, on_stderr)
_set_symlink(steam_dir / "sdk64", sdk64_target, on_stderr)
class SteamInstaller:
def __init__(self, install_dir: Path | None = None, steamcmd: str = "steamcmd"):
self.install_dir = get_left4me_root() / "installation" if install_dir is None else Path(install_dir)
self.steamcmd = steamcmd
def install_or_update(
self,
*,
on_stdout: Callable[[str], None] | None = None,
on_stderr: Callable[[str], None] | None = None,
passthrough: bool = False,
should_cancel: Callable[[], bool] | None = None,
) -> None:
for platform in ("windows", "linux"):
emit_step(f"downloading {platform} platform payload...", on_stdout, passthrough)
run_command(
[
self.steamcmd,
"+force_install_dir",
str(self.install_dir),
"+login",
"anonymous",
"+@sSteamCmdForcePlatformType",
platform,
"+app_update",
"222860",
"validate",
"+quit",
],
on_stdout=on_stdout,
on_stderr=on_stderr,
passthrough=passthrough,
should_cancel=should_cancel,
)
_ensure_steam_sdk_symlinks(
self.install_dir,
self.steamcmd,
on_stdout=on_stdout,
on_stderr=on_stderr,
passthrough=passthrough,
)
emit_step("installation complete.", on_stdout, passthrough)