summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/distutils/fcompiler/gnu.py47
-rw-r--r--numpy/distutils/tests/test_fcompiler_gnu.py8
2 files changed, 40 insertions, 15 deletions
diff --git a/numpy/distutils/fcompiler/gnu.py b/numpy/distutils/fcompiler/gnu.py
index b61574dba..f568135c0 100644
--- a/numpy/distutils/fcompiler/gnu.py
+++ b/numpy/distutils/fcompiler/gnu.py
@@ -40,22 +40,41 @@ class GnuFCompiler(FCompiler):
while version_string.startswith('gfortran: warning'):
version_string = version_string[version_string.find('\n')+1:]
- # Try to find a valid version string
- m = re.search(r'([0-9.]+)', version_string)
- if m:
- # g77 provides a longer version string that starts with GNU
- # Fortran
- if version_string.startswith('GNU Fortran'):
- return ('g77', m.group(1))
-
- # gfortran only outputs a version string such as #.#.#, so check
- # if the match is at the start of the string
- elif m.start() == 0:
+ # Gfortran versions from after 2010 will output a simple string
+ # (usually "x.y", "x.y.z" or "x.y.z-q") for ``-dumpversion``; older
+ # gfortrans may still return long version strings (``-dumpversion`` was
+ # an alias for ``--version``)
+ if len(version_string) <= 20:
+ # Try to find a valid version string
+ m = re.search(r'([0-9.]+)', version_string)
+ if m:
+ # g77 provides a longer version string that starts with GNU
+ # Fortran
+ if version_string.startswith('GNU Fortran'):
+ return ('g77', m.group(1))
+
+ # gfortran only outputs a version string such as #.#.#, so check
+ # if the match is at the start of the string
+ elif m.start() == 0:
+ return ('gfortran', m.group(1))
+ else:
+ # Output probably from --version, try harder:
+ m = re.search(r'GNU Fortran\s+95.*?([0-9-.]+)', version_string)
+ if m:
return ('gfortran', m.group(1))
+ m = re.search(r'GNU Fortran.*?\-?([0-9-.]+)', version_string)
+ if m:
+ v = m.group(1)
+ if v.startswith('0') or v.startswith('2') or v.startswith('3'):
+ # the '0' is for early g77's
+ return ('g77', v)
+ else:
+ # at some point in the 4.x series, the ' 95' was dropped
+ # from the version string
+ return ('gfortran', v)
- # If these checks fail, then raise an error to make the problem easy
- # to find.
- err = 'A valid Fortran verison was not found in this string:\n'
+ # If still nothing, raise an error to make the problem easy to find.
+ err = 'A valid Fortran version was not found in this string:\n'
raise ValueError(err + version_string)
def version_match(self, version_string):
diff --git a/numpy/distutils/tests/test_fcompiler_gnu.py b/numpy/distutils/tests/test_fcompiler_gnu.py
index f7a124c50..7ca99db22 100644
--- a/numpy/distutils/tests/test_fcompiler_gnu.py
+++ b/numpy/distutils/tests/test_fcompiler_gnu.py
@@ -1,6 +1,6 @@
from __future__ import division, absolute_import, print_function
-from numpy.testing import *
+from numpy.testing import TestCase, assert_, run_module_suite
import numpy.distutils.fcompiler
@@ -14,6 +14,12 @@ g77_version_strings = [
]
gfortran_version_strings = [
+ ('GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3))',
+ '4.0.3'),
+ ('GNU Fortran 95 (GCC) 4.1.0', '4.1.0'),
+ ('GNU Fortran 95 (GCC) 4.2.0 20060218 (experimental)', '4.2.0'),
+ ('GNU Fortran (GCC) 4.3.0 20070316 (experimental)', '4.3.0'),
+ ('GNU Fortran (rubenvb-4.8.0) 4.8.0', '4.8.0'),
('4.8.0', '4.8.0'),
('4.0.3-7', '4.0.3'),
("gfortran: warning: couldn't understand kern.osversion '14.1.0\n4.9.1",