Skip to content

Commit

Permalink
Merge pull request #7551 from charris/backport-7549
Browse files Browse the repository at this point in the history
Backport 7549, BUG: allow graceful recovery for no compiler
  • Loading branch information
charris committed Apr 16, 2016
2 parents def1094 + 1c122a4 commit 1a3e301
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions numpy/distutils/tests/test_system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os
import shutil
from tempfile import mkstemp, mkdtemp
from subprocess import Popen, PIPE
from distutils.errors import DistutilsError

from numpy.distutils import ccompiler
from numpy.testing import TestCase, run_module_suite, assert_, assert_equal
Expand Down Expand Up @@ -54,6 +56,27 @@ def get_class(name, notfound_action=1):
}
"""

def have_compiler():
""" Return True if there appears to be an executable compiler
"""
compiler = ccompiler.new_compiler()
try:
cmd = compiler.compiler # Unix compilers
except AttributeError:
try:
compiler.initialize() # MSVC is different
except DistutilsError:
return False
cmd = [compiler.cc]
try:
Popen(cmd, stdout=PIPE, stderr=PIPE)
except OSError:
return False
return True


HAVE_COMPILER = have_compiler()


class test_system_info(system_info):

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

@skipif(not HAVE_COMPILER)
def test_compile1(self):
# Compile source and link the first source
c = ccompiler.new_compiler()
previousDir = os.getcwd()
try:
# Change directory to not screw up directories
previousDir = os.getcwd()
os.chdir(self._dir1)
c.compile([os.path.basename(self._src1)], output_dir=self._dir1)
# Ensure that the object exists
assert_(os.path.isfile(self._src1.replace('.c', '.o')) or
os.path.isfile(self._src1.replace('.c', '.obj')))
finally:
os.chdir(previousDir)
except OSError:
pass

@skipif(not HAVE_COMPILER)
@skipif('msvc' in repr(ccompiler.new_compiler()))
def test_compile2(self):
# Compile source and link the second source
tsi = self.c_temp2
c = ccompiler.new_compiler()
extra_link_args = tsi.calc_extra_info()['extra_link_args']
previousDir = os.getcwd()
try:
# Change directory to not screw up directories
previousDir = os.getcwd()
os.chdir(self._dir2)
c.compile([os.path.basename(self._src2)], output_dir=self._dir2,
extra_postargs=extra_link_args)
# Ensure that the object exists
assert_(os.path.isfile(self._src2.replace('.c', '.o')))
finally:
os.chdir(previousDir)
except OSError:
pass


if __name__ == '__main__':
run_module_suite()

0 comments on commit 1a3e301

Please sign in to comment.