Skip to content

Commit a06d4b7

Browse files
committed
Make build-project.py portable
1 parent f06bd2d commit a06d4b7

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

build-project.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22
"""Build pip using pinned build requirements."""
33

44
import subprocess
5-
import sys
65
import tempfile
6+
import venv
7+
from os import PathLike
78
from pathlib import Path
9+
from types import SimpleNamespace
10+
11+
12+
class EnvBuilder(venv.EnvBuilder):
13+
"""A subclass of venv.EnvBuilder that exposes the python executable command."""
14+
15+
def ensure_directories(
16+
self, env_dir: str | bytes | PathLike[str] | PathLike[bytes]
17+
) -> SimpleNamespace:
18+
context = super().ensure_directories(env_dir)
19+
self.env_exec_cmd = context.env_exec_cmd
20+
return context
821

922

1023
def get_git_head_timestamp() -> str:
@@ -22,19 +35,11 @@ def get_git_head_timestamp() -> str:
2235

2336
def main() -> None:
2437
with tempfile.TemporaryDirectory() as build_env:
38+
env_builder = EnvBuilder(with_pip=True)
39+
env_builder.create(build_env)
2540
subprocess.run(
2641
[
27-
sys.executable,
28-
"-m",
29-
"venv",
30-
build_env,
31-
],
32-
check=True,
33-
)
34-
build_python = Path(build_env) / "bin" / "python"
35-
subprocess.run(
36-
[
37-
build_python,
42+
env_builder.env_exec_cmd,
3843
"-Im",
3944
"pip",
4045
"install",
@@ -48,7 +53,7 @@ def main() -> None:
4853
)
4954
subprocess.run(
5055
[
51-
build_python,
56+
env_builder.env_exec_cmd,
5257
"-Im",
5358
"build",
5459
"--no-isolation",

0 commit comments

Comments
 (0)