Download src/restore_source_checkout.py from DanielNguyen121/IsSynth-Cars: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/DanielNguyen121/IsSynth-Cars/resolve/main/src/restore_source_checkout.py
- Command line
-
hf download hf://DanielNguyen121/IsSynth-Cars/src/restore_source_checkout.py
-
curl -L -o restore_source_checkout.py https://huggingface.co/DanielNguyen121/IsSynth-Cars/resolve/main/src/restore_source_checkout.py
1.77 kB
| #!/usr/bin/env python3 | |
| """Restore the pinned SPC Git checkout when Molab supplies only a source snapshot.""" | |
| from pathlib import Path | |
| import hashlib | |
| import subprocess | |
| ROOT = Path('/marimo/SPC') | |
| STAGING = Path('/marimo/SPC_official_restore') | |
| BACKUP = Path('/marimo/SPC_snapshot_backup_20261025') | |
| COMMIT = '96834b22d5e59c852e53d713d434cbabb2f0d165' | |
| def revision(path): | |
| result = subprocess.run(['git', '-C', str(path), 'rev-parse', 'HEAD'], capture_output=True, text=True) | |
| return result.stdout.strip() if result.returncode == 0 else None | |
| if revision(ROOT) == COMMIT: | |
| print('SPC_SOURCE_READY', COMMIT, flush=True) | |
| else: | |
| if (ROOT / '.git').exists(): | |
| raise RuntimeError('Existing SPC Git checkout has a different revision; refusing to replace it') | |
| if not STAGING.exists(): | |
| subprocess.run(['git', 'clone', '--quiet', 'https://github.com/thanhhai1988/SPC.git', str(STAGING)], check=True) | |
| subprocess.run(['git', '-C', str(STAGING), 'checkout', '--quiet', COMMIT], check=True) | |
| if ROOT.exists(): | |
| for relative in ('data_train.py', 'util_data.py'): | |
| existing, canonical = ROOT / relative, STAGING / relative | |
| if not existing.exists() or hashlib.sha256(existing.read_bytes()).digest() != hashlib.sha256(canonical.read_bytes()).digest(): | |
| raise RuntimeError(f'Existing SPC snapshot differs at {relative}; refusing automatic replacement') | |
| backup = BACKUP | |
| suffix = 1 | |
| while backup.exists(): | |
| backup = BACKUP.with_name(f'{BACKUP.name}_{suffix}') | |
| suffix += 1 | |
| ROOT.rename(backup) | |
| print('SPC_SNAPSHOT_BACKUP', backup, flush=True) | |
| STAGING.rename(ROOT) | |
| assert revision(ROOT) == COMMIT | |
| print('SPC_SOURCE_READY', COMMIT, flush=True) | |