From 9e1849b32f8a25abfc293534a7756727a7b89f97 Mon Sep 17 00:00:00 2001 From: Marcel Stimberg Date: Mon, 9 May 2022 11:15:41 +0200 Subject: [PATCH] Use a temporary directory for flag test --- brian2/codegen/cpp_prefs.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/brian2/codegen/cpp_prefs.py b/brian2/codegen/cpp_prefs.py index f67abc51b..f49c2cc00 100644 --- a/brian2/codegen/cpp_prefs.py +++ b/brian2/codegen/cpp_prefs.py @@ -236,14 +236,13 @@ def _determine_flag_compatibility(compiler, flagname): import tempfile from distutils.errors import CompileError - with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f, std_silent(): - f.write('int main (int argc, char **argv) { return 0; }') + with tempfile.TemporaryDirectory(prefix='brian_flag_test_') as temp_dir, std_silent(): + fname = os.path.join(temp_dir, 'flag_test.cpp') + with open(fname, 'wt') as f: + f.write('int main (int argc, char **argv) { return 0; }') try: - object_files = compiler.compile([f.name], - output_dir=os.path.dirname(f.name), - extra_postargs=[flagname]) - for object_file in object_files: - os.unlink(object_file) + compiler.compile([fname], output_dir=temp_dir, + extra_postargs=[flagname]) except CompileError: logger.warn(f"Removing unsupported flag '{flagname}' from " f'compiler flags.')