1
1
import errno
2
- import os
3
2
import sys
4
3
from pathlib import Path
5
4
10
9
11
10
# TODO These two lines may be removed in the future, when we are 100% sure
12
11
# no one has an old cutils_ext.so lying around anymore.
13
- if os .path .exists (os .path .join (config .compiledir , "cutils_ext.so" )):
14
- os .remove (os .path .join (config .compiledir , "cutils_ext.so" ))
12
+ (config .compiledir / "cutils_ext.so" ).unlink (missing_ok = True )
15
13
16
14
17
15
def compile_cutils ():
@@ -69,13 +67,13 @@ def compile_cutils():
69
67
}
70
68
"""
71
69
72
- loc = os . path . join ( config .compiledir , "cutils_ext" )
73
- if not os . path . exists (loc ):
70
+ loc = config .compiledir / "cutils_ext"
71
+ if not loc . exists ():
74
72
try :
75
- os .mkdir (loc )
73
+ loc .mkdir ()
76
74
except OSError as e :
77
75
assert e .errno == errno .EEXIST
78
- assert os . path . exists (loc ), loc
76
+ assert loc . exists (), loc
79
77
80
78
args = cmodule .GCC_compiler .compile_args (march_flags = False )
81
79
cmodule .GCC_compiler .compile_str ("cutils_ext" , code , location = loc , preargs = args )
@@ -89,16 +87,14 @@ def compile_cutils():
89
87
# repeated in compile_str()) but if another cutils_ext does exist then it
90
88
# will be imported and compile_str won't get called at all.
91
89
sys .path .insert (0 , str (config .compiledir ))
92
- location = os . path . join ( str ( config .compiledir ), "cutils_ext" )
93
- if not os . path . exists (location ):
90
+ location = config .compiledir / "cutils_ext"
91
+ if not location . exists ():
94
92
try :
95
- os .mkdir (location )
93
+ location .mkdir ()
96
94
except OSError as e :
97
95
assert e .errno == errno .EEXIST
98
- assert os .path .exists (location ), location
99
- if not os .path .exists (os .path .join (location , "__init__.py" )):
100
- with open (os .path .join (location , "__init__.py" ), "w" ):
101
- pass
96
+ assert location .exists (), location
97
+ (location / "__init__.py" ).touch (exist_ok = True )
102
98
103
99
try :
104
100
from cutils_ext .cutils_ext import * # noqa
0 commit comments