"""Check the standalone scientific material hashes before running an analysis."""
import hashlib
import json
from pathlib import Path
import sys
folder=Path(sys.argv[1]) if len(sys.argv)>1 else Path('.')
manifest=json.loads((folder/'hashes.json').read_text())
for entry in manifest['files']:
    relative=Path(entry['path'])
    if relative.is_absolute() or '..' in relative.parts:
        raise ValueError('Unsafe public scientific path')
    content=(folder/relative).read_bytes()
    if len(content)!=entry['bytes'] or hashlib.sha256(content).hexdigest()!=entry['sha256']:
        raise ValueError('Changed scientific material: '+entry['path'])
print('PASS',len(manifest['files']),'standalone scientific inputs/scripts/results; no private checkout')
