|
| 1 | +import os |
| 2 | +import sys |
| 3 | +# Use tomllib if available (Python 3.11+), otherwise fall back to tomli |
| 4 | +try: |
| 5 | + import tomllib # Python 3.11+ |
| 6 | +except ImportError: |
| 7 | + try: |
| 8 | + import tomli as tomllib # For older Python versions |
| 9 | + except ImportError: |
| 10 | + print("Please install tomli for Python < 3.11: pip install tomli") |
| 11 | + sys.exit(1) |
| 12 | + |
| 13 | +#import yaml |
| 14 | +import subprocess |
| 15 | +from pathlib import Path |
| 16 | + |
| 17 | +def load_builds(config_file): |
| 18 | + with open(config_file, "rb") as f: |
| 19 | + config = tomllib.load(f) |
| 20 | + builds = config["builds"] |
| 21 | + python_versions = config.get("pythons", {}) |
| 22 | + return builds, python_versions |
| 23 | + #with open(config_file, "r", encoding="utf-8") as f: |
| 24 | + # return yaml.safe_load(f)["builds"] |
| 25 | + |
| 26 | +def run_build(build, python_versions): |
| 27 | + print(f"\n=== Building WinPython: {build['name']} ===") |
| 28 | + print(build) |
| 29 | + |
| 30 | + root_dir_for_builds = build["root_dir_for_builds"] |
| 31 | + my_python_target = build["python_target"] |
| 32 | + my_flavor = build["flavor"] |
| 33 | + my_arch = str(build["arch"]) |
| 34 | + my_create_installer = build.get("create_installer", "True") |
| 35 | + my_requirements = build.get("requirements", "") |
| 36 | + my_source_dirs = build.get("source_dirs", "") |
| 37 | + my_find_links = build.get("find_links", "") |
| 38 | + my_toolsdirs = build.get("toolsdirs", "") |
| 39 | + #my_install_options = build.get("install_options", "") |
| 40 | + wheelhousereq = build.get("wheelhousereq", "") |
| 41 | + |
| 42 | + # Get Python release info from TOML [pythons] |
| 43 | + py_target = my_python_target |
| 44 | + vinfo = python_versions.get(py_target, {}) |
| 45 | + my_python_target_release = vinfo.get("python_target_release", "") |
| 46 | + my_release = vinfo.get("release", "") |
| 47 | + my_release_level = vinfo.get("my_release_level", "b0") |
| 48 | + mandatory_requirements = vinfo.get("mandatory_requirements", os.path.join(os.getcwd(), "mandatory_requirements.txt")) |
| 49 | + |
| 50 | + # Get Python release info from TOML [pythons] |
| 51 | + my_constraints = build.get("my_constraints", r"C:\WinP\constraints.txt") |
| 52 | + target_python_exe = build.get("target_python_exe", "python.exe") |
| 53 | + |
| 54 | + # Build directory logic |
| 55 | + my_basedir = f"{root_dir_for_builds}\\bd{my_python_target}" |
| 56 | + my_WINPYDIRBASE = f"{my_basedir}\\bu{my_flavor}\\WPy{my_arch}-{my_python_target_release}{my_release}{my_release_level}" |
| 57 | + |
| 58 | + # Build env paths (customize as needed) already defined per the launcher of that script... |
| 59 | + |
| 60 | + my_python_exe = Path(sys.executable) |
| 61 | + my_buildenvi = str(my_python_exe.parent) |
| 62 | + |
| 63 | + my_archive_dir = os.path.join(os.getcwd(), "WinPython_build_logs") |
| 64 | + os.makedirs(my_archive_dir, exist_ok=True) |
| 65 | + |
| 66 | + my_requirements_pre = build.get("my_requirements_pre", mandatory_requirements) |
| 67 | + |
| 68 | + # Build command |
| 69 | + build_cmd = [ |
| 70 | + str(my_python_exe), |
| 71 | + "-m", "winpython.build_winpython", |
| 72 | + "--buildenv", my_buildenvi, |
| 73 | + "--python-target", my_python_target, |
| 74 | + "--release", my_release, |
| 75 | + "--release-level", my_release_level, |
| 76 | + "--winpydirbase", my_WINPYDIRBASE, |
| 77 | + "--flavor", my_flavor, |
| 78 | + "--source_dirs", my_source_dirs, |
| 79 | + "--tools_dirs", my_toolsdirs, |
| 80 | + "--log-dir", my_archive_dir, |
| 81 | + "--mandatory-req", mandatory_requirements, |
| 82 | + "--pre-req", my_requirements_pre, |
| 83 | + "--requirements", my_requirements, |
| 84 | + "--constraints", my_constraints, |
| 85 | + "--find-links", my_find_links, |
| 86 | + "--wheelhousereq", wheelhousereq, |
| 87 | + "--create-installer", my_create_installer, |
| 88 | + #"--install-options", env["my_install_options"], |
| 89 | + ] |
| 90 | + |
| 91 | + print("Running build command:") |
| 92 | + print(" ".join(build_cmd)) |
| 93 | + subprocess.run(build_cmd, cwd=os.getcwd(), check=False) |
| 94 | + |
| 95 | +def main(): |
| 96 | + config_file = sys.argv[1] if len(sys.argv) > 1 else "winpython_buildsZZZ.toml" |
| 97 | + builds, python_versions = load_builds(config_file) |
| 98 | + for build in builds: |
| 99 | + run_build(build, python_versions) |
| 100 | + |
| 101 | +if __name__ == "__main__": |
| 102 | + main() |
0 commit comments