Skip to content

Commit 8c4d081

Browse files
committed
feat: test for presence of swig
1 parent 5c98e46 commit 8c4d081

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

transpyle/cpp/compiler.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
import typing as t
1010

1111
import argunparse
12+
import version_query
1213

1314
from ..general import \
1415
temporarily_change_dir, run_tool, \
15-
Language, CodeReader, Parser, AstGeneralizer, Unparser, Compiler
16+
ExternalTool, Language, CodeReader, Parser, AstGeneralizer, Unparser, Compiler
17+
from ..general.exc import ExternalToolVersionError
1618
from .compiler_interface import GppInterface, ClangppInterface
1719

1820
SWIG_INTERFACE_TEMPLATE = '''/* File: {module_name}.i */
@@ -90,6 +92,23 @@
9092
_LOG = logging.getLogger(__name__)
9193

9294

95+
class Swig(ExternalTool):
96+
"""Define requirements for SWIG."""
97+
98+
path = pathlib.Path('swig')
99+
_version_arg = '-version'
100+
101+
@classmethod
102+
def _version_output_filter(cls, output: str) -> str:
103+
for output_line in output.splitlines():
104+
if output_line.startswith('SWIG Version '):
105+
return output_line.replace('SWIG Version ', '')
106+
raise ExternalToolVersionError(f'could not extract version from output: {output}')
107+
108+
109+
Swig.assert_version_at_least(version_query.Version(4, 0))
110+
111+
93112
class SwigCompiler(Compiler):
94113

95114
# TODO: create SWIG compiler interface similarily to F2PY interface

0 commit comments

Comments
 (0)