Skip to content

Commit 7064c53

Browse files
authored
Merge pull request #173 from mbel-tech/claude/project-thread-s4y5cm
2 parents 7069843 + 344e5e2 commit 7064c53

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎track2data/core/models.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import math
1818
from dataclasses import dataclass, field
1919
from datetime import datetime
20-
from pathlib import Path
20+
from pathlib import Path, PurePath
2121
from typing import TYPE_CHECKING, Any, Literal
2222

2323
import numpy as np
@@ -737,6 +737,10 @@ class ExportTarget(BaseModel):
737737
# ── Project manifest ──────────────────────────────────────────────────────────
738738

739739

740+
def _hash_default(value: object) -> str:
741+
return value.as_posix() if isinstance(value, PurePath) else str(value)
742+
743+
740744
class ProjectManifest(BaseModel):
741745
schema_version: int = 1
742746
# Stamped into every exported manifest.json and the run README's
@@ -771,12 +775,10 @@ class ProjectManifest(BaseModel):
771775

772776
def project_hash(self) -> str:
773777
"""16-char hex hash of the manifest content (timestamps excluded)."""
774-
# JSON mode writes a path with forward slashes on every platform, so the same project
775-
# hashes the same on Windows and elsewhere.
776-
data: dict[str, Any] = self.model_dump(
777-
mode="json", exclude={"created_at", "updated_at", "run_log_path"}
778-
)
779-
serialised = json.dumps(data, sort_keys=True, default=str)
778+
data: dict[str, Any] = self.model_dump(exclude={"created_at", "updated_at", "run_log_path"})
779+
# A path is written with forward slashes on every platform, so the same project hashes the
780+
# same on Windows and elsewhere (``as_posix`` equals ``str`` on posix).
781+
serialised = json.dumps(data, sort_keys=True, default=_hash_default)
780782
return hashlib.sha256(serialised.encode()).hexdigest()[:16]
781783

782784

0 commit comments

Comments
 (0)