1
- import errno
2
1
import logging
3
- import os
4
2
import sys
5
3
import warnings
6
4
from importlib import reload
@@ -43,23 +41,12 @@ def try_reload():
43
41
# compile_str()) but if another lazylinker_ext does exist then it will be
44
42
# imported and compile_str won't get called at all.
45
43
location = config .compiledir / "lazylinker_ext"
46
- if not location .exists ():
47
- try :
48
- # Try to make the location
49
- os .mkdir (location )
50
- except OSError as e :
51
- # If we get an error, verify that the error was # 17, the
52
- # path already exists, and that it is a directory Note: we
53
- # can't check if it exists before making it, because we
54
- # are not holding the lock right now, so we could race
55
- # another process and get error 17 if we lose the race
56
- assert e .errno == errno .EEXIST
57
- assert location .is_dir ()
44
+ location .mkdir (exist_ok = True )
58
45
59
46
init_file = location / "__init__.py"
60
47
if not init_file .exists ():
61
48
try :
62
- with open (init_file , "w" ):
49
+ with init_file . open ("w" ):
63
50
pass
64
51
except OSError as e :
65
52
if init_file .exists ():
@@ -129,12 +116,7 @@ def try_reload():
129
116
code = cfile .read_text ("utf-8" )
130
117
131
118
loc = config .compiledir / dirname
132
- if not loc .exists ():
133
- try :
134
- os .mkdir (loc )
135
- except OSError as e :
136
- assert e .errno == errno .EEXIST
137
- assert loc .exists ()
119
+ loc .mkdir (exist_ok = True )
138
120
139
121
args = GCC_compiler .compile_args ()
140
122
GCC_compiler .compile_str (dirname , code , location = loc , preargs = args )
@@ -147,8 +129,7 @@ def try_reload():
147
129
# imported at the same time: we need to make sure we do not
148
130
# reload the now outdated __init__.pyc below.
149
131
init_pyc = loc / "__init__.pyc"
150
- if init_pyc .is_file ():
151
- os .remove (init_pyc )
132
+ init_pyc .unlink (missing_ok = True )
152
133
153
134
try_import ()
154
135
try_reload ()
0 commit comments