Skip to content

Commit

Permalink
code style cleanup in get_software_libdir + enhance test
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Jun 7, 2024
1 parent 1636724 commit 171fdb8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
15 changes: 9 additions & 6 deletions easybuild/tools/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions test/framework/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'])

Expand Down

0 comments on commit 171fdb8

Please sign in to comment.