File size: 1,995 Bytes
e1ced61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Freeze a locally verified candidate. This script has no upload capability."""

import argparse
import json
from pathlib import Path

from hf_release_common import VERSION, file_digest, read_json, write_json


def freeze(dataset):
    required = [
        "dataset-validation.json",
        "replay-validation.json",
        "gqa-reconstruction-validation.json",
    ]
    for name in required:
        if read_json(dataset / "validation" / name).get("status") != "passed":
            raise ValueError("Missing successful release check: " + name)
    files = {}
    for path in sorted(dataset.rglob("*")):
        if path.is_symlink():
            raise ValueError("Symlink in upload candidate")
        if not path.is_file() or path.name == "MANIFEST.json":
            continue
        relative = str(path.relative_to(dataset))
        if (
            any(part in {".git", ".cache", ".venv", "__pycache__"} for part in path.parts)
            or path.suffix in {".pyc", ".log"}
            or path.name.startswith(".env")
        ):
            raise ValueError("Unintended local file in upload candidate: " + relative)
        files[relative] = {"bytes": path.stat().st_size, "sha256": file_digest(path)}
    manifest = {
        "version": VERSION,
        "purpose": "Release integrity and provenance, separate from semantic/pixel witness evidence",
        "files": files,
        "total_bytes": sum(row["bytes"] for row in files.values()),
        "publication_performed": False,
    }
    write_json(dataset / "MANIFEST.json", manifest)
    return {
        "status": "frozen_not_uploaded",
        "files": len(files),
        "bytes": manifest["total_bytes"],
        "manifest_sha256": file_digest(dataset / "MANIFEST.json"),
    }


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--dataset", type=Path, required=True)
    args = parser.parse_args()
    print(json.dumps(freeze(args.dataset)))