-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_build.py
More file actions
57 lines (42 loc) · 2.16 KB
/
run_build.py
File metadata and controls
57 lines (42 loc) · 2.16 KB
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
"""Script to run the hatch build for a given python version and architecture."""
import itertools
import os
import platform
import subprocess
import sys
from constants import MACHINE_MAPPING_TO_ARCH
def run_hatch_build(python_version: str, build_arch: str) -> None:
"""Run the hatch build for the given Python version and architecture."""
# modify_pyproject_toml(python_version, build_arch)
env = os.environ.copy()
env["PYTHON_BUILD_VERSION"] = python_version
env["BUILD_ARCH"] = build_arch
# Run the hatch build with the environment variables set:
subprocess.run(["uv", "build", "--wheel"], check=True, env=env)
def main(github_actions: bool = False) -> None:
"""Entry point to run the hatch build for the given Python version and architecture.
Make sure to have first downloaded and extracted the release assets from the Github repository.
i.e. run `uv run download_and_extract_assets.py` before running this script.
Args:
github_actions: If the script is running in a Github Actions environment. If true, the
script will run the hatch build for only the Python version and architecture detected.
"""
# Iterate through the Python versions and architectures:
# See the file names in the extracted folder for the exact names:
# This must be the same as the dictionary in the hatch_build.py file
python_versions = ["Python3.9", "Python3.10", "Python3.11", "Python3.12", "Python3.13"]
build_architectures = ["amd64", "arm64", "armhf", "Windows_x64", "Windows_x86"]
if github_actions:
detected_python_version = f"Python{sys.version_info.major}.{sys.version_info.minor}"
detected_arch = MACHINE_MAPPING_TO_ARCH.get(platform.machine())
run_hatch_build(detected_python_version, detected_arch)
else:
for python_version, build_arch in itertools.product(python_versions, build_architectures):
run_hatch_build(python_version, build_arch)
if __name__ == "__main__":
if os.getenv("GITHUB_ACTIONS", "false") == "true":
print("Building in Github Actions environment.")
main(github_actions=True)
else:
print("Building locally")
main()