package_terminal: --wheelhouse builds with no internet; lock_wheels --download fetches exactly the locked wheels
A box with no DNS (p620) can build the Linux archive from a folder of wheels fetched and hash-checked elsewhere: pip still runs --require-hashes against the lock, with --no-index --find-links.
This commit is contained in:
1 parent
d5be478937
commit
2e324bbbe8
2 files changed
+29
-4
No files matched your search
@@ -9,6 +9,7 @@ packages) by letting pip resolve and download the wheels for the target's tags a
|
||||
|
||||
python packaging/lock_wheels.py --target windows-x86_64 # writes packaging/locks/...
|
||||
python packaging/lock_wheels.py --target linux-x86_64 --check # fails when the committed lock differs
|
||||
python packaging/lock_wheels.py --target linux-x86_64 --download wheelhouse/ # exactly the locked wheels
|
||||
|
||||
Run it when a pin in requirements.txt changes, review the diff, commit. Building an archive never runs it.
|
||||
"""
|
||||
@@ -116,11 +117,30 @@ def build_lock(target: str) -> str:
|
||||
return "\n".join(out) + "\n"
|
||||
|
||||
|
||||
def download_locked(target: str, dest: Path) -> int:
|
||||
"""Fetch exactly the wheels the committed lock names (pip verifies every hash) into `dest`, for a build on a
|
||||
machine with no internet: package_terminal.py --wheelhouse dest. Works from any host for any target."""
|
||||
spec = TARGETS[target]
|
||||
dest.mkdir(parents=True, exist_ok=True)
|
||||
cmd = [sys.executable, "-m", "pip", "download", "--quiet", "--only-binary=:all:", "--require-hashes", "--no-deps",
|
||||
"--python-version", PYTHON, "--implementation", "cp", "--abi", ABI, "-d", str(dest),
|
||||
"-r", str(lock_path(target))]
|
||||
for p in spec["platforms"]:
|
||||
cmd += ["--platform", p]
|
||||
subprocess.run(cmd, check=True)
|
||||
count = len(list(dest.glob("*.whl")))
|
||||
print(f"{count} wheels in {dest}")
|
||||
return 0
|
||||
|
||||
|
||||
def main() -> int:
|
||||
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
ap.add_argument("--target", choices=sorted(TARGETS), required=True)
|
||||
ap.add_argument("--check", action="store_true", help="compare with the committed lock instead of writing")
|
||||
ap.add_argument("--download", metavar="DIR", help="fetch the locked wheels into DIR (hash-checked) and stop")
|
||||
a = ap.parse_args()
|
||||
if a.download:
|
||||
return download_locked(a.target, Path(a.download))
|
||||
text = build_lock(a.target)
|
||||
path = lock_path(a.target)
|
||||
if a.check:
|
||||
|
||||
@@ -167,14 +167,17 @@ def lock_names(lock: Path) -> dict[str, str]:
|
||||
return out
|
||||
|
||||
|
||||
def install_locked(py: Path, lock: Path, root: Path) -> dict[str, str]:
|
||||
"""pip install --require-hashes into the bundled interpreter, then check what is there is exactly the lock."""
|
||||
def install_locked(py: Path, lock: Path, root: Path, wheelhouse: Path | None = None) -> dict[str, str]:
|
||||
"""pip install --require-hashes into the bundled interpreter, then check what is there is exactly the lock.
|
||||
With a wheelhouse (lock_wheels.py --download) nothing is fetched at all: pip reads the wheels from the folder and
|
||||
still checks every hash against the lock."""
|
||||
env = {**os.environ, "PIP_NO_INPUT": "1", "PIP_DISABLE_PIP_VERSION_CHECK": "1", "PYTHONNOUSERSITE": "1",
|
||||
"PIP_CONFIG_FILE": os.devnull}
|
||||
for name in ("PYTHONHOME", "PYTHONPATH", "PIP_REQUIRE_VIRTUALENV", "PIP_INDEX_URL", "PIP_EXTRA_INDEX_URL"):
|
||||
env.pop(name, None)
|
||||
source = ["--no-index", "--find-links", str(wheelhouse)] if wheelhouse else []
|
||||
subprocess.run([str(py), "-m", "pip", "install", "--isolated", "--no-cache-dir", "--no-warn-script-location",
|
||||
"--require-hashes", "--no-deps", "--only-binary=:all:", "-r", str(lock)],
|
||||
"--require-hashes", "--no-deps", "--only-binary=:all:", *source, "-r", str(lock)],
|
||||
check=True, cwd=str(root), env=env)
|
||||
subprocess.run([str(py), "-m", "pip", "check"], check=True, cwd=str(root), env=env)
|
||||
listed = subprocess.run([str(py), "-m", "pip", "list", "--format=json", "--isolated"], check=True,
|
||||
@@ -237,6 +240,8 @@ def main() -> int:
|
||||
help="skip the locked install (layout checks only; the result is NOT distributable)")
|
||||
ap.add_argument("--keep-staging", action="store_true")
|
||||
ap.add_argument("--cache", default=None, help="where the pinned interpreter archive is cached")
|
||||
ap.add_argument("--wheelhouse", default=None,
|
||||
help="install the locked wheels from this folder (lock_wheels.py --download) and fetch nothing")
|
||||
args = ap.parse_args()
|
||||
|
||||
target = args.target or host_target()
|
||||
@@ -297,7 +302,7 @@ def main() -> int:
|
||||
removed: list[str] = []
|
||||
if not args.skip_deps:
|
||||
print("installing the locked runtime wheels into the bundled interpreter (build time only)")
|
||||
installed = install_locked(py, lock, root)
|
||||
installed = install_locked(py, lock, root, Path(args.wheelhouse).resolve() if args.wheelhouse else None)
|
||||
removed = drop_build_path_launchers(root, staging, target)
|
||||
# nothing the bundle writes while it is built may stay: compiled files are rebuilt on first use
|
||||
for cache_dir in list(root.rglob("__pycache__")):
|
||||
|
||||
Reference in new issue
Block a user