Spaces:
Running
Running
File size: 1,475 Bytes
7c9e8d9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #!/usr/bin/env python3
"""Zero-dependency Hugging Face Static Space preflight."""
from pathlib import Path
import json,re,hashlib
root=Path(__file__).resolve().parent
readme=(root/'README.md').read_text(encoding='utf-8')
assert readme.startswith('---\n'), 'Missing README front matter'
front=readme.split('---',2)[1]
values=dict(re.findall(r'^([A-Za-z_]+):\s*(.*?)\s*$',front,re.M))
assert values['sdk']=='static', 'Space needs sdk: static'
assert values['app_file']=='index.html', 'Wrong app file'
assert values['license']=='mit', 'Wrong code license'
assert len(values['short_description'])<=60, 'Short description too long'
assert values['colorFrom'] in {'red','yellow','green','blue','indigo','purple','pink','gray'}
assert values['colorTo'] in {'red','yellow','green','blue','indigo','purple','pink','gray'}
for name in ('index.html','styles.css','engine.js','app.js','train.json','iid_test.json','challenge.json'):
assert (root/name).is_file(), 'Missing '+name
manifest=json.loads((root/'dataset_manifest.json').read_text())
for name,digest in manifest['files_sha256'].items():
assert hashlib.sha256((root/name).read_bytes()).hexdigest()==digest, f'Data checksum changed: {name}'
for name,count in [('train.json',842),('iid_test.json',130),('challenge.json',54)]:
assert len(json.loads((root/name).read_text()))==count,name
print('PASS: Static SDK, app entry point, license, 60-char description, colors, source files, dataset SHA256 and partition counts.')
|