File size: 1,851 Bytes
c9bff01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Export locked dependencies for the Linux/Python 3.12 HF Spaces runtime."""

import argparse
from pathlib import Path
import subprocess


ROOT = Path(__file__).resolve().parents[1]


def export_requirements() -> str:
    locked = subprocess.run(
        [
            "uv",
            "export",
            "--locked",
            "--no-dev",
            "--no-hashes",
            "--no-emit-project",
            "--no-annotate",
            "--no-header",
        ],
        cwd=ROOT,
        check=True,
        text=True,
        stdout=subprocess.PIPE,
    ).stdout
    # The lock already contains the full graph. Only select the target platform;
    # do not expand dependencies or carry Windows CUDA pins into ZeroGPU config.
    return subprocess.run(
        [
            "uv",
            "pip",
            "compile",
            "-",
            "--no-deps",
            "--python-platform=x86_64-unknown-linux-gnu",
            "--python-version=3.12",
            "--only-binary=:all:",
            "--no-annotate",
            "--custom-compile-command=uv run --locked python scripts/export_requirements.py",
        ],
        cwd=ROOT,
        input=locked,
        check=True,
        text=True,
        stdout=subprocess.PIPE,
    ).stdout


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--check", action="store_true", help="Check without writing")
    args = parser.parse_args()
    requirements = export_requirements()
    destination = ROOT / "requirements.txt"
    if args.check:
        if destination.read_text(encoding="utf-8") != requirements:
            parser.exit(
                1, "requirements.txt is stale; run scripts/export_requirements.py\n"
            )
    else:
        destination.write_text(requirements, encoding="utf-8", newline="\n")