| 308 | from atomicwrites import atomic_write |
| 309 | |
| 310 | def _write_pyc( |
| 311 | state: "AssertionState", |
| 312 | co: types.CodeType, |
| 313 | source_stat: os.stat_result, |
| 314 | pyc: Path, |
| 315 | ) -> bool: |
| 316 | try: |
| 317 | with atomic_write(os.fspath(pyc), mode="wb", overwrite=True) as fp: |
| 318 | _write_pyc_fp(fp, source_stat, co) |
| 319 | except OSError as e: |
| 320 | state.trace(f"error writing pyc file at {pyc}: {e}") |
| 321 | # we ignore any failure to write the cache file |
| 322 | # there are many reasons, permission-denied, pycache dir being a |
| 323 | # file etc. |
| 324 | return False |
| 325 | return True |
| 326 | |
| 327 | |
| 328 | else: |