From b8ed6735d4a0f4d700d073b9c0134db3b1d5fef8 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 18 Sep 2018 16:28:13 -0500 Subject: [PATCH] Fix for temp file on windows On windows the temp file cannot be opened a second time while it is still opened by python. Close the file in python before asking the compiler to read it. See https://docs.python.org/3.7/library/tempfile.html#tempfile.NamedTemporaryFile --- setup.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index c3e5971b..930bf51d 100644 --- a/setup.py +++ b/setup.py @@ -59,12 +59,13 @@ def has_flag(compiler, flagname): the specified compiler. """ import tempfile - with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f: + with tempfile.NamedTemporaryFile('w', suffix='.cpp', delete=False) as f: f.write('int main (int argc, char **argv) { return 0; }') - try: - compiler.compile([f.name], extra_postargs=[flagname]) - except setuptools.distutils.errors.CompileError: - return False + fname = f.name + try: + compiler.compile([fname], extra_postargs=[flagname]) + except setuptools.distutils.errors.CompileError: + return False return True -- GitLab