Load and normalize a cache entry. Returns: - For .meta.ff: normalized binary bytes (with version prefix) - For .data.ff: raw binary bytes - For .meta.json/.data.json/.deps.json: parsed and normalized dict/list
(cache: MetadataStore, s: str)
| 99 | |
| 100 | |
| 101 | def load(cache: MetadataStore, s: str) -> Any: |
| 102 | """Load and normalize a cache entry. |
| 103 | |
| 104 | Returns: |
| 105 | - For .meta.ff: normalized binary bytes (with version prefix) |
| 106 | - For .data.ff: raw binary bytes |
| 107 | - For .meta.json/.data.json/.deps.json: parsed and normalized dict/list |
| 108 | """ |
| 109 | data = cache.read(s) |
| 110 | if s.endswith(".meta.ff"): |
| 111 | version_prefix = data[:2] |
| 112 | buf = ReadBuffer(data[2:]) |
| 113 | meta = CacheMeta.read(buf, data_file="") |
| 114 | if meta is None: |
| 115 | # Can't deserialize (e.g. different mypy version). Fall back to |
| 116 | # raw bytes -- we lose mtime normalization but the diff stays correct. |
| 117 | return data |
| 118 | normalize_meta(meta) |
| 119 | return serialize_meta_ff(meta, version_prefix) |
| 120 | if s.endswith(".meta_ex.ff"): |
| 121 | buf = ReadBuffer(data) |
| 122 | meta = CacheMetaEx.read(buf) |
| 123 | if meta is None: |
| 124 | # Can't deserialize. Fall back to raw bytes as above |
| 125 | return data |
| 126 | meta.dependencies.sort() |
| 127 | meta.suppressed.sort() |
| 128 | outbuf = WriteBuffer() |
| 129 | meta.write(outbuf) |
| 130 | return outbuf.getvalue() |
| 131 | if s.endswith(".data.ff"): |
| 132 | return data |
| 133 | obj = json_loads(data) |
| 134 | if s.endswith(".meta.json"): |
| 135 | normalize_json_meta(obj) |
| 136 | if s.endswith(".deps.json"): |
| 137 | # For deps files, sort the deps to avoid spurious mismatches |
| 138 | for v in obj.values(): |
| 139 | v.sort() |
| 140 | return obj |
| 141 | |
| 142 | |
| 143 | def encode_for_diff(s: str, obj: object) -> str: |
no test coverage detected
searching dependent graphs…