Skip to content

Commit 3509704

Browse files
committed
Merge pull request numpy#7549 from matthew-brett/fix-no-compiler-errors
BUG: allow graceful recovery for no Liux compiler
2 parents f1b0091 + fc398de commit 3509704

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

numpy/distutils/tests/test_system_info.py

+30-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
import shutil
55
from tempfile import mkstemp, mkdtemp
6+
from subprocess import Popen, PIPE
7+
from distutils.errors import DistutilsError
68

79
from numpy.distutils import ccompiler
810
from numpy.testing import TestCase, run_module_suite, assert_, assert_equal
@@ -54,6 +56,27 @@ def get_class(name, notfound_action=1):
5456
}
5557
"""
5658

59+
def have_compiler():
60+
""" Return True if there appears to be an executable compiler
61+
"""
62+
compiler = ccompiler.new_compiler()
63+
try:
64+
cmd = compiler.compiler # Unix compilers
65+
except AttributeError:
66+
try:
67+
compiler.initialize() # MSVC is different
68+
except DistutilsError:
69+
return False
70+
cmd = [compiler.cc]
71+
try:
72+
Popen(cmd, stdout=PIPE, stderr=PIPE)
73+
except OSError:
74+
return False
75+
return True
76+
77+
78+
HAVE_COMPILER = have_compiler()
79+
5780

5881
class test_system_info(system_info):
5982

@@ -171,38 +194,39 @@ def test_temp2(self):
171194
extra = tsi.calc_extra_info()
172195
assert_equal(extra['extra_link_args'], ['-Wl,-rpath=' + self._lib2])
173196

197+
@skipif(not HAVE_COMPILER)
174198
def test_compile1(self):
175199
# Compile source and link the first source
176200
c = ccompiler.new_compiler()
201+
previousDir = os.getcwd()
177202
try:
178203
# Change directory to not screw up directories
179-
previousDir = os.getcwd()
180204
os.chdir(self._dir1)
181205
c.compile([os.path.basename(self._src1)], output_dir=self._dir1)
182206
# Ensure that the object exists
183207
assert_(os.path.isfile(self._src1.replace('.c', '.o')) or
184208
os.path.isfile(self._src1.replace('.c', '.obj')))
209+
finally:
185210
os.chdir(previousDir)
186-
except OSError:
187-
pass
188211

212+
@skipif(not HAVE_COMPILER)
189213
@skipif('msvc' in repr(ccompiler.new_compiler()))
190214
def test_compile2(self):
191215
# Compile source and link the second source
192216
tsi = self.c_temp2
193217
c = ccompiler.new_compiler()
194218
extra_link_args = tsi.calc_extra_info()['extra_link_args']
219+
previousDir = os.getcwd()
195220
try:
196221
# Change directory to not screw up directories
197-
previousDir = os.getcwd()
198222
os.chdir(self._dir2)
199223
c.compile([os.path.basename(self._src2)], output_dir=self._dir2,
200224
extra_postargs=extra_link_args)
201225
# Ensure that the object exists
202226
assert_(os.path.isfile(self._src2.replace('.c', '.o')))
227+
finally:
203228
os.chdir(previousDir)
204-
except OSError:
205-
pass
229+
206230

207231
if __name__ == '__main__':
208232
run_module_suite()

0 commit comments

Comments
 (0)