-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-project.py
executable file
·70 lines (60 loc) · 1.84 KB
/
build-project.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
"""Build pip using pinned build requirements."""
import subprocess
import tempfile
import venv
from os import PathLike
from pathlib import Path
from types import SimpleNamespace
class EnvBuilder(venv.EnvBuilder):
"""A subclass of venv.EnvBuilder that exposes the python executable command."""
def ensure_directories(
self, env_dir: str | bytes | PathLike[str] | PathLike[bytes]
) -> SimpleNamespace:
context = super().ensure_directories(env_dir)
self.env_exec_cmd = context.env_exec_cmd
return context
def get_git_head_timestamp() -> str:
return subprocess.run(
[
"git",
"log",
"-1",
"--pretty=format:%ct",
],
text=True,
stdout=subprocess.PIPE,
).stdout.strip()
def main() -> None:
with tempfile.TemporaryDirectory() as build_env:
env_builder = EnvBuilder(with_pip=True)
# If this venv creation step fails, you may be hitting
# https://github.com/astral-sh/python-build-standalone/issues/381
# Try running with a another Python distribution.
env_builder.create(build_env)
subprocess.run(
[
env_builder.env_exec_cmd,
"-Im",
"pip",
"install",
"--no-deps",
"--only-binary=:all:",
"--require-hashes",
"-r",
Path(__file__).parent / "build-requirements.txt",
],
check=True,
)
subprocess.run(
[
env_builder.env_exec_cmd,
"-Im",
"build",
"--no-isolation",
],
check=True,
env={"SOURCE_DATE_EPOCH": get_git_head_timestamp()},
)
if __name__ == "__main__":
main()