File size: 2,797 Bytes
29f25be | 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 | """Create an isolated Mac Git checkout and install the handoff payload."""
import argparse
import json
import shutil
import subprocess
from pathlib import Path, PurePosixPath
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"destination",
nargs="?",
type=Path,
default=Path.home() / "Documents/Sources/VimeML-v21-coreml",
)
args = parser.parse_args()
package = Path(__file__).resolve().parent
manifest = json.loads(
(package / "handoff-manifest.json").read_text(encoding="utf-8")
)
destination = args.destination.expanduser().resolve()
if destination.exists():
parser.error("Destination exists; choose a new checkout directory.")
destination.parent.mkdir(parents=True, exist_ok=True)
subprocess.run(
[
"git",
"clone",
"--branch",
manifest["source_branch"],
str(package / "repository.bundle"),
str(destination),
],
check=True,
)
head = subprocess.check_output(
["git", "rev-parse", "HEAD"], cwd=destination, text=True
).strip()
if head != manifest["source_commit"]:
raise ValueError("Git checkout does not match the recorded source commit.")
subprocess.run(
["git", "remote", "set-url", "origin", manifest["remote"]],
cwd=destination,
check=True,
)
subprocess.run(
["git", "switch", "-c", manifest["mac_branch"]], cwd=destination, check=True
)
for entry in manifest["payload_files"]:
relative = PurePosixPath(entry["path"])
if (
relative.is_absolute()
or ".." in relative.parts
or relative.parts[0] not in {"artifacts", "outputs"}
):
raise ValueError("Unexpected payload path.")
source = package / "payload" / relative
target = destination / relative
if not source.is_file() or source.stat().st_size != entry["bytes"]:
raise ValueError(f"Missing/incomplete payload file: {relative}")
if target.exists():
raise ValueError(f"Payload would overwrite a checkout file: {relative}")
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(source, target)
record = destination / "outputs/deployment/mac-v21-handoff.json"
record.parent.mkdir(parents=True, exist_ok=True)
record.write_text(
json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", encoding="utf-8"
)
print(f"Ready: {destination}")
print("Artifact exchange: docs/reference/artifact-exchange.md")
print(
"No dependencies installed, conversion, quantization or device operation started."
)
if __name__ == "__main__":
main()
|