Skip to content

Commit fa667e5

Browse files
committed
test(fortran): isolate further
1 parent f7fcb8f commit fa667e5

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

test/test_dependencies.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
class Tests(unittest.TestCase):
88

9-
def test_gfortran(self):
10-
gfortran_path = shutil.which('gfortran')
11-
self.assertIsNotNone(gfortran_path)
12-
139
def test_swig(self):
1410
swig_path = shutil.which('swig')
1511
self.assertIsNotNone(swig_path)

test/test_fortran.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@
1313
from transpyle.general import AstGeneralizer, Binder, CodeReader, Compiler, Parser, Unparser
1414
try:
1515
from transpyle.fortran.parser import FortranParser
16-
except ImportError:
16+
except (ImportError, ExternalToolError):
1717
pass
1818
try:
1919
from transpyle.fortran.ast_generalizer import FortranAstGeneralizer
20-
except ImportError:
20+
except (ImportError, ExternalToolError):
2121
pass
2222
try:
2323
from transpyle.fortran.unparser import Fortran77Unparser
24-
except ImportError:
24+
except (ImportError, ExternalToolError):
2525
pass
2626
try:
2727
from transpyle.fortran.compiler import F2PyCompiler
28-
except ImportError:
28+
except (ImportError, ExternalToolError):
2929
pass
3030
try:
3131
from transpyle.fortran.compiler_interface import GfortranInterface, PgifortranInterface
32-
except ImportError:
32+
except (ImportError, ExternalToolError):
3333
pass
3434

3535
from .common import \

transpyle/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
try:
3030
from .fortran import *
31-
except ImportError:
31+
except (ImportError, ExternalToolError):
3232
_LOG.warning("Fortran unavailable")
3333

3434
# try:

transpyle/fortran/compiler_interface.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
import argunparse
77
import numpy.f2py
8+
import version_query
89

9-
from ..general import call_tool, CompilerInterface
10+
from ..general import call_tool, CompilerInterface, ExternalTool
11+
from ..general.exc import ExternalToolVersionError
1012

1113
_LOG = logging.getLogger(__name__)
1214

@@ -33,6 +35,24 @@ class GfortranInterface(CompilerInterface):
3335
}
3436

3537

38+
class Gfortran(ExternalTool):
39+
40+
"""GNU Fortran compiler tool."""
41+
42+
path = GfortranInterface._executables['']
43+
_version_arg = '--version'
44+
45+
@classmethod
46+
def _version_output_filter(cls, output: str) -> str:
47+
for output_line in output.splitlines():
48+
if output_line.startswith('GNU Fortran '):
49+
return output_line.split(' ')[-1]
50+
raise ExternalToolVersionError(f'could not extract version from output: {output}')
51+
52+
53+
Gfortran.assert_version_at_least(version_query.Version(10, 0))
54+
55+
3656
class PgifortranInterface(CompilerInterface):
3757

3858
"""PGI Fortran compiler interface."""

0 commit comments

Comments
 (0)