Datasets:
Download scripts/publish_dataset.py from hcltech-robotics/simrepairbench: direct link, hf CLI and curl.
- Browser
- Download file 3.61 kB
-
https://huggingface.co/datasets/hcltech-robotics/simrepairbench/resolve/main/scripts/publish_dataset.py
- Command line
-
hf download hf://datasets/hcltech-robotics/simrepairbench/scripts/publish_dataset.py
-
curl -L -o publish_dataset.py https://huggingface.co/datasets/hcltech-robotics/simrepairbench/resolve/main/scripts/publish_dataset.py
3.61 kB
| """Publish the verified CASTAIGNE25 objects in one history-preserving HF commit.""" | |
| import argparse | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import subprocess | |
| import sys | |
| from huggingface_hub import HfApi, CommitOperationAdd, CommitOperationDelete | |
| REPOSITORY = 'hcltech-robotics/simrepairbench' | |
| def sha256(path): | |
| with path.open('rb') as stream: | |
| return hashlib.file_digest(stream, 'sha256').hexdigest() | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--parent-commit', required=True) | |
| parser.add_argument('--files', type=Path, required=True) | |
| parser.add_argument('--allow-missing-previews', action='store_true', help='Allow native null images for explicitly unavailable captures') | |
| args = parser.parse_args() | |
| root = Path(__file__).resolve().parents[1] | |
| viewer_command = [sys.executable, str(root / 'scripts/build_case_viewer.py'), '--check'] | |
| if args.allow_missing_previews: | |
| viewer_command.append('--allow-missing-previews') | |
| subprocess.run(viewer_command, check=True) | |
| packages = json.loads((root / 'cases/packages.json').read_text())['packages'] | |
| if len(packages) != 25 or sum(p['fault_count'] for p in packages) != 128: | |
| raise ValueError('Exactly the verified 25-object, 128-fault set is required') | |
| for package in packages: | |
| if not package['archive_verified'] or sha256(root / package['path']) != package['sha256']: | |
| raise ValueError('Archive digest mismatch: ' + package['case_id']) | |
| paths = args.files.read_text().splitlines() + [p['path'] for p in packages] | |
| if len(paths) != len(set(paths)): | |
| raise ValueError('Duplicate publication paths') | |
| if any(Path(p).is_absolute() or '..' in Path(p).parts or p.startswith(('.git/', 'work/', 'telemetry/', 'audit/', 'provenance/')) for p in paths): | |
| raise ValueError('Non-release publication path') | |
| notices = {'licenses/NVIDIA-SimReady-CC-BY-4.0.txt', 'licenses/simreadybench-MIT-LICENSE.txt', 'LICENSE', 'README.md'} | |
| if not notices.issubset(paths): | |
| raise ValueError('The release must retain source attribution and required licence notices') | |
| api = HfApi() | |
| if api.repo_info(REPOSITORY, repo_type='dataset').sha != args.parent_commit: | |
| raise ValueError('The destination changed; inspect the new commit before publication') | |
| present = api.list_repo_files(REPOSITORY, repo_type='dataset', revision=args.parent_commit) | |
| cleanup = [CommitOperationDelete(folder, is_folder=True) for folder in ('audit', 'telemetry', 'provenance') | |
| if any(p.startswith(folder + '/') for p in present)] | |
| cleanup += [CommitOperationDelete(path, is_folder=False) for path in ('CODEX_TASK.md', 'STATUS.json') if path in present] | |
| result = api.create_commit( | |
| repo_id=REPOSITORY, repo_type='dataset', revision='main', parent_commit=args.parent_commit, | |
| operations=cleanup + [CommitOperationAdd(path_in_repo=p, path_or_fileobj=str(root / p)) for p in paths], | |
| commit_message='Publish CASTAIGNE25 repair tasks and native image case viewer', | |
| commit_description='Typed fault lists, source and damaged asset links, versioned partial-reward scoring and retained source licences.') | |
| receipt = {'repository': REPOSITORY, 'commit': result.oid, 'url': result.commit_url, | |
| 'parent_commit': args.parent_commit, 'files': paths} | |
| (root / 'work/publication-receipt.json').write_text(json.dumps(receipt, indent=2) + '\n') | |
| print(json.dumps({'commit': result.oid, 'url': result.commit_url}), flush=True) | |
| if __name__ == '__main__': | |
| main() | |