#!/usr/bin/env python3 from pathlib import Path import json import re import sys ROOT = Path(__file__).resolve().parents[1] REQUIRED_FILES = [ "README.md", "DATASHEET.md", "METHODS.md", "PRIVACY_AND_DISCLOSURE.md", "EVALUATION_REPORT.md", "EVALUATION_METRICS.json", "SAFE_USE_POLICY.md", "MODEL_AND_DATA_GOVERNANCE.md", "CITATION.cff", "ZENODO_METADATA.json", "datacite_metadata.json", "release_manifest.json", "RELEASE_CHECKLIST.md", "docs/DOI_RELEASE_PLAN.md", "docs/ANNOUNCEMENT_POST.md", "docs/REVIEW_NOTES.md", ] REQUIRED_ARTIFACTS = [ "persona_core", "household_core", "persona_views", "actor_state_init", "benchmark_tasks", "source_registry", "field_provenance", ] REQUIRED_README_STRINGS = [ "Package architecture", "Responsible use", "not observed microdata", "Synthetic personas are not real people", ] def read_json(rel): path = ROOT / rel try: return json.loads(path.read_text(encoding="utf-8")) except Exception as exc: raise ValueError(f"{rel} is not valid JSON: {exc}") from exc def is_lfs_pointer(path): try: head = path.read_bytes()[:120] except OSError: return False return head.startswith(b"version https://git-lfs.github.com/spec/v1") def main(): errors = [] warnings = [] for rel in REQUIRED_FILES: if not (ROOT / rel).exists(): errors.append(f"Missing required file: {rel}") if errors: for err in errors: print("ERROR:", err) return 1 try: manifest = read_json("release_manifest.json") metrics = read_json("EVALUATION_METRICS.json") zenodo = read_json("ZENODO_METADATA.json") datacite = read_json("datacite_metadata.json") except ValueError as exc: print("ERROR:", exc) return 1 readme = (ROOT / "README.md").read_text(encoding="utf-8", errors="ignore") if not readme.startswith("---"): errors.append("README.md does not start with Hugging Face YAML front matter") for needle in REQUIRED_README_STRINGS: if needle not in readme: errors.append(f"README.md missing required text: {needle}") citation = (ROOT / "CITATION.cff").read_text(encoding="utf-8", errors="ignore") for needle in [ "cff-version: 1.2.0", "type: dataset", "license: \"CC-BY-4.0\"", ]: if needle not in citation: errors.append(f"CITATION.cff missing required text: {needle}") doi_pattern = re.compile(r"^10\.\d{4,9}/[-._;()/:A-Za-z0-9]+$") zenodo_doi = zenodo.get("doi") datacite_doi = datacite.get("identifier", {}).get("identifier") citation_doi_match = re.search(r'^doi:\s+"([^"]+)"', citation, re.MULTILINE) citation_doi = citation_doi_match.group(1) if citation_doi_match else None for label, doi in [ ("ZENODO_METADATA.json doi", zenodo_doi), ("datacite_metadata.json identifier", datacite_doi), ("CITATION.cff doi", citation_doi), ]: if doi != "10.XXXX/zenodo.XXXXXXX" and not (isinstance(doi, str) and doi_pattern.match(doi)): errors.append(f"{label} is not a DOI placeholder or valid DOI: {doi!r}") if zenodo_doi and zenodo_doi not in readme and "10.XXXX/zenodo.XXXXXXX" not in readme: errors.append("README.md does not include the Zenodo DOI or placeholder") artifacts = manifest.get("artifacts", {}) for artifact in REQUIRED_ARTIFACTS: entry = artifacts.get(artifact) if not entry: errors.append(f"release_manifest.json missing artifact: {artifact}") continue parquet = entry.get("parquet") if not parquet: errors.append(f"release_manifest.json artifact {artifact} missing parquet path") continue if not (ROOT / parquet).exists(): errors.append(f"Missing artifact file declared in manifest: {parquet}") release = metrics.get("release", {}) manifest_pairs = [ ("total_personas", "personas"), ("total_households", "households"), ("total_persona_views", "persona_views"), ("release_date", "release_date"), ("population_reference_date", "population_reference_date"), ] for manifest_key, metric_key in manifest_pairs: if manifest.get(manifest_key) != release.get(metric_key): errors.append( f"Manifest/metrics mismatch for {manifest_key}/{metric_key}: " f"{manifest.get(manifest_key)!r} != {release.get(metric_key)!r}" ) expected_total_rows = sum( int(artifacts[name]["rows"]) for name in REQUIRED_ARTIFACTS if name in artifacts and "rows" in artifacts[name] ) if expected_total_rows != 8889089: warnings.append(f"Total package rows from manifest are {expected_total_rows:,}, expected v0.1 value is 8,889,089") safe_use = (ROOT / "SAFE_USE_POLICY.md").read_text(encoding="utf-8", errors="ignore") for needle in ["political microtargeting", "individual-level persuasion", "automated eligibility decisions"]: if needle not in safe_use: errors.append(f"SAFE_USE_POLICY.md missing prohibition: {needle}") try: import pyarrow.parquet as pq except Exception as exc: warnings.append(f"pyarrow not available; skipped Parquet row inspection: {exc}") else: for artifact in REQUIRED_ARTIFACTS: entry = artifacts.get(artifact, {}) parquet_name = entry.get("parquet") if not parquet_name: continue path = ROOT / parquet_name if is_lfs_pointer(path): warnings.append(f"{parquet_name} is a Git LFS pointer; skipped Parquet row inspection") continue try: pf = pq.ParquetFile(path) actual_rows = pf.metadata.num_rows except Exception as exc: errors.append(f"Could not inspect {parquet_name}: {exc}") continue expected_rows = int(entry["rows"]) if actual_rows != expected_rows: errors.append(f"{parquet_name} row count mismatch: {actual_rows:,} != {expected_rows:,}") print("Release:", manifest.get("id")) print("Release date:", manifest.get("release_date")) print("Population reference date:", manifest.get("population_reference_date")) print("Manifest package rows:", f"{expected_total_rows:,}") if warnings: print("\nWarnings:") for warning in warnings: print("-", warning) if errors: print("\nValidation errors:") for err in errors: print("-", err) return 1 print("\nOK: release documentation and metadata validation passed") return 0 if __name__ == "__main__": sys.exit(main())