"""Install requirements into the app's virtualenv.

The Setup Python App page has a "Run Pip Install" button, but it is a
split-button that does not fire when driven programmatically. This does
the same thing: the Execute-python-script box runs with the virtualenv's
own interpreter, so pip installs into the right place.
"""

import subprocess
import sys

APP = "/home/abmtgrou/en.tupyfittings.com"

proc = subprocess.run(
    [sys.executable, "-m", "pip", "install", "-r", "requirements.txt"],
    cwd=APP, capture_output=True, text=True,
)
out = "returncode: %s\n--- stdout tail ---\n%s\n--- stderr tail ---\n%s" % (
    proc.returncode, proc.stdout[-2500:], proc.stderr[-1500:])
open(APP + "/pip.out", "w").write(out + "\n")
print(out[-1800:])