GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — winpython/build_winpython_meta.py at master · winpython/winpython Expand file tree/ Copy pathbuild_winpython_meta.pyMore file actions 190 lines (170 loc) · 8.24 KB / Copy pathbuild_winpython_meta.pyFile metadata and controls190 lines (170 loc) · 8.24 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 # build_winpython_meta.py # Local builds are made with Python 3.11 or later. import os import sys import shutil import argparse import tomllib # stdlib since 3.11; we choose toml over yaml, more python standard import subprocess from pathlib import Path # Flavor paths are names, not full paths: these say what they hang from. UNDER_BASEDIR = ("requirements", "source_dirs", "wheelhousereq") UNDER_ROOT = ("toolsdirs",) def load_builds(config_file): with open(config_file, "rb") as f: config = tomllib.load(f) python_versions = config.get("pythons", {}) # A file may still spell out one [[builds]] block per build; otherwise the # builds are the (python, flavor) pairs [pythons] asks for. builds = config["builds"] if "builds" in config else expand_builds(config) return builds, python_versions def expand_builds(config): """One build per flavor listed by each [pythons."3XX"], paths derived. A flavor names its files relative to the build directory, so a new Python minor is one [pythons] block. Where a Python needs its own file - a requirements list under another name, say - [pythons."3XX".overrides.flavor] replaces that flavor's entries for that Python alone. """ defaults = config.get("defaults", {}) flavors = config.get("flavors", {}) builds = [] for target, vinfo in config.get("pythons", {}).items(): root = Path(vinfo.get("root_dir_for_builds", defaults.get("root_dir_for_builds", ""))) basedir = root / f"bd{target}" overrides = vinfo.get("overrides", {}) for flavor in vinfo.get("builds", []): if flavor not in flavors: raise KeyError(f"python {target} builds {flavor!r}, which has no [flavors.{flavor}]") build = {**defaults, "name": flavor, "python_target": target, "flavor": flavor} for key, value in {**flavors[flavor], **overrides.get(flavor, {})}.items(): if key in UNDER_BASEDIR: value = str(basedir / value) elif key in UNDER_ROOT: value = str(root / value) build[key] = value builds.append(build) return builds def select_builds(builds, wanted): """Builds asked for on the command line: "315", "315:slim", ":slim".""" if not wanted: return builds kept = [] for spec in wanted: target, _, flavor = spec.partition(":") matching = [b for b in builds if (not target or b["python_target"] == target) and (not flavor or b["flavor"] == flavor)] if not matching: raise SystemExit(f"no build matches {spec!r}") kept += [b for b in matching if b not in kept] return kept def must_exist(path, build, key): """pip_install() skips a missing requirements file without failing, which would drop those packages silently. Say so instead.""" if path and not Path(path).exists(): raise FileNotFoundError(f"build {build['name']!r} needs {key} = {path!r}, which does not exist") return path def declared_file(build, key, default): """Path named by the build for `key`, else `default`.""" declared = build.get(key) return str(default) if declared is None else must_exist(str(declared), build, key) def copy_lockfiles(build_dir, lock_dir, overwrite=False, dry_run=False): """Copy the build's pylock and requir files to lock_dir, e.g. a cycle_XXXX_XX. A file already there is kept unless overwrite: a published lock must not be replaced by accident. The _wheels locks are build scaffolding, not copied. """ lock_dir = Path(lock_dir) files = [f for pattern in ("pylock.*.toml", "requir.*.txt") for f in sorted(Path(build_dir).glob(pattern)) if "_wheels" not in f.name] if not files: print(f"no lockfile to copy in {build_dir}") for f in files: dest = lock_dir / f.name if dest.exists() and not overwrite: print(f"kept existing {dest} (use --lock-overwrite to replace)") continue print(f"{'would copy' if dry_run else 'copy'} {f} -> {dest}") if not dry_run: lock_dir.mkdir(parents=True, exist_ok=True) shutil.copy2(f, dest) def run_build(build, python_versions, dry_run=False, lock_dir=None, lock_overwrite=False): print(f"\n=== Building WinPython: {build['python_target']} {build['name']} ===") print(build) root_dir_for_builds = build["root_dir_for_builds"] my_python_target = build["python_target"] my_flavor = build["flavor"] my_arch = str(build["arch"]) my_create_installer = build.get("create_installer", "True") my_requirements = must_exist(build.get("requirements", ""), build, "requirements") my_source_dirs = build.get("source_dirs", "") my_find_links = build.get("find_links", "") my_toolsdirs = build.get("toolsdirs", "") wheelhousereq = must_exist(build.get("wheelhousereq", ""), build, "wheelhousereq") # "pip" (default, what ships) | "none" | "parallel" | "parallel-N" my_bytecode = build.get("bytecode", "pip") # wheels only, unless a flavor still has a package with no wheel for its target my_only_binary = "yes" if build.get("only_binary", True) else "no" # Get Python release info from TOML [pythons] py_target = my_python_target vinfo = python_versions.get(py_target, {}) my_python_target_release = vinfo.get("python_target_release", "") my_release = vinfo.get("release", "") my_release_level = vinfo.get("my_release_level", "b0") # A build may name its own file for a specific problem; otherwise the one # shipped beside this script is used. here = Path(__file__).parent mandatory_requirements = declared_file(build, "mandatory_requirements", here / "mandatory_requirements.txt") my_constraints = declared_file(build, "constraints", here / "constraints.txt") # Build directory logic my_basedir = f"{root_dir_for_builds}\\bd{my_python_target}" my_WINPYDIRBASE = f"{my_basedir}\\bu{my_flavor}\\WPy{my_arch}-{my_python_target_release}{my_release}{my_release_level}" # Build env paths (customize as needed) already defined per the launcher of that script... my_python_exe = Path(sys.executable) my_buildenvi = str(my_python_exe.parent) my_archive_dir = os.path.join(os.getcwd(), "WinPython_build_logs") os.makedirs(my_archive_dir, exist_ok=True) # Build command build_cmd = [ str(my_python_exe), "-m", "winpython.build_winpython", "--buildenv", my_buildenvi, "--python-target", my_python_target, "--release", my_release, "--release-level", my_release_level, "--winpydirbase", my_WINPYDIRBASE, "--flavor", my_flavor, "--source_dirs", my_source_dirs, "--tools_dirs", my_toolsdirs, "--log-dir", my_archive_dir, "--mandatory-req", mandatory_requirements, "--requirements", my_requirements, "--constraints", my_constraints, "--find-links", my_find_links, "--wheelhousereq", wheelhousereq, "--bytecode", my_bytecode, "--only-binary", my_only_binary, "--create-installer", my_create_installer, ] print("Dry run, build command:" if dry_run else "Running build command:") print(" ".join(build_cmd)) if not dry_run: returncode = subprocess.run(build_cmd, check=False).returncode if returncode: print(f"build failed ({returncode}), no lockfile copied") return if lock_dir: copy_lockfiles(Path(my_WINPYDIRBASE).parent, lock_dir, lock_overwrite, dry_run) def main(): parser = argparse.ArgumentParser() parser.add_argument("config", nargs="?", default="winpython_builds.toml") parser.add_argument("builds", nargs="*", help='"315", "315:slim", ":slim"') parser.add_argument("--dry-run", action="store_true") parser.add_argument("--lock-dir", help="copy the pylock and requir files there") parser.add_argument("--lock-overwrite", action="store_true", help="replace files already in --lock-dir") args = parser.parse_args() builds, python_versions = load_builds(args.config) for build in select_builds(builds, args.builds): run_build(build, python_versions, args.dry_run, args.lock_dir, args.lock_overwrite) if __name__ == "__main__": main() |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |