41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Supply missing parity tools locally, without sudo or changing the worker."""
|
|
from pathlib import Path
|
|
import os
|
|
import platform
|
|
import shutil
|
|
import subprocess
|
|
|
|
try:
|
|
from .fetch_ffprobe import fetch
|
|
except ImportError:
|
|
from fetch_ffprobe import fetch
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
TYPST_VERSION = "0.13.1"
|
|
|
|
|
|
def prepare():
|
|
install = ROOT / "downloads/ci-tools"
|
|
bindir = install / "bin"
|
|
bindir.mkdir(parents=True, exist_ok=True)
|
|
os.environ["PATH"] = str(bindir) + os.pathsep + os.environ.get("PATH", "")
|
|
for program in ("ffmpeg", "ffprobe"):
|
|
if not shutil.which(program):
|
|
if platform.system() != "Linux" or platform.machine().lower() not in ("x86_64", "amd64"):
|
|
raise RuntimeError(f"Install {program} on PATH; automatic CI provisioning needs Linux x86-64")
|
|
binary, _ = fetch("x86_64-unknown-linux-gnu", program=program)
|
|
link = bindir / program
|
|
link.unlink(missing_ok=True)
|
|
link.symlink_to(binary.resolve())
|
|
subprocess.run([program, "-version"], check=True, stdout=subprocess.DEVNULL, timeout=30)
|
|
print(f"Parity dependency ready: {program}", flush=True)
|
|
if not shutil.which("typst"):
|
|
subprocess.run(["cargo", "install", "typst-cli", "--version", TYPST_VERSION,
|
|
"--locked", "--root", str(install)], check=True)
|
|
subprocess.run(["typst", "--version"], check=True, timeout=30)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
prepare()
|