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.
This commit is contained in:
parent
f2824d64d9
commit
2d5aadc21d
@ -9,7 +9,6 @@
|
|||||||
import fileinput
|
import fileinput
|
||||||
import glob
|
import glob
|
||||||
import grp
|
import grp
|
||||||
import itertools
|
|
||||||
import numbers
|
import numbers
|
||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
@ -1400,16 +1399,15 @@ def search_paths_for_executables(*path_hints):
|
|||||||
A list containing the real path of every existing directory
|
A list containing the real path of every existing directory
|
||||||
in `path_hints` and its `bin` subdirectory if it exists.
|
in `path_hints` and its `bin` subdirectory if it exists.
|
||||||
"""
|
"""
|
||||||
# Select the realpath of existing directories
|
executable_paths = []
|
||||||
existing_paths = filter(os.path.isdir, map(os.path.realpath, path_hints))
|
for path in path_hints:
|
||||||
|
if not os.path.isdir(path):
|
||||||
|
continue
|
||||||
|
|
||||||
# Adding their 'bin' subdirectory
|
executable_paths.append(path)
|
||||||
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]
|
|
||||||
|
|
||||||
return list(
|
bin_dir = os.path.join(path, 'bin')
|
||||||
itertools.chain.from_iterable(map(maybe_add_bin, existing_paths))
|
if os.path.isdir(bin_dir):
|
||||||
)
|
executable_paths.append(bin_dir)
|
||||||
|
|
||||||
|
return executable_paths
|
||||||
|
Loading…
Reference in New Issue
Block a user