From 2d5aadc21d4439cf394368c736e363f9b1322cf8 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Fri, 7 Jun 2019 08:34:31 +0200 Subject: [PATCH] Simplified the implementation of 'search_paths_for_executables' The function doesn't use anymore 'map', 'filter' and 'os.path.realpath' + it's based on a single loop. --- lib/spack/llnl/util/filesystem.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index cd227e733ac..2234b34d3b4 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -9,7 +9,6 @@ import fileinput import glob import grp -import itertools import numbers import os import pwd @@ -1400,16 +1399,15 @@ def search_paths_for_executables(*path_hints): A list containing the real path of every existing directory in `path_hints` and its `bin` subdirectory if it exists. """ - # Select the realpath of existing directories - existing_paths = filter(os.path.isdir, map(os.path.realpath, path_hints)) + executable_paths = [] + for path in path_hints: + if not os.path.isdir(path): + continue - # Adding their 'bin' subdirectory - def maybe_add_bin(path): - bin_subdirectory = os.path.realpath(os.path.join(path, 'bin')) - if os.path.isdir(bin_subdirectory): - return [path, bin_subdirectory] - return [path] + executable_paths.append(path) - return list( - itertools.chain.from_iterable(map(maybe_add_bin, existing_paths)) - ) + bin_dir = os.path.join(path, 'bin') + if os.path.isdir(bin_dir): + executable_paths.append(bin_dir) + + return executable_paths