|
17 | 17 | import math |
18 | 18 | from dataclasses import dataclass, field |
19 | 19 | from datetime import datetime |
20 | | -from pathlib import Path |
| 20 | +from pathlib import Path, PurePath |
21 | 21 | from typing import TYPE_CHECKING, Any, Literal |
22 | 22 |
|
23 | 23 | import numpy as np |
@@ -737,6 +737,10 @@ class ExportTarget(BaseModel): |
737 | 737 | # ── Project manifest ────────────────────────────────────────────────────────── |
738 | 738 |
|
739 | 739 |
|
| 740 | +def _hash_default(value: object) -> str: |
| 741 | + return value.as_posix() if isinstance(value, PurePath) else str(value) |
| 742 | + |
| 743 | + |
740 | 744 | class ProjectManifest(BaseModel): |
741 | 745 | schema_version: int = 1 |
742 | 746 | # Stamped into every exported manifest.json and the run README's |
@@ -771,12 +775,10 @@ class ProjectManifest(BaseModel): |
771 | 775 |
|
772 | 776 | def project_hash(self) -> str: |
773 | 777 | """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) |
780 | 782 | return hashlib.sha256(serialised.encode()).hexdigest()[:16] |
781 | 783 |
|
782 | 784 |
|
|
0 commit comments