Skip to content

Commit caf2e5a

Browse files
committed
Replace mkstemp with NamedTemporaryFile in build_meta
1 parent 574cb20 commit caf2e5a

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

setuptools/build_meta.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,11 @@ def _patch_distutils_exec():
9999
return
100100

101101
def _exec(code, global_vars):
102-
try:
103-
_, tmp = tempfile.mkstemp(suffix="setup.py")
104-
with open(tmp, "wb") as f:
105-
f.write(code)
106-
with tokenize.open(tmp) as f:
102+
with tempfile.NamedTemporaryFile(suffix="setup.py") as tmp:
103+
tmp.write(code)
104+
tmp.close()
105+
with tokenize.open(tmp.name) as f:
107106
code = f.read().replace(r'\r\n', r'\n')
108-
finally:
109-
os.remove(tmp)
110107
orig_exec(code, {**global_vars, "__name__": "__main__"})
111108

112109
distutils.core.exec = _exec

0 commit comments

Comments
 (0)