From f35ae5e6b8336ff42f8d9722ca1e7f10e8b85404 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Fri, 8 Nov 2024 11:16:20 +0100 Subject: [PATCH] Remove extra indent by checking for missing root first --- easybuild/tools/modules.py | 84 +++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/easybuild/tools/modules.py b/easybuild/tools/modules.py index 5a6c55d917..ef357b69d1 100644 --- a/easybuild/tools/modules.py +++ b/easybuild/tools/modules.py @@ -1712,52 +1712,52 @@ def get_software_libdir(name, only_one=True, fs=None, full_path=False): """ lib_subdirs = ['lib', 'lib64'] root = get_software_root(name) + if not root: + # return None if software package root could not be determined + return None + found_subdirs = [] - if root: - for lib_subdir in lib_subdirs: - lib_dir_path = os.path.join(root, lib_subdir) - if os.path.exists(lib_dir_path): - # take into account that lib64 could be a symlink to lib (or vice versa) - # see https://github.com/easybuilders/easybuild-framework/issues/3139 - if any(os.path.samefile(lib_dir_path, os.path.join(root, x)) for x in found_subdirs): - _log.debug("%s is the same as one of the other paths, so skipping it", lib_dir_path) - - elif fs is None or any(os.path.exists(os.path.join(lib_dir_path, f)) for f in fs): - _log.debug("Retaining library subdir '%s' (found at %s)", lib_subdir, lib_dir_path) - found_subdirs.append(lib_subdir) - - elif build_option('extended_dry_run'): + for lib_subdir in lib_subdirs: + lib_dir_path = os.path.join(root, lib_subdir) + if os.path.exists(lib_dir_path): + # take into account that lib64 could be a symlink to lib (or vice versa) + # see https://github.com/easybuilders/easybuild-framework/issues/3139 + if any(os.path.samefile(lib_dir_path, os.path.join(root, x)) for x in found_subdirs): + _log.debug("%s is the same as one of the other paths, so skipping it", lib_dir_path) + + elif fs is None or any(os.path.exists(os.path.join(lib_dir_path, f)) for f in fs): + _log.debug("Retaining library subdir '%s' (found at %s)", lib_subdir, lib_dir_path) found_subdirs.append(lib_subdir) - break - # if no library subdir was found, return None - if not found_subdirs: - return None - if full_path: - res = [os.path.join(root, subdir) for subdir in found_subdirs] - else: - res = found_subdirs - if only_one: - if len(res) == 1: - res = res[0] - else: - 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()]] - has_libs = [any(glob.glob(os.path.join(root, subdir, f)) for f in lib_glob) - for subdir in found_subdirs] - if has_libs[0] and not has_libs[1]: - return res[0] - if 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(found_subdirs)) - return res - else: - # return None if software package root could not be determined + elif build_option('extended_dry_run'): + found_subdirs.append(lib_subdir) + break + + # if no library subdir was found, return None + if not found_subdirs: return None + if full_path: + res = [os.path.join(root, subdir) for subdir in found_subdirs] + else: + res = found_subdirs + if only_one: + if len(res) == 1: + res = res[0] + else: + 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()]] + has_libs = [any(glob.glob(os.path.join(root, subdir, f)) for f in lib_glob) + for subdir in found_subdirs] + if has_libs[0] and not has_libs[1]: + return res[0] + if 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(found_subdirs)) + return res def get_software_version_env_var_name(name):