Skip to content

Commit fa176fe

Browse files
authored
use uv to bootstrap the host system Python environment (#892)
Add a new build script which uses uv to bootstrap the Python environment on the host and runs the build. To use this new script on a host with uv installed use: ``` ./build-uv.py ```
1 parent 6945a61 commit fa176fe

File tree

8 files changed

+1022
-30
lines changed

8 files changed

+1022
-30
lines changed

.github/workflows/linux.yml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ jobs:
7171
with:
7272
persist-credentials: false
7373

74-
- name: Install Python
75-
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
74+
- name: Set up uv
75+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
7676
with:
77-
python-version: "3.11"
77+
enable-cache: false
7878

7979
- name: Set up Docker Buildx
8080
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
@@ -88,7 +88,7 @@ jobs:
8888

8989
- name: Generate Dockerfiles
9090
run: |
91-
./build-linux.py --make-target empty
91+
./build-uv.py --make-target empty
9292
repo_name=$(echo "${GITHUB_REPOSITORY,,}" | sed 's|\.|_|g')
9393
git_ref_name=$(echo "${GITHUB_REF_NAME,,}" | sed 's|[^a-z0-9_-]|_|g')
9494
echo "REPO_NAME=${repo_name}" >> "${GITHUB_ENV}"
@@ -150,8 +150,10 @@ jobs:
150150
fetch-depth: 0
151151
persist-credentials: false
152152

153-
- name: Set up Python
154-
uses: astral-sh/setup-uv@38f3f104447c67c051c4a08e39b64a148898af3a # v4.2.0
153+
- name: Set up uv
154+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
155+
with:
156+
enable-cache: false
155157

156158
- name: Get pull request labels
157159
id: get-labels
@@ -222,10 +224,10 @@ jobs:
222224
fetch-depth: 0
223225
persist-credentials: false
224226

225-
- name: Install Python
226-
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
227+
- name: Set up uv
228+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
227229
with:
228-
python-version: "3.11"
230+
enable-cache: false
229231

230232
- name: Download pythonbuild
231233
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
@@ -265,12 +267,12 @@ jobs:
265267
if: ${{ ! matrix.dry-run }}
266268
run: |
267269
# Do empty target so all generated files are touched.
268-
./build-linux.py --make-target empty
270+
./build-uv.py --make-target empty
269271
270272
# Touch mtimes of all images so they are newer than autogenerated files above.
271273
touch build/image-*
272274
273-
./build-linux.py --target-triple ${MATRIX_TARGET_TRIPLE} --python cpython-${MATRIX_PYTHON} --options ${MATRIX_BUILD_OPTIONS}
275+
./build-uv.py --target-triple ${MATRIX_TARGET_TRIPLE} --python cpython-${MATRIX_PYTHON} --options ${MATRIX_BUILD_OPTIONS}
274276
env:
275277
MATRIX_TARGET_TRIPLE: ${{ matrix.target_triple }}
276278
MATRIX_PYTHON: ${{ matrix.python }}
@@ -330,10 +332,10 @@ jobs:
330332
fetch-depth: 0
331333
persist-credentials: false
332334

333-
- name: Install Python
334-
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
335+
- name: Set up uv
336+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
335337
with:
336-
python-version: "3.11"
338+
enable-cache: false
337339

338340
- name: Download pythonbuild
339341
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
@@ -373,12 +375,12 @@ jobs:
373375
if: ${{ ! matrix.dry-run }}
374376
run: |
375377
# Do empty target so all generated files are touched.
376-
./build-linux.py --make-target empty
378+
./build-uv.py --make-target empty
377379
378380
# Touch mtimes of all images so they are newer than autogenerated files above.
379381
touch build/image-*
380382
381-
./build-linux.py --target-triple ${MATRIX_TARGET_TRIPLE} --python cpython-${MATRIX_PYTHON} --options ${MATRIX_BUILD_OPTIONS}
383+
./build-uv.py --target-triple ${MATRIX_TARGET_TRIPLE} --python cpython-${MATRIX_PYTHON} --options ${MATRIX_BUILD_OPTIONS}
382384
env:
383385
MATRIX_TARGET_TRIPLE: ${{ matrix.target_triple }}
384386
MATRIX_PYTHON: ${{ matrix.python }}

.github/workflows/macos.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ jobs:
6363
fetch-depth: 0
6464
persist-credentials: false
6565

66-
- name: Set up Python
67-
uses: astral-sh/setup-uv@38f3f104447c67c051c4a08e39b64a148898af3a # v4.2.0
66+
- name: Set up uv
67+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
68+
with:
69+
enable-cache: false
6870

6971
- name: Get pull request labels
7072
id: get-labels
@@ -128,10 +130,10 @@ jobs:
128130
fetch-depth: 0
129131
persist-credentials: false
130132

131-
- name: Install Python
132-
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
133+
- name: Set up uv
134+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
133135
with:
134-
python-version: "3.11"
136+
enable-cache: false
135137

136138
- name: Download pythonbuild
137139
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
@@ -142,7 +144,7 @@ jobs:
142144
- name: Build
143145
if: ${{ ! matrix.dry-run }}
144146
run: |
145-
./build-macos.py --target-triple ${MATRIX_TARGET_TRIPLE} --python cpython-${MATRIX_PYTHON} --options ${MATRIX_BUILD_OPTIONS}
147+
./build-uv.py --target-triple ${MATRIX_TARGET_TRIPLE} --python cpython-${MATRIX_PYTHON} --options ${MATRIX_BUILD_OPTIONS}
146148
env:
147149
MATRIX_TARGET_TRIPLE: ${{ matrix.target_triple }}
148150
MATRIX_PYTHON: ${{ matrix.python }}

.github/workflows/windows.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ jobs:
6363
fetch-depth: 0
6464
persist-credentials: false
6565

66-
- name: Set up Python
67-
uses: astral-sh/setup-uv@38f3f104447c67c051c4a08e39b64a148898af3a # v4.2.0
66+
- name: Set up uv
67+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
68+
with:
69+
enable-cache: false
6870

6971
- name: Get pull request labels
7072
id: get-labels
@@ -134,10 +136,10 @@ jobs:
134136
with:
135137
packages: autoconf automake libtool
136138

137-
- name: Install Python
138-
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
139+
- name: Set up uv
140+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
139141
with:
140-
python-version: "3.12"
142+
enable-cache: false
141143

142144
- name: Download pythonbuild Executable
143145
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
@@ -148,14 +150,14 @@ jobs:
148150
# don't get compiled properly.
149151
- name: Bootstrap Python environment
150152
run: |
151-
py.exe -3.12 build-windows.py --help
153+
uv run build-uv.py --help
152154
153155
- name: Build
154156
if: ${{ ! matrix.dry-run }}
155157
shell: cmd
156158
run: |
157159
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\%MATRIX_VCVARS%"
158-
py.exe -3.12 build-windows.py --python cpython-%MATRIX_PYTHON% --sh c:\cygwin\bin\sh.exe --options %MATRIX_BUILD_OPTIONS%
160+
uv run build-uv.py --python cpython-%MATRIX_PYTHON% --sh c:\cygwin\bin\sh.exe --options %MATRIX_BUILD_OPTIONS%
159161
env:
160162
MATRIX_VCVARS: ${{ matrix.vcvars }}
161163
MATRIX_PYTHON: ${{ matrix.python }}

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

build-uv.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env -S uv run
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
6+
import os
7+
import pathlib
8+
import platform
9+
import subprocess
10+
import sys
11+
12+
ROOT = pathlib.Path(os.path.abspath(__file__)).parent
13+
14+
15+
def run():
16+
env = dict(os.environ)
17+
env["PYTHONUNBUFFERED"] = "1"
18+
python = sys.executable
19+
system = platform.system()
20+
21+
if system == "Darwin" or system == "Linux":
22+
args = [
23+
python,
24+
"build-main.py",
25+
*sys.argv[1:],
26+
]
27+
make_dir = ROOT / "cpython-unix"
28+
os.chdir(make_dir)
29+
return os.execve(python, args, env)
30+
elif system == "Windows":
31+
args = [
32+
python,
33+
"build.py",
34+
*sys.argv[1:],
35+
]
36+
cwd = str(ROOT / "cpython-windows")
37+
return subprocess.run(args, cwd=cwd, env=env, check=True, bufsize=0)
38+
else:
39+
raise Exception(f"Unsupported host system: {system}")
40+
41+
42+
if __name__ == "__main__":
43+
try:
44+
run()
45+
except subprocess.CalledProcessError as e:
46+
sys.exit(e.returncode)

cpython-windows/build.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,8 @@ def build_cpython(
15121512
p for p in env["PATH"].split(";") if p != str(BUILD / "venv" / "bin")
15131513
]
15141514
env["PATH"] = ";".join(paths)
1515-
del env["PYTHONPATH"]
1515+
if "PYTHONPATH" in env:
1516+
del env["PYTHONPATH"]
15161517

15171518
env["PYTHONHOME"] = str(cpython_source_path)
15181519

@@ -1974,6 +1975,7 @@ def main() -> None:
19741975
release_tag = release_tag_from_git()
19751976

19761977
# Create, e.g., `cpython-3.10.13+20240224-x86_64-pc-windows-msvc-pgo.tar.zst`.
1978+
DIST.mkdir(exist_ok=True)
19771979
compress_python_archive(
19781980
tar_path,
19791981
DIST,

pyproject.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[project]
2+
name = "python-build-standalone"
3+
version = "0.1.0"
4+
description = "Produces standalone, highly-redistributable builds of Python."
5+
readme = "README.rst"
6+
requires-python = ">=3.10"
7+
dependencies = [
8+
"docker>=7.1.0",
9+
"jinja2>=3.1.5",
10+
"jsonschema>=4.23.0",
11+
"pygithub>=2.6.1 ; platform_machine != 'aarch64' or sys_platform != 'win32'",
12+
"pyyaml>=6.0.2",
13+
"six>=1.17.0",
14+
"tomli>=2.2.1",
15+
"typing-extensions>=4.14.1",
16+
"zstandard>=0.23.0",
17+
]
18+
19+
[build-system]
20+
requires = ["uv_build>=0.9.12,<0.10.0"]
21+
build-backend = "uv_build"
22+
23+
[tool.uv.build-backend]
24+
module-name = "pythonbuild"
25+
module-root = ""

0 commit comments

Comments
 (0)