| 316 | |
| 317 | |
| 318 | def _write_pyc( |
| 319 | state: AssertionState, |
| 320 | co: types.CodeType, |
| 321 | source_stat: os.stat_result, |
| 322 | pyc: Path, |
| 323 | ) -> bool: |
| 324 | proc_pyc = f"{pyc}.{os.getpid()}" |
| 325 | try: |
| 326 | with open(proc_pyc, "wb") as fp: |
| 327 | _write_pyc_fp(fp, source_stat, co) |
| 328 | except OSError as e: |
| 329 | state.trace(f"error writing pyc file at {proc_pyc}: errno={e.errno}") |
| 330 | return False |
| 331 | |
| 332 | try: |
| 333 | os.replace(proc_pyc, pyc) |
| 334 | except OSError as e: |
| 335 | state.trace(f"error writing pyc file at {pyc}: {e}") |
| 336 | # we ignore any failure to write the cache file |
| 337 | # there are many reasons, permission-denied, pycache dir being a |
| 338 | # file etc. |
| 339 | return False |
| 340 | return True |
| 341 | |
| 342 | |
| 343 | def _rewrite_test(fn: Path, config: Config) -> tuple[os.stat_result, types.CodeType]: |