mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-21 11:39:50 +00:00
fix(annotate): tag uploaded dataset revision
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -140,7 +140,7 @@ def _push_to_hub(root: Path, cfg: AnnotationPipelineConfig) -> None:
|
|||||||
exist_ok=True,
|
exist_ok=True,
|
||||||
)
|
)
|
||||||
print(f"[lerobot-annotate] uploading {root} -> {repo_id}...", flush=True)
|
print(f"[lerobot-annotate] uploading {root} -> {repo_id}...", flush=True)
|
||||||
api.upload_folder(
|
commit_info = api.upload_folder(
|
||||||
folder_path=str(root),
|
folder_path=str(root),
|
||||||
repo_id=repo_id,
|
repo_id=repo_id,
|
||||||
repo_type="dataset",
|
repo_type="dataset",
|
||||||
@@ -169,13 +169,18 @@ def _push_to_hub(root: Path, cfg: AnnotationPipelineConfig) -> None:
|
|||||||
version_tag = ds_version
|
version_tag = ds_version
|
||||||
except Exception as exc: # noqa: BLE001
|
except Exception as exc: # noqa: BLE001
|
||||||
print(f"[lerobot-annotate] could not read codebase_version from info.json ({exc}); falling back to {version_tag}", flush=True)
|
print(f"[lerobot-annotate] could not read codebase_version from info.json ({exc}); falling back to {version_tag}", flush=True)
|
||||||
|
revision = getattr(commit_info, "oid", None)
|
||||||
|
tag_kwargs = {
|
||||||
|
"repo_id": repo_id,
|
||||||
|
"tag": version_tag,
|
||||||
|
"repo_type": "dataset",
|
||||||
|
"exist_ok": True,
|
||||||
|
}
|
||||||
|
if revision is not None:
|
||||||
|
tag_kwargs["revision"] = revision
|
||||||
|
|
||||||
try:
|
try:
|
||||||
api.create_tag(
|
api.create_tag(**tag_kwargs)
|
||||||
repo_id=repo_id,
|
|
||||||
tag=version_tag,
|
|
||||||
repo_type="dataset",
|
|
||||||
exist_ok=True,
|
|
||||||
)
|
|
||||||
print(f"[lerobot-annotate] tagged {repo_id} as {version_tag}", flush=True)
|
print(f"[lerobot-annotate] tagged {repo_id} as {version_tag}", flush=True)
|
||||||
except Exception as exc: # noqa: BLE001
|
except Exception as exc: # noqa: BLE001
|
||||||
print(
|
print(
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import json
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
|
||||||
|
def test_push_to_hub_tags_uploaded_dataset_revision(tmp_path, monkeypatch):
|
||||||
|
from lerobot.scripts.lerobot_annotate import _push_to_hub
|
||||||
|
|
||||||
|
root = tmp_path / "dataset"
|
||||||
|
(root / "meta").mkdir(parents=True)
|
||||||
|
(root / "meta" / "info.json").write_text(json.dumps({"codebase_version": "v3.0"}))
|
||||||
|
|
||||||
|
calls = {}
|
||||||
|
|
||||||
|
class FakeHfApi:
|
||||||
|
def create_repo(self, **kwargs):
|
||||||
|
calls["create_repo"] = kwargs
|
||||||
|
|
||||||
|
def upload_folder(self, **kwargs):
|
||||||
|
calls["upload_folder"] = kwargs
|
||||||
|
return SimpleNamespace(oid="abc123")
|
||||||
|
|
||||||
|
def create_tag(self, **kwargs):
|
||||||
|
calls["create_tag"] = kwargs
|
||||||
|
|
||||||
|
monkeypatch.setattr("huggingface_hub.HfApi", FakeHfApi)
|
||||||
|
|
||||||
|
cfg = SimpleNamespace(
|
||||||
|
repo_id="source/dataset",
|
||||||
|
dest_repo_id="annotated/dataset",
|
||||||
|
push_private=True,
|
||||||
|
push_commit_message=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
_push_to_hub(root, cfg)
|
||||||
|
|
||||||
|
assert calls["create_repo"] == {
|
||||||
|
"repo_id": "annotated/dataset",
|
||||||
|
"repo_type": "dataset",
|
||||||
|
"private": True,
|
||||||
|
"exist_ok": True,
|
||||||
|
}
|
||||||
|
assert calls["upload_folder"]["repo_id"] == "annotated/dataset"
|
||||||
|
assert calls["create_tag"] == {
|
||||||
|
"repo_id": "annotated/dataset",
|
||||||
|
"tag": "v3.0",
|
||||||
|
"repo_type": "dataset",
|
||||||
|
"exist_ok": True,
|
||||||
|
"revision": "abc123",
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user