Datasets:
Wind Tunnel Response Lab v0.2.0
Browse files1234567891011226 unmodified lines23823924024124224324413 unmodified lines2582592602612622632 unmodified lines26626726826927027127227327427527627727827928028128228328428528615 unmodified lines30230330430530630730846 unmodified lines35535635735835936036136236336436536636736836937014 unmodified lines385386387388389"""Stage and verify explicit release trees, then optionally publish to the Hub."""import hashlibimport jsonfrom pathlib import Pathimport reimport shutilimport subprocessfrom urllib.parse import urlencode, urlsplitimport urllib.requestfrom .sources import digest, object_hash, read, write226 unmodified linesdef publish(config, staging, dry_run):from huggingface_hub import CommitOperationAdd, HfApi, get_tokenfrom huggingface_hub.errors import RepositoryNotFoundErrorprint(verify(staging))13 unmodified linesoutput = Path("artifacts/hub-publication.json")receipt = read(output) if output.exists() else {"repos": {}}def upstream(key, repo):identifier, kind = repo["repo_id"], repo["type"]root = staging / key2 unmodified linesexcept RepositoryNotFoundError:api.create_repo(identifier, repo_type=kind, private=True, space_sdk="static" if kind == "space" else None)info = api.repo_info(identifier, repo_type=kind)write(output, {**receipt, "created_pending": sorted(set(receipt.get("created_pending", [])) | {identifier})})receipt["created_pending"] = sorted(set(receipt.get("created_pending", [])) | {identifier})remote_files = {s.rfilename for s in info.siblings}if "release_identity.json" in remote_files:identity = read(api.hf_hub_download(identifier, "release_identity.json", repo_type=kind, revision=info.sha))if identity.get("project") != SENTINEL or identity.get("repo_id") != identifier:raise ValueError(f"Destination belongs to an unrelated project: {identifier}")elif identifier not in receipt.get("created_pending", []) or remote_files - {".gitattributes", "README.md"}:raise ValueError(f"Occupied repository lacks the Response Lab identity: {identifier}")known = receipt["repos"].get(key)hashed = object_hash(repo["files"])if known and known["revision"] == info.sha and known["files_sha256"] == hashed:revision = info.shaelse:ops = [CommitOperationAdd(path_in_repo=name, path_or_fileobj=root / name) for name in repo["files"]]commit = api.create_commit(identifier, repo_type=kind, operations=ops,parent_commit=info.sha, commit_message=f"Wind Tunnel Response Lab {config['version']}")revision = commit.oid15 unmodified linesidentity = read(api.hf_hub_download(repo["repo_id"], "release_identity.json", repo_type=repo["type"], revision=existing.sha))if identity.get("project") == SENTINEL and identity.get("repo_id") == repo["repo_id"]:continueif repo["repo_id"] in receipt.get("created_pending", []) and not files - {".gitattributes", "README.md"}:continueraise ValueError(f"Occupied repository lacks the Response Lab identity: {repo['repo_id']}")46 unmodified linesinfo = api.repo_info(identifier, repo_type=kind, revision=revision, token=False)if info.private or info.sha != revision:raise ValueError(f"Visibility or revision check failed: {identifier}")for name, expected in repo["files"].items():local = api.hf_hub_download(identifier, name, revision=revision, repo_type=kind, token=False)if digest(local) != expected:raise ValueError(f"Failed remote digest: {identifier}/{name}")for table, split in viewer.get(key, {}).items():query = urlencode({"dataset": identifier, "config": table, "split": split})with urllib.request.urlopen(f"https://datasets-server.huggingface.co/first-rows?{query}", timeout=30) as response:if not json.load(response)["rows"]:raise ValueError(f"Empty Data Studio viewer: {identifier}/{table}")checks[key] = {"revision": revision, "anonymous_files_verified": True, "viewer_configs": list(viewer.get(key, {}))}space = receipt["repos"]["space"]visible = api.space_info(space["repo_id"], token=False)if visible.sha != space["revision"] or visible.private or visible.sdk != "static":14 unmodified linesraise ValueError(f"Live Space asset doesn't match the pinned revision: {asset}")checks["space"]["runtime_url"] = root_urlchecks["space"]["live_assets_verified"] = Truewrite("artifacts/hub-verification.json", checks)print(f"Verified anonymous immutable downloads, viewer rows, and Static Space assets at {root_url}.")1234567891011121314226 unmodified lines24124224324424524624713 unmodified lines2612622632642652662672682692702712722732742752762772782792802812822832842 unmodified lines28728828929029129229329429529629729829930030130230330430530630730830931031131231315 unmodified lines32933033133233333433546 unmodified lines38238338438538638738838939039139239339439539639714 unmodified lines412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441"""Stage and verify explicit release trees, then optionally publish to the Hub."""from concurrent.futures import ThreadPoolExecutorimport hashlibimport jsonfrom pathlib import Pathimport reimport shutilimport subprocessfrom time import sleepfrom urllib.parse import urlencode, urlsplitfrom urllib.error import HTTPErrorimport urllib.requestfrom .sources import digest, object_hash, read, write226 unmodified linesdef publish(config, staging, dry_run):from huggingface_hub import CommitOperationAdd, CommitOperationDelete, HfApi, get_tokenfrom huggingface_hub.errors import RepositoryNotFoundErrorprint(verify(staging))13 unmodified linesoutput = Path("artifacts/hub-publication.json")receipt = read(output) if output.exists() else {"repos": {}}def pending_starter(repo, info):identifier, kind = repo["repo_id"], repo["type"]if identifier not in receipt.get("created_pending", []) or not info.private:return Falseallowed = {".gitattributes", "README.md"}if kind == "space" and info.sdk == "static":allowed.update({"index.html", "style.css"})files = {entry.rfilename for entry in info.siblings}if files - allowed:return Falserecorded = receipt.get("created_initial_revisions", {}).get(identifier)if recorded:return info.sha == recorded# The first publisher only recorded the created repository ID. Recover# exclusively when the private repository still has its initial commit.history = api.list_repo_commits(identifier, repo_type=kind)return len(history) == 1 and history[0].commit_id == info.sha and history[0].title == "initial commit"def upstream(key, repo):identifier, kind = repo["repo_id"], repo["type"]root = staging / key2 unmodified linesexcept RepositoryNotFoundError:api.create_repo(identifier, repo_type=kind, private=True, space_sdk="static" if kind == "space" else None)info = api.repo_info(identifier, repo_type=kind)receipt["created_pending"] = sorted(set(receipt.get("created_pending", [])) | {identifier})receipt.setdefault("created_initial_revisions", {})[identifier] = info.shawrite(output, receipt)remote_files = {s.rfilename for s in info.siblings}starter = Falseif "release_identity.json" in remote_files:identity = read(api.hf_hub_download(identifier, "release_identity.json", repo_type=kind, revision=info.sha))if identity.get("project") != SENTINEL or identity.get("repo_id") != identifier:raise ValueError(f"Destination belongs to an unrelated project: {identifier}")else:starter = pending_starter(repo, info)if not starter:raise ValueError(f"Occupied repository lacks the Response Lab identity: {identifier}")known = receipt["repos"].get(key)hashed = object_hash(repo["files"])if known and known["revision"] == info.sha and known["files_sha256"] == hashed:revision = info.shaelse:ops = [CommitOperationAdd(path_in_repo=name, path_or_fileobj=root / name) for name in repo["files"]]if starter and kind == "space" and "style.css" in remote_files and "style.css" not in repo["files"]:ops.append(CommitOperationDelete(path_in_repo="style.css"))commit = api.create_commit(identifier, repo_type=kind, operations=ops,parent_commit=info.sha, commit_message=f"Wind Tunnel Response Lab {config['version']}")revision = commit.oid15 unmodified linesidentity = read(api.hf_hub_download(repo["repo_id"], "release_identity.json", repo_type=repo["type"], revision=existing.sha))if identity.get("project") == SENTINEL and identity.get("repo_id") == repo["repo_id"]:continueif pending_starter(repo, existing):continueraise ValueError(f"Occupied repository lacks the Response Lab identity: {repo['repo_id']}")46 unmodified linesinfo = api.repo_info(identifier, repo_type=kind, revision=revision, token=False)if info.private or info.sha != revision:raise ValueError(f"Visibility or revision check failed: {identifier}")def verify_file(entry):name, expected = entrylocal = api.hf_hub_download(identifier, name, revision=revision, repo_type=kind, token=False)if digest(local) != expected:raise ValueError(f"Failed remote digest: {identifier}/{name}")with ThreadPoolExecutor(max_workers=8) as pool:list(pool.map(verify_file, repo["files"].items()))checks[key] = {"revision": revision, "anonymous_files_verified": True, "viewer_configs": {}}print(f"Verified {len(repo['files'])} public files @ {revision}: {identifier}")space = receipt["repos"]["space"]visible = api.space_info(space["repo_id"], token=False)if visible.sha != space["revision"] or visible.private or visible.sdk != "static":14 unmodified linesraise ValueError(f"Live Space asset doesn't match the pinned revision: {asset}")checks["space"]["runtime_url"] = root_urlchecks["space"]["live_assets_verified"] = Truedef verify_table(target):key, identifier, table, split = targetquery = urlencode({"dataset": identifier, "config": table, "split": split})for attempt in range(6):try:with urllib.request.urlopen(f"https://datasets-server.huggingface.co/first-rows?{query}", timeout=25) as response:count = len(json.load(response)["rows"])if not count:raise ValueError(f"Empty Data Studio viewer: {identifier}/{table}")return key, table, {"status": "ready", "preview_rows": count}except HTTPError as error:if error.code not in (429, 502, 503, 504) or attempt == 5:return key, table, {"status": "unverified", "http_status": error.code}sleep(6 + 4 * attempt)raise AssertionError("Viewer retry loop did not return")targets = [(key, receipt["repos"][key]["repo_id"], table, split)for key, configs in viewer.items() for table, split in configs.items()]with ThreadPoolExecutor(max_workers=len(targets)) as pool:for key, table, status in pool.map(verify_table, targets):checks[key]["viewer_configs"][table] = statuswrite("artifacts/hub-verification.json", checks)pending = [f"{key}/{table}" for key, result in checks.items()for table, status in result["viewer_configs"].items() if status["status"] != "ready"]if pending:raise RuntimeError("Public files and live Space verified; Data Studio still unverified: " + ", ".join(pending))print(f"Verified anonymous immutable downloads, viewer rows, and Static Space assets at {root_url}.")
reproduction/src/windtunnel_response/release.py+64-12