(self, ctx: ReportConfigContext)
| 146 | self.metastore = create_metastore(options, parallel_worker=False) |
| 147 | |
| 148 | def report_config_data(self, ctx: ReportConfigContext) -> tuple[str | None, list[str]] | None: |
| 149 | # The config data we report is the group map entry for the module. |
| 150 | # If the data is being used to check validity, we do additional checks |
| 151 | # that the IR cache exists and matches the metadata cache and all |
| 152 | # output source files exist and are up to date. |
| 153 | |
| 154 | id, path, is_check = ctx.id, ctx.path, ctx.is_check |
| 155 | |
| 156 | if id not in self.group_map: |
| 157 | return None |
| 158 | |
| 159 | # If we aren't doing validity checks, just return the cache data |
| 160 | if not is_check: |
| 161 | return self.group_map[id] |
| 162 | |
| 163 | # Load the metadata and IR cache |
| 164 | meta_path, _, _ = get_cache_names(id, path, self.options) |
| 165 | ir_path = get_ir_cache_name(id, path, self.options) |
| 166 | try: |
| 167 | meta_json = self.metastore.read(meta_path) |
| 168 | ir_json = self.metastore.read(ir_path) |
| 169 | except FileNotFoundError: |
| 170 | # This could happen if mypyc failed after mypy succeeded |
| 171 | # in the previous run or if some cache files got |
| 172 | # deleted. No big deal, just fail to load the cache. |
| 173 | return None |
| 174 | |
| 175 | ir_data = json.loads(ir_json) |
| 176 | |
| 177 | # Check that the IR cache matches the metadata cache |
| 178 | if hash_digest(meta_json) != ir_data["meta_hash"]: |
| 179 | return None |
| 180 | |
| 181 | # Check that all the source files are present and as |
| 182 | # expected. The main situation where this would come up is the |
| 183 | # user deleting the build directory without deleting |
| 184 | # .mypy_cache, which we should handle gracefully. |
| 185 | for path, hash in ir_data["src_hashes"].items(): |
| 186 | try: |
| 187 | with open(os.path.join(self.compiler_options.target_dir, path), "rb") as f: |
| 188 | contents = f.read() |
| 189 | except FileNotFoundError: |
| 190 | return None |
| 191 | real_hash = hash_digest(contents) |
| 192 | if hash != real_hash: |
| 193 | return None |
| 194 | |
| 195 | return self.group_map[id] |
| 196 | |
| 197 | def get_additional_deps(self, file: MypyFile) -> list[tuple[int, str, int]]: |
| 198 | # Report dependency on modules in the module's group |
nothing calls this directly
no test coverage detected