-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
build-windows.py
55 lines (42 loc) · 1.45 KB
/
build-windows.py
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
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
import os
import pathlib
import subprocess
import sys
import venv
ROOT = pathlib.Path(os.path.abspath(__file__)).parent
BUILD = ROOT / "build"
DIST = ROOT / "dist"
VENV = BUILD / "venv"
PIP = VENV / "Scripts" / "pip.exe"
PYTHON = VENV / "Scripts" / "python.exe"
REQUIREMENTS = ROOT / "requirements.win.txt"
WINDOWS_DIR = ROOT / "cpython-windows"
def bootstrap():
BUILD.mkdir(exist_ok=True)
DIST.mkdir(exist_ok=True)
venv.create(VENV, with_pip=True)
subprocess.run([str(PIP), "install", "-r", str(REQUIREMENTS)], check=True)
os.environ["PYBUILD_BOOTSTRAPPED"] = "1"
os.environ["PATH"] = "%s;%s" % (str(VENV / "bin"), os.environ["PATH"])
os.environ["PYTHONPATH"] = str(ROOT)
args = [str(PYTHON), __file__]
args.extend(sys.argv[1:])
subprocess.run(args, check=True)
def run():
env = dict(os.environ)
env["PYTHONUNBUFFERED"] = "1"
args = [str(PYTHON), "build.py"]
args.extend(sys.argv[1:])
subprocess.run(args, cwd=str(WINDOWS_DIR), env=env, check=True, bufsize=0)
if __name__ == "__main__":
try:
if "PYBUILD_BOOTSTRAPPED" not in os.environ:
bootstrap()
else:
run()
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)