From 171fdb81465d362fad0d223981edcb914c268fb2 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Fri, 7 Jun 2024 17:07:44 +0200 Subject: [PATCH] code style cleanup in get_software_libdir + enhance test --- easybuild/tools/modules.py | 15 +++++++++------ test/framework/modules.py | 13 +++++++++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/easybuild/tools/modules.py b/easybuild/tools/modules.py index a24ddaa369..7318be4f4f 100644 --- a/easybuild/tools/modules.py +++ b/easybuild/tools/modules.py @@ -1706,13 +1706,16 @@ def get_software_libdir(name, only_one=True, fs=None): if len(res) == 1: res = res[0] else: - if fs is None: - # check if only one (exactly) has libraries + if fs is None and len(res) == 2: + # if both lib and lib64 were found, check if only one (exactly) has libraries; # this is needed for software with library archives in lib64 but other files/directories in lib - lib_glob = ["*.%s" % ext for ext in ["a", get_shared_lib_ext()]] - haslibs = [any(glob.glob(os.path.join(root, subdir, f)) for f in lib_glob) for subdir in res] - if haslibs[0] != haslibs[1]: - return res[int(not haslibs[0])] + lib_glob = ['*.%s' % ext for ext in ['a', get_shared_lib_ext()]] + has_libs = [any(glob.glob(os.path.join(root, subdir, f)) for f in lib_glob) for subdir in res] + if has_libs[0] and not has_libs[1]: + return res[0] + elif has_libs[1] and not has_libs[0]: + return res[1] + raise EasyBuildError("Multiple library subdirectories found for %s in %s: %s", name, root, ', '.join(res)) return res diff --git a/test/framework/modules.py b/test/framework/modules.py index bb11802db7..195bf0339c 100644 --- a/test/framework/modules.py +++ b/test/framework/modules.py @@ -51,6 +51,7 @@ from easybuild.tools.modules import curr_module_paths, get_software_libdir, get_software_root, get_software_version from easybuild.tools.modules import invalidate_module_caches_for, modules_tool, reset_module_caches from easybuild.tools.run import run_cmd +from easybuild.tools.systemtools import get_shared_lib_ext # number of modules included for testing purposes @@ -678,11 +679,19 @@ def test_get_software_root_version_libdir(self): root = os.path.join(tmpdir, name) mkdir(os.path.join(root, 'lib64')) os.environ['EBROOT%s' % env_var_name] = root - write_file(os.path.join(root, 'lib', 'foo.a'), 'foo') + write_file(os.path.join(root, 'lib', 'libfoo.a'), 'foo') self.assertEqual(get_software_libdir(name), 'lib') + remove_file(os.path.join(root, 'lib', 'libfoo.a')) + + # also check vice versa with *shared* library in lib64 + shlib_ext = get_shared_lib_ext() + write_file(os.path.join(root, 'lib64', 'libfoo.' + shlib_ext), 'foo') + self.assertEqual(get_software_libdir(name), 'lib64') + + remove_file(os.path.join(root, 'lib64', 'libfoo.' + shlib_ext)) + # check expected result of get_software_libdir with multiple lib subdirs - remove_file(os.path.join(root, 'lib', 'foo.a')) self.assertErrorRegex(EasyBuildError, "Multiple library subdirectories found.*", get_software_libdir, name) self.assertEqual(get_software_libdir(name, only_one=False), ['lib', 'lib64'])