#!/usr/bin/env python3 """Check exact vendored pure-Python source hashes before importing them.""" from pathlib import Path import hashlib import json ROOT = Path(__file__).resolve().parent / 'vendor' manifest = json.loads((ROOT / 'manifest.json').read_text()) expected = set() for item in manifest['files']: path = ROOT / item['path'] path.resolve().relative_to(ROOT.resolve()) assert path.is_file(), f"Missing vendored file: {item['path']}" assert hashlib.sha256(path.read_bytes()).hexdigest() == item['sha256'], f"Vendor hash mismatch: {item['path']}" expected.add(item['path']) actual = {p.relative_to(ROOT).as_posix() for p in ROOT.rglob('*') if p.is_file() and p.name != 'manifest.json' and '__pycache__' not in p.parts and p.suffix != '.pyc'} assert actual == expected, f'Unmanifested vendor files: {actual ^ expected}' print(json.dumps(dict(status='verified', files=len(expected), packages=[dict(name=p['distribution'], version=p['version']) for p in manifest['packages']]), indent=2))