From 8bc42cabd9d9a4bfae31903ac4fd7fe88d1e98f2 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Tue, 7 Apr 2026 14:10:06 +0200 Subject: [PATCH] fix: store absolute paths in dataset.json Co-Authored-By: Claude Sonnet 4.6 --- main.py | 6 +++--- tests/test_utils.py | 2 +- tools/migrate_dataset_json.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 36667d2..3cd9bc3 100755 --- a/main.py +++ b/main.py @@ -120,10 +120,10 @@ def upsert_clip_annotation(folder: str, clip_path: str, label: str) -> None: entries = json.load(f) except (json.JSONDecodeError, ValueError): entries = [] - rel_path = os.path.relpath(clip_path, folder) - entry: dict = {"path": rel_path, "label": label} + abs_path = os.path.abspath(clip_path) + entry: dict = {"path": abs_path, "label": label} for i, e in enumerate(entries): - if e.get("path") == rel_path: + if e.get("path") == abs_path: entries[i] = entry break else: diff --git a/tests/test_utils.py b/tests/test_utils.py index 263b422..2565151 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -245,7 +245,7 @@ def test_upsert_creates_file(): entries = json.load(f) assert len(entries) == 1 assert entries[0]["label"] == "dog barking" - assert entries[0]["path"] == "clip_001.mp4" + assert entries[0]["path"] == clip def test_upsert_appends_new_clips(): with tempfile.TemporaryDirectory() as d: diff --git a/tools/migrate_dataset_json.py b/tools/migrate_dataset_json.py index 7e0b23e..07f6c4f 100644 --- a/tools/migrate_dataset_json.py +++ b/tools/migrate_dataset_json.py @@ -30,7 +30,7 @@ def load_db_records(db_path: Path) -> list[dict]: def build_entries_for_folder(folder: str, records: list[dict]) -> list[dict]: return [ - {"path": os.path.relpath(rec["output_path"], folder), "label": rec["label"]} + {"path": os.path.abspath(rec["output_path"]), "label": rec["label"]} for rec in records ]