This commit is contained in:
2026-01-10 17:30:18 -08:00
parent 08fef4a5d3
commit c2edd5139f
10 changed files with 769 additions and 86 deletions

View File

@@ -39,7 +39,9 @@ Optional flags:
--playwright-only Install only Playwright browsers (installs playwright package if missing)
--browsers Comma-separated list of Playwright browsers to install (default: chromium)
--install-editable Install the project in editable mode (pip install -e scripts) for running tests
--install-deno Install the Deno runtime using the official installer
--install-mpv Install MPV player if not already installed (default)
--no-mpv Skip installing MPV player
--install-deno Install the Deno runtime using the official installer (default)
--no-deno Skip installing the Deno runtime
--deno-version Pin a specific Deno version to install (e.g., v1.34.3)
--upgrade-pip Upgrade pip, setuptools, and wheel before installing deps
@@ -174,6 +176,82 @@ def _build_playwright_install_cmd(browsers: str | None) -> list[str]:
return base + items
def _check_deno_installed() -> bool:
"""Check if Deno is already installed and accessible in PATH."""
return shutil.which("deno") is not None
def _check_mpv_installed() -> bool:
"""Check if MPV is already installed and accessible in PATH."""
return shutil.which("mpv") is not None
def _install_mpv() -> int:
"""Install MPV player for the current platform.
Returns exit code 0 on success, non-zero otherwise.
"""
system = platform.system().lower()
try:
if system == "windows":
# Windows: use winget (built-in package manager)
if shutil.which("winget"):
print("Installing MPV via winget...")
run(["winget", "install", "--id=mpv.net", "-e"])
else:
print(
"MPV not found and winget not available.\n"
"Please install MPV manually from https://mpv.io/installation/",
file=sys.stderr
)
return 1
elif system == "darwin":
# macOS: use Homebrew
if shutil.which("brew"):
print("Installing MPV via Homebrew...")
run(["brew", "install", "mpv"])
else:
print(
"MPV not found and Homebrew not available.\n"
"Install Homebrew from https://brew.sh then run: brew install mpv",
file=sys.stderr
)
return 1
else:
# Linux: use apt, dnf, or pacman
if shutil.which("apt"):
print("Installing MPV via apt...")
run(["sudo", "apt", "install", "-y", "mpv"])
elif shutil.which("dnf"):
print("Installing MPV via dnf...")
run(["sudo", "dnf", "install", "-y", "mpv"])
elif shutil.which("pacman"):
print("Installing MPV via pacman...")
run(["sudo", "pacman", "-S", "mpv"])
else:
print(
"MPV not found and no recognized package manager available.\n"
"Please install MPV manually for your distribution.",
file=sys.stderr
)
return 1
# Verify installation
if shutil.which("mpv"):
print(f"MPV installed at: {shutil.which('mpv')}")
return 0
print("MPV installation completed but 'mpv' not found in PATH.", file=sys.stderr)
return 1
except subprocess.CalledProcessError as exc:
print(f"MPV install failed: {exc}", file=sys.stderr)
return int(exc.returncode or 1)
except Exception as exc:
print(f"MPV install error: {exc}", file=sys.stderr)
return 1
def _install_deno(version: str | None = None) -> int:
"""Install Deno runtime for the current platform.
@@ -270,6 +348,17 @@ def main() -> int:
action="store_true",
help="Install the project in editable mode (pip install -e scripts) for running tests",
)
mpv_group = parser.add_mutually_exclusive_group()
mpv_group.add_argument(
"--install-mpv",
action="store_true",
help="Install MPV player if not already installed (default behavior)",
)
mpv_group.add_argument(
"--no-mpv",
action="store_true",
help="Skip installing MPV player (opt out)"
)
deno_group = parser.add_mutually_exclusive_group()
deno_group.add_argument(
"--install-deno",
@@ -930,6 +1019,24 @@ def main() -> int:
f"Warning: failed to verify or modify site-packages for top-level CLI: {exc}"
)
# Check and install MPV if needed
install_mpv_requested = True
if getattr(args, "no_mpv", False):
install_mpv_requested = False
elif getattr(args, "install_mpv", False):
install_mpv_requested = True
if install_mpv_requested:
if _check_mpv_installed():
if not args.quiet:
print("MPV is already installed.")
else:
if not args.quiet:
print("MPV not found in PATH. Attempting to install...")
rc = _install_mpv()
if rc != 0:
print("Warning: MPV installation failed. Install it manually from https://mpv.io/installation/", file=sys.stderr)
# Optional: install Deno runtime (default: install unless --no-deno is passed)
install_deno_requested = True
if getattr(args, "no_deno", False):
@@ -938,12 +1045,15 @@ def main() -> int:
install_deno_requested = True
if install_deno_requested:
if not args.quiet:
print("Installing Deno runtime (local/system)...")
rc = _install_deno(args.deno_version)
if rc != 0:
print("Deno installation failed.", file=sys.stderr)
return rc
if _check_deno_installed():
if not args.quiet:
print("Deno is already installed.")
else:
if not args.quiet:
print("Installing Deno runtime (local/system)...")
rc = _install_deno(args.deno_version)
if rc != 0:
print("Warning: Deno installation failed.", file=sys.stderr)
# Write project-local launcher script under scripts/ to keep the repo root uncluttered.
def _write_launchers() -> None: