8000 BLD: Change Fortran version flag and string check · pitrou/numpy@c4c2f21 · GitHub
[go: up one dir, main page]

Skip to content

Commit c4c2f21

Browse files
committed
BLD: Change Fortran version flag and string check
The version check flag for GnuFCompiler and Gnu95FCompiler were changed from `--version` to `-dumpversion`. This simplifies the gnu_version_match code for gfortran, and makes it possible to drop much of the check code for g77 as well. This fix addresses issue numpy#5315 and numpy#5321.
1 parent 8a2dd06 commit c4c2f21

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

numpy/distutils/fcompiler/gnu.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,23 @@ class GnuFCompiler(FCompiler):
3535

3636
def gnu_version_match(self, version_string):
3737
"""Handle the different versions of GNU fortran compilers"""
38-
m = re.search(r'GNU Fortran', version_string)
39-
if not m:
40-
return None
41-
m = re.search(r'GNU Fortran\s+95.*?([0-9-.]+)', version_string)
42-
if m:
43-
return ('gfortran', m.group(1))
44-
m = re.search(r'GNU Fortran.*?\-?([0-9-.]+)', version_string)
38+
# Try to find a valid version string
39+
m = re.search(r'([0-9.]+)', version_string)
4540
if m:
46-
v = m.group(1)
47-
if v.startswith('0') or v.startswith('2') or v.startswith('3'):
48-
# the '0' is for early g77's
49-
return ('g77', v)
50-
else:
51-
# at some point in the 4.x series, the ' 95' was dropped
52-
# from the version string
53-
return ('gfortran', v)
41+
# g77 provides a longer version string that starts with GNU
42+
# Fortran
43+
if version_string.startswith('GNU Fortran'):
44+
return ('g77', m.group(1))
45+
46+
# gfortran only outputs a version string such as #.#.#, so check
47+
# if the match is at the start of the string
48+
elif m.start() == 0:
49+
return ('gfortran', m.group(1))
50+
51+
# If these checks fail, then raise an error to make the problem easy
52+
# to find.
53+
err = 'A valid Fortran verison was not found in this string:\n'
54+
raise ValueError(err + version_string)
5455

5556
def version_match(self, version_string):
5657
v = self.gnu_version_match(version_string)
@@ -68,7 +69,7 @@ def version_match(self, version_string):
6869

6970
possible_executables = ['g77', 'f77']
7071
executables = {
71-
'version_cmd' : [None, "--version"],
72+
'version_cmd' : [None, "-dumpversion"],
7273
'compiler_f77' : [None, "-g", "-Wall", "-fno-second-underscore"],
7374
'compiler_f90' : None, # Use --fcompiler=gnu95 for f90 codes
7475
'compiler_fix' : None,
@@ -254,7 +255,7 @@ def version_match(self, version_string):
254255

255256
possible_executables C933 = ['gfortran', 'f95']
256257
executables = {
257-
'version_cmd' : ["<F90>", "--version"],
258+
'version_cmd' : ["<F90>", "-dumpversion"],
258259
'compiler_f77' : [None, "-Wall", "-g", "-ffixed-form",
259260
"-fno-second-underscore"] + _EXTRAFLAGS,
260261
'compiler_f90' : [None, "-Wall", "-g",

numpy/distutils/tests/test_fcompiler_gnu.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@
1414
]
1515

1616
gfortran_version_strings = [
17-
('GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3))',
18-
'4.0.3'),
19-
('GNU Fortran 95 (GCC) 4.1.0', '4.1.0'),
20-
('GNU Fortran 95 (GCC) 4.2.0 20060218 (experimental)', '4.2.0'),
21-
('GNU Fortran (GCC) 4.3.0 20070316 (experimental)', '4.3.0'),
22-
('GNU Fortran (rubenvb-4.8.0) 4.8.0', '4.8.0'),
17+
('4.8.0', '4.8.0'),
18+
('4.0.3-7', '4.0.3'),
2319
]
2420

2521
class TestG77Versions(TestCase):

0 commit comments

Comments
 (0)
0