|
20 | 20 | )
|
21 | 21 | from filelock import SoftFileLock
|
22 | 22 | import attrs.exceptions
|
23 |
| -from fileformats.core import FileSet |
| 23 | +from fileformats.core.fileset import FileSet, MockMixin |
24 | 24 | from . import user_cache_dir, add_exc_note
|
25 | 25 |
|
26 | 26 | logger = logging.getLogger("pydra")
|
|
55 | 55 | )
|
56 | 56 |
|
57 | 57 | Hash = NewType("Hash", bytes)
|
58 |
| -CacheKey = NewType("CacheKey", ty.Tuple[ty.Hashable, ty.Hashable]) |
| 58 | +CacheKey = NewType("CacheKey", ty.Tuple[ty.Hashable, ...]) |
59 | 59 |
|
60 | 60 |
|
61 | 61 | def location_converter(path: ty.Union[Path, str, None]) -> Path:
|
@@ -478,11 +478,29 @@ def bytes_repr_fileset(
|
478 | 478 | fileset: FileSet, cache: Cache
|
479 | 479 | ) -> Iterator[ty.Union[CacheKey, bytes]]:
|
480 | 480 | fspaths = sorted(fileset.fspaths)
|
| 481 | + # Yield the cache key for the fileset, which is a tuple of the file-system paths |
| 482 | + # and their mtime. Is used to store persistent cache of the fileset hashes |
| 483 | + # to avoid recomputation between calls |
481 | 484 | yield CacheKey(
|
482 | 485 | tuple(repr(p) for p in fspaths) # type: ignore[arg-type]
|
483 | 486 | + tuple(p.lstat().st_mtime_ns for p in fspaths)
|
484 | 487 | )
|
485 |
| - yield from fileset.__bytes_repr__(cache) |
| 488 | + cls = type(fileset) |
| 489 | + yield f"{cls.__module__}.{cls.__name__}:".encode() |
| 490 | + for key, chunk_iter in fileset.byte_chunks(): |
| 491 | + yield (",'" + key + "'=").encode() |
| 492 | + yield from chunk_iter |
| 493 | + |
| 494 | + |
| 495 | +# Need to disable the mtime cache key for mocked filesets. Used in doctests |
| 496 | +@register_serializer(MockMixin) |
| 497 | +def bytes_repr_mock_fileset( |
| 498 | + mock_fileset: MockMixin, cache: Cache |
| 499 | +) -> Iterator[ty.Union[CacheKey, bytes]]: |
| 500 | + cls = type(mock_fileset) |
| 501 | + yield f"{cls.__module__}.{cls.__name__}:".encode() |
| 502 | + for key, _ in mock_fileset.byte_chunks(): |
| 503 | + yield (",'" + key + "'").encode() |
486 | 504 |
|
487 | 505 |
|
488 | 506 | @register_serializer(list)
|
|
0 commit comments