@@ -302,53 +302,31 @@ def _write_pyc_fp(
302
302
fp .write (marshal .dumps (co ))
303
303
304
304
305
- if sys .platform == "win32" :
306
- from atomicwrites import atomic_write
307
-
308
- def _write_pyc (
309
- state : "AssertionState" ,
310
- co : types .CodeType ,
311
- source_stat : os .stat_result ,
312
- pyc : Path ,
313
- ) -> bool :
314
- try :
315
- with atomic_write (os .fspath (pyc ), mode = "wb" , overwrite = True ) as fp :
316
- _write_pyc_fp (fp , source_stat , co )
317
- except OSError as e :
318
- state .trace (f"error writing pyc file at { pyc } : { e } " )
319
- # we ignore any failure to write the cache file
320
- # there are many reasons, permission-denied, pycache dir being a
321
- # file etc.
322
- return False
323
- return True
324
-
325
- else :
326
-
327
- def _write_pyc (
328
- state : "AssertionState" ,
329
- co : types .CodeType ,
330
- source_stat : os .stat_result ,
331
- pyc : Path ,
332
- ) -> bool :
333
- proc_pyc = f"{ pyc } .{ os .getpid ()} "
334
- try :
335
- fp = open (proc_pyc , "wb" )
336
- except OSError as e :
337
- state .trace (f"error writing pyc file at { proc_pyc } : errno={ e .errno } " )
338
- return False
305
+ def _write_pyc (
306
+ state : "AssertionState" ,
307
+ co : types .CodeType ,
308
+ source_stat : os .stat_result ,
309
+ pyc : Path ,
310
+ ) -> bool :
311
+ proc_pyc = f"{ pyc } .{ os .getpid ()} "
312
+ try :
313
+ fp = open (proc_pyc , "wb" )
314
+ except OSError as e :
315
+ state .trace (f"error writing pyc file at { proc_pyc } : errno={ e .errno } " )
316
+ return False
339
317
340
- try :
341
- _write_pyc_fp (fp , source_stat , co )
342
- os .rename (proc_pyc , pyc )
343
- except OSError as e :
344
- state .trace (f"error writing pyc file at { pyc } : { e } " )
345
- # we ignore any failure to write the cache file
346
- # there are many reasons, permission-denied, pycache dir being a
347
- # file etc.
348
- return False
349
- finally :
350
- fp .close ()
351
- return True
318
+ try :
319
+ _write_pyc_fp (fp , source_stat , co )
320
+ os .replace (proc_pyc , pyc )
321
+ except OSError as e :
322
+ state .trace (f"error writing pyc file at { pyc } : { e } " )
323
+ # we ignore any failure to write the cache file
324
+ # there are many reasons, permission-denied, pycache dir being a
325
+ # file etc.
326
+ return False
327
+ finally :
328
+ fp .close ()
329
+ return True
352
330
353
331
354
332
def _rewrite_test (fn : Path , config : Config ) -> Tuple [os .stat_result , types .CodeType ]:
0 commit comments