diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py index 3c884eb775a..ef3caf26698 100644 --- a/setuptools/build_meta.py +++ b/setuptools/build_meta.py @@ -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