|
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,18 +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 |
486 | 493 |
|
487 | 494 |
|
| 495 | +# Need to disable the mtime cache key for mocked filesets. Used in doctests |
488 | 496 | @register_serializer(MockMixin) |
489 | 497 | def bytes_repr_mock_fileset( |
490 | 498 | mock_fileset: MockMixin, cache: Cache |
491 | 499 | ) -> Iterator[ty.Union[CacheKey, bytes]]: |
492 | | - yield from mock_fileset.__bytes_repr__(cache) |
| 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() |
493 | 504 |
|
494 | 505 |
|
495 | 506 | @register_serializer(list) |
|
0 commit comments