From a2d70a45fbc2ee07160c3ee750dbffe9d4fd5b1b Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Sat, 4 Mar 2017 11:23:57 -0600 Subject: Allow find_libraries to accept lists or strings (#3363) * Allow find_libraries to accept lists or strings * Convert one more example from list to string --- lib/spack/llnl/util/filesystem.py | 28 +++++++++++++++------------- lib/spack/spack/spec.py | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 79f15f9a21..7f6773266d 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -568,20 +568,22 @@ def find_libraries(args, root, shared=True, recurse=False): """Returns an iterable object containing a list of full paths to libraries if found. - Args: - args: iterable object containing a list of library names to \ - search for (e.g. 'libhdf5') - root: root folder where to start searching - shared: if True searches for shared libraries, otherwise for static - recurse: if False search only root folder, if True descends top-down \ - from the root - - Returns: - list of full paths to the libraries that have been found + :param args: Library name(s) to search for + :type args: str or collections.Sequence + :param str root: The root directory to start searching from + :param bool shared: if True searches for shared libraries, + otherwise for static + :param bool recurse: if False search only root folder, + if True descends top-down from the root + + :returns: The libraries that have been found + :rtype: LibraryList """ - if not isinstance(args, collections.Sequence) or isinstance(args, str): - message = '{0} expects a sequence of strings as first argument' - message += ' [got {1} instead]' + if isinstance(args, str): + args = [args] + elif not isinstance(args, collections.Sequence): + message = '{0} expects a string or sequence of strings as the ' + message += 'first argument [got {1} instead]' raise TypeError(message.format(find_libraries.__name__, type(args))) # Construct the right suffix for the library diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index c0ee8486db..9fc2c99e4a 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -767,7 +767,7 @@ def _libs_default_handler(descriptor, spec, cls): name = 'lib' + spec.name shared = '+shared' in spec return find_libraries( - [name], root=spec.prefix, shared=shared, recurse=True + name, root=spec.prefix, shared=shared, recurse=True ) -- cgit v1.2.3-60-g2f50