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.
This commit is contained in:
Sylvain Tricot 2020-06-04 13:35:45 +02:00
parent a9d42a81fe
commit 6a3492846f
1 changed files with 14 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import os import os
import subprocess
############################################################################### ###############################################################################
def filtered_glob(env, pattern, omit=[], def filtered_glob(env, pattern, omit=[],
@ -16,7 +17,8 @@ def f2py_generator(source, target, env, for_signature):
modulefile = str(target[0]) modulefile = str(target[0])
modulename = modulefile.replace(suffix, '').replace('/', '.') modulename = modulefile.replace(suffix, '').replace('/', '.')
compiler = env['FORTRAN'] compiler = env['FORTRAN']
cmd = f"f2py3 --fcompiler={compiler} "
cmd = f"$F2PY --fcompiler={compiler} "
cmd += f" $F2PY_OPTS -m {modulename} -c {objects} {main}" cmd += f" $F2PY_OPTS -m {modulename} -c {objects} {main}"
cmd += f" && cp {'/'.join(modulename.split('.'))}.*.so {modulefile}" cmd += f" && cp {'/'.join(modulename.split('.'))}.*.so {modulefile}"
#cmd += " 1>/dev/null 2>/dev/null" #cmd += " 1>/dev/null 2>/dev/null"
@ -55,6 +57,10 @@ AddOption('--compiler',
choices=['gfortran', 'ifort'], choices=['gfortran', 'ifort'],
help='The Fortran compiler to use') 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': elif GetOption('compiler') == 'ifort':
env = ifort_env 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'): if GetOption('dbg'):
gfortran_env.Append(FORTRANFLAGS = ['-g', '-Wall', '-Wextra', '-Warray-temporaries', gfortran_env.Append(FORTRANFLAGS = ['-g', '-Wall', '-Wextra', '-Warray-temporaries',
'-Wconversion', '-fbacktrace', '-ffree-line-length-0', '-Wconversion', '-fbacktrace', '-ffree-line-length-0',