From 6a3492846f6f8f7881343796d8983b026ccfd7e2 Mon Sep 17 00:00:00 2001 From: Sylvain Tricot Date: Thu, 4 Jun 2020 13:35:45 +0200 Subject: [PATCH] Add a f2py_path option to the scons script. Sometimes the virtualenv version of f2py does not take precedence over the system-wide one if any. It is now possible to enforce a given f2py path. --- src/SConstruct | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/SConstruct b/src/SConstruct index 196886a..5673fa9 100644 --- a/src/SConstruct +++ b/src/SConstruct @@ -1,4 +1,5 @@ import os +import subprocess ############################################################################### def filtered_glob(env, pattern, omit=[], @@ -16,7 +17,8 @@ def f2py_generator(source, target, env, for_signature): modulefile = str(target[0]) modulename = modulefile.replace(suffix, '').replace('/', '.') compiler = env['FORTRAN'] - cmd = f"f2py3 --fcompiler={compiler} " + + cmd = f"$F2PY --fcompiler={compiler} " cmd += f" $F2PY_OPTS -m {modulename} -c {objects} {main}" cmd += f" && cp {'/'.join(modulename.split('.'))}.*.so {modulefile}" #cmd += " 1>/dev/null 2>/dev/null" @@ -55,6 +57,10 @@ AddOption('--compiler', choices=['gfortran', 'ifort'], help='The Fortran compiler to use') +AddOption('--f2py_path', + dest='f2py_path', + default='f2py3', + help='The full path to the f2py compiler') @@ -71,6 +77,13 @@ if GetOption('compiler') == 'gfortran': elif GetOption('compiler') == 'ifort': env = ifort_env +f2py_path = GetOption('f2py_path') +p = subprocess.run(['which', f2py_path], stdout=subprocess.PIPE) +if p.returncode != 0: + raise Exception('Invalid path for f2py compiler!') +else: + env.Append(F2PY=p.stdout.decode('utf8').strip()) + if GetOption('dbg'): gfortran_env.Append(FORTRANFLAGS = ['-g', '-Wall', '-Wextra', '-Warray-temporaries', '-Wconversion', '-fbacktrace', '-ffree-line-length-0',