File size: 908 Bytes
7e2301f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Run a shell command on the remote GPU box and print its output.

  MARIMO_URL=... MARIMO_TOKEN=... python tools/remote_sh.py "cd /root/PhotonTTS && pytest -q"
"""

from __future__ import annotations

import os
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent))
from push_remote import DEFAULT_EXEC, run_remote  # noqa: E402


def main():
    sys.stdout.reconfigure(encoding="utf-8", errors="replace")
    cmd = " ".join(sys.argv[1:])
    timeout = int(os.environ.get("REMOTE_TIMEOUT", 3600))
    code = (
        "import subprocess\n"
        f"r = subprocess.run({cmd!r}, shell=True, capture_output=True, text=True, timeout={timeout})\n"
        "print(r.stdout[-20000:], r.stderr[-5000:], f'[exit {r.returncode}]')\n"
    )
    print(run_remote(code, os.environ["MARIMO_URL"], os.environ["MARIMO_TOKEN"], DEFAULT_EXEC))


if __name__ == "__main__":
    main()