Fix the install problem due to *.so suffix.

F2PY can generate inconsistent suffix for *.so files due to a
different version of numpy if not the same as the one used
in the virtualenv. The workaround is to remove the
"cpython-36m-x86_64-linux-gnu"-like part of the name. The import
mechanism works well without. This is a tiny hack though.
This commit is contained in:
Sylvain Tricot 2020-05-29 16:13:02 +02:00
parent 43886601e9
commit 22a1433726
3 changed files with 11 additions and 15 deletions

View File

@ -1,9 +1,6 @@
from sysconfig import get_config_var
import os import os
############################################################################### ###############################################################################
suffix = get_config_var('EXT_SUFFIX')
def filtered_glob(env, pattern, omit=[], def filtered_glob(env, pattern, omit=[],
ondisk=True, source=False, strings=False): ondisk=True, source=False, strings=False):
return list(filter( return list(filter(
@ -12,27 +9,26 @@ def filtered_glob(env, pattern, omit=[],
# Create a builder for f2py # Create a builder for f2py
def f2py_generator(source, target, env, for_signature): def f2py_generator(source, target, env, for_signature):
suffix = ".so"
main = source[0] main = source[0]
objects = " ".join(o.get_path() for o in source[1:] if str(o).endswith('.o')) objects = " ".join(o.get_path() for o in source[1:] if str(o).endswith('.o'))
modulename = str(target[0]).replace(suffix, '').replace('/', '.') moduledir = os.path.dirname(target[0].abspath)
modulefile = str(target[0])
modulename = modulefile.replace(suffix, '').replace('/', '.')
compiler = env['FORTRAN'] compiler = env['FORTRAN']
cmd = f"f2py3 --fcompiler={compiler} " cmd = f"f2py3 --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 += " 1>/dev/null 2>/dev/null" #cmd += " 1>/dev/null 2>/dev/null"
return cmd return cmd
def f2py_emitter(target, source, env):
""" used to add the correct cpython .so suffix to the modulename """
target[0] = str(target[0]).replace('.', '/') + suffix
return target, source
def install_module(env, module): def install_module(env, module):
destdir = os.path.dirname(module[0].srcnode().abspath) destdir = os.path.dirname(module[0].srcnode().abspath)
env.Install(destdir, module) env.Install(destdir, module)
env.Alias('install', destdir) env.Alias('install', destdir)
return None return None
f2py_bld = Builder(generator=f2py_generator, emitter=f2py_emitter) f2py_bld = Builder(generator=f2py_generator)
# define the default build environment # define the default build environment
std = Environment(tools=['default', 'fortran'], F2PY_OPTS=[], LIBS=[]) std = Environment(tools=['default', 'fortran'], F2PY_OPTS=[], LIBS=[])

View File

@ -4,7 +4,7 @@ import os
objects_src= ['phagen_scf_2.1_dp.f'] objects_src= ['phagen_scf_2.1_dp.f']
objects = env.Object(objects_src) objects = env.Object(objects_src)
module = env.F2py('libphagen', ['main.f'] + objects, F2PYCOMSTR=">>") module = env.F2py('libphagen.so', ['main.f'] + objects, F2PYCOMSTR=">>")
env.InstallModule(module) env.InstallModule(module)
env.Alias('phagen', module) env.Alias('phagen', module)

View File

@ -45,19 +45,19 @@ Requires(memalloc_obj, dim_mod_obj)
common_deps = dim_mod_obj + memalloc_obj + cluster_gen_obj + common_sub_obj common_deps = dim_mod_obj + memalloc_obj + cluster_gen_obj + common_sub_obj
deps = common_deps + renormalization_obj + phd_se_noso_nosp_nosym_obj deps = common_deps + renormalization_obj + phd_se_noso_nosp_nosym_obj
phd_se_mod = env_spec.F2py('_phd_se_noso_nosp_nosym', ['phd_se_noso_nosp_nosym/main.f'] + deps) phd_se_mod = env_spec.F2py('_phd_se_noso_nosp_nosym.so', ['phd_se_noso_nosp_nosym/main.f'] + deps)
env_spec.InstallModule(phd_se_mod) env_spec.InstallModule(phd_se_mod)
deps = common_deps + renormalization_obj + phd_mi_noso_nosp_nosym_obj deps = common_deps + renormalization_obj + phd_mi_noso_nosp_nosym_obj
phd_mi_mod = env_spec.F2py('_phd_mi_noso_nosp_nosym', ['phd_mi_noso_nosp_nosym/main.f'] + deps) phd_mi_mod = env_spec.F2py('_phd_mi_noso_nosp_nosym.so', ['phd_mi_noso_nosp_nosym/main.f'] + deps)
env_spec.InstallModule(phd_mi_mod) env_spec.InstallModule(phd_mi_mod)
deps = common_deps + renormalization_obj + eig_common_obj + eig_mi_obj deps = common_deps + renormalization_obj + eig_common_obj + eig_mi_obj
eig_mi_mod = env_spec.F2py('_eig_mi', ['eig/mi/main.f'] + deps) eig_mi_mod = env_spec.F2py('_eig_mi.so', ['eig/mi/main.f'] + deps)
env_spec.InstallModule(eig_mi_mod) env_spec.InstallModule(eig_mi_mod)
deps = common_deps + renormalization_obj + eig_common_obj + eig_pw_obj deps = common_deps + renormalization_obj + eig_common_obj + eig_pw_obj
eig_pw_mod = env_spec.F2py('_eig_pw', ['eig/pw/main.f'] + deps) eig_pw_mod = env_spec.F2py('_eig_pw.so', ['eig/pw/main.f'] + deps)
env_spec.InstallModule(eig_pw_mod) env_spec.InstallModule(eig_pw_mod)
# Alias # Alias