Skip to content

Commit fc4b038

Browse files
committed
Remove os.path in link/c/cutils.py
1 parent 60d83c0 commit fc4b038

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

pytensor/link/c/cutils.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import errno
2-
import os
32
import sys
43
from pathlib import Path
54

@@ -10,8 +9,7 @@
109

1110
# TODO These two lines may be removed in the future, when we are 100% sure
1211
# 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)
1513

1614

1715
def compile_cutils():
@@ -69,13 +67,13 @@ def compile_cutils():
6967
}
7068
"""
7169

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():
7472
try:
75-
os.mkdir(loc)
73+
loc.mkdir()
7674
except OSError as e:
7775
assert e.errno == errno.EEXIST
78-
assert os.path.exists(loc), loc
76+
assert loc.exists(), loc
7977

8078
args = cmodule.GCC_compiler.compile_args(march_flags=False)
8179
cmodule.GCC_compiler.compile_str("cutils_ext", code, location=loc, preargs=args)
@@ -89,16 +87,14 @@ def compile_cutils():
8987
# repeated in compile_str()) but if another cutils_ext does exist then it
9088
# will be imported and compile_str won't get called at all.
9189
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():
9492
try:
95-
os.mkdir(location)
93+
location.mkdir()
9694
except OSError as e:
9795
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)
10298

10399
try:
104100
from cutils_ext.cutils_ext import * # noqa

0 commit comments

Comments
 (0)