Skip to content

Commit

Permalink
Replace mkstemp with NamedTemporaryFile in build_meta
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Dec 20, 2021
1 parent 574cb20 commit caf2e5a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,11 @@ def _patch_distutils_exec():
return

def _exec(code, global_vars):
try:
_, tmp = tempfile.mkstemp(suffix="setup.py")
with open(tmp, "wb") as f:
f.write(code)
with tokenize.open(tmp) as f:
with tempfile.NamedTemporaryFile(suffix="setup.py") as tmp:
tmp.write(code)
tmp.close()
with tokenize.open(tmp.name) as f:
code = f.read().replace(r'\r\n', r'\n')
finally:
os.remove(tmp)
orig_exec(code, {**global_vars, "__name__": "__main__"})

distutils.core.exec = _exec
Expand Down

0 comments on commit caf2e5a

Please sign in to comment.