Download scripts/check-package.py from tinjyuu/pompom: direct link, hf CLI and curl.
- Browser
- Download file 2.3 kB
-
https://huggingface.co/spaces/tinjyuu/pompom/resolve/main/scripts/check-package.py
- Command line
-
hf download hf://spaces/tinjyuu/pompom/scripts/check-package.py
-
curl -L -o check-package.py https://huggingface.co/spaces/tinjyuu/pompom/resolve/main/scripts/check-package.py
2.3 kB
| """Check the actual wheel and sdist for isolation and required runtime assets.""" | |
| import tarfile | |
| import struct | |
| import zipfile | |
| from pathlib import Path | |
| root = Path(__file__).resolve().parents[1] | |
| required = {'pompom/main.py', 'pompom/static/index.html', 'pompom/static/main.js', 'pompom/assets/reminder-1.wav', 'pompom/assets/reminder-2.wav', 'pompom/speech.py', 'pompom/assets/speech-slouch.wav', 'pompom/assets/speech-custom.wav', 'pompom/assets/speech-phone-slouch.wav', 'pompom/assets/speech-phone-custom.wav', 'pompom/assets/speech-slouch-custom.wav', 'pompom/assets/speech-phone-slouch-custom.wav'} | |
| def check_wav(data, name): | |
| fmt = data.index(b'fmt ') + 8 | |
| encoding, channels, rate, byte_rate, alignment, bits = struct.unpack_from('<HHIIHH', data, fmt) | |
| assert encoding == 1 and alignment == channels * bits // 8, name | |
| assert byte_rate == rate * alignment, f'{name}: invalid WAV byte rate' | |
| import tomllib | |
| version = tomllib.loads((root / 'pyproject.toml').read_text())['project']['version'] | |
| for path in [*sorted((root / 'dist').glob(f'pompom-{version}-*.whl')), *sorted((root / 'dist').glob(f'pompom-{version}.tar.gz'))]: | |
| if path.suffix == '.whl': | |
| with zipfile.ZipFile(path) as archive: | |
| names = archive.namelist() | |
| for name in names: | |
| if name.endswith('.wav'): | |
| check_wav(archive.read(name), name) | |
| assert all(n.startswith('pompom/') or '.dist-info/' in n for n in names), names | |
| else: | |
| with tarfile.open(path) as archive: | |
| names = [n.split('/', 1)[1].removeprefix('src/') for n in archive.getnames() if '/' in n] | |
| for member in archive.getmembers(): | |
| if member.isfile() and member.name.endswith('.wav'): | |
| check_wav(archive.extractfile(member).read(), member.name) | |
| assert not any(n.split('/')[0] in {'api','apps','clients','devices','docs','tests','scripts','.venv'} for n in names) | |
| assert required <= set(names), required - set(names) | |
| assert not any('__pycache__' in n or n.endswith(('.pyc','.env','settings.json')) for n in names) | |
| print(f'OK: {path.name} — Reachy-only package with UI and audio') | |
| assert list((root / 'dist').glob('*.whl')) and list((root / 'dist').glob('*.tar.gz')), 'Build first: python -m build' | |