Given the raw name of a library in `library_name`, tries to find a
    static library with this name in the given `library_path`. `library_path`
    is automatically extended with common library directories on Linux and Mac
    OS X.
177132
def find_static_library(library_name, library_path):
    """"""

    variants = ["lib{0}.a", "{0}.a", "{0}.lib", "lib{0}.lib"]
    if is_unix_like():
        extra_libdirs = ["/usr/local/lib64", "/usr/local/lib",
                "/usr/lib64", "/usr/lib", "/lib64", "/lib"]
    else:
        extra_libdirs = []

    for path in extra_libdirs:
        if path not in library_path and os.path.isdir(path):
            library_path.append(path)

    for path in library_path:
        for variant in variants:
            full_path = os.path.join(path, variant.format(library_name))
            if os.path.isfile(full_path):
                return full_path
846277
def find_module(cls, fullname, path=None):
        
        spec = cls.find_spec(fullname, path)
        if spec is None:
            return None
        elif spec.loader is None and spec.submodule_search_locations:
            # Here we need to create a namespace loader to handle namespaces since python2 doesn't...
            return NamespaceLoader2(spec.name, spec.submodule_search_locations)
        else:
            return spec.loader
973322
def add_library(self, name):
        
        libdoc = LibraryDocumentation(name)
        if len(libdoc.keywords) > 0:
            # FIXME: figure out the path to the library file
            collection_id = self.add_collection(None, libdoc.name, libdoc.type,
                                                libdoc.doc, libdoc.version,
                                                libdoc.scope, libdoc.named_args,
                                                libdoc.doc_format)
            self._load_keywords(collection_id, libdoc=libdoc)
567072
def load_library(version):
    
    check_version(version)
    module_name = SUPPORTED_LIBRARIES[version]
    lib = sys.modules.get(module_name)
    if lib is None:
        lib = importlib.import_module(module_name)
    return lib
1313076
def _load_library(self):
        
        path = self._library_path()
        logger.info("Loading library from path {}".format(path))
        library_dir = os.path.dirname(path)
        if platform.system() == 'Windows':
            import win32api
            olddir = os.getcwd()
            os.chdir(library_dir)
            win32api.SetDllDirectory('.')

        result = cdll.LoadLibrary(path)

        if platform.system() == 'Windows':
            os.chdir(olddir)

        return result
271217
def find_library(series_path):
    

    for location in cfg.CONF.libraries:
        if os.path.isdir(os.path.join(location, series_path)):
            return location
        # already tried the full path; now walk down the path
        segments = series_path.split(os.sep)[:-1]
        while segments:
            seg_path = os.path.join(*segments)
            # if the directory exists then we found our location
            if os.path.isdir(os.path.join(location, seg_path)):
                return location
            # remove the last element and try again
            segments = segments[:-1]

    return cfg.CONF.default_library
268755
def common_directory(paths):
    
    import posixpath
    def get_dir_with_slash(path):
        if path == b'' or path.endswith(b'/'):
            return path
        else:
            dirname, basename = posixpath.split(path)
            if dirname == b'':
                return dirname
            else:
                return dirname + b'/'

    if not paths:
        return None
    elif len(paths) == 1:
        return get_dir_with_slash(paths[0])
    else:
        common = common_path(paths[0], paths[1])
        for path in paths[2:]:
            common = common_path(common, path)
        return get_dir_with_slash(common)
649210
def _find_library_candidates(library_names,
                             library_file_extensions,
                             library_search_paths):
    
    candidates = set()
    for library_name in library_names:
        for search_path in library_search_paths:
            glob_query = os.path.join(search_path, '*'+library_name+'*')
            for filename in glob.iglob(glob_query):
                filename = os.path.realpath(filename)
                if filename in candidates:
                    continue
                basename = os.path.basename(filename)
                if basename.startswith('lib'+library_name):
                    basename_end = basename[len('lib'+library_name):]
                elif basename.startswith(library_name):
                    basename_end = basename[len(library_name):]
                else:
                    continue
                for file_extension in library_file_extensions:
                    if basename_end.startswith(file_extension):
                        if basename_end[len(file_extension):][:1] in ('', '.'):
                            candidates.add(filename)
                    if basename_end.endswith(file_extension):
                        basename_middle = basename_end[:-len(file_extension)]
                        if all(c in '0123456789.' for c in basename_middle):
                            candidates.add(filename)
    return candidates
1004595
def _find_lib_path():
    """"""
    curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
    amalgamation_lib_path = os.path.join(curr_path, '../../lib/libmxnet_predict.so')
    if os.path.exists(amalgamation_lib_path) and os.path.isfile(amalgamation_lib_path):
        lib_path = [amalgamation_lib_path]
        return lib_path
    else:
        logging.info('Cannot find libmxnet_predict.so. Will search for MXNet library using libinfo.py then.')
        try:
            from mxnet.libinfo import find_lib_path
            lib_path = find_lib_path()
            return lib_path
        except ImportError:
            libinfo_path = os.path.join(curr_path, '../../python/mxnet/libinfo.py')
            if os.path.exists(libinfo_path) and os.path.isfile(libinfo_path):
                libinfo = {'__file__': libinfo_path}
                exec(compile(open(libinfo_path, "rb").read(), libinfo_path, 'exec'), libinfo, libinfo)
                lib_path = libinfo['find_lib_path']()
                return lib_path
            else:
                raise RuntimeError('Cannot find libinfo.py at %s.' % libinfo_path)
1171015
def CheckLib(context, library = None, symbol = "main",
             header = None, language = None, autoadd = 1):
    

    if library == []:
        library = [None]

    if not SCons.Util.is_List(library):
        library = [library]

    # ToDo: accept path for the library
    res = SCons.Conftest.CheckLib(context, library, symbol, header = header,
                                        language = language, autoadd = autoadd)
    context.did_show_result = 1
    return not res
1139629
def get_library_name():
    
    from os.path import split, abspath

    __lib_name = split(split(abspath(sys.modules[__name__].__file__))[0])[1]

    assert __lib_name in ["sframe", "turicreate"]

    return __lib_name
1369545
def find_lib_fpath(libname, root_dir, recurse_down=True, verbose=False, debug=False):
    

    def get_lib_fname_list(libname):
        """
        input <libname>: library name (e.g. 'hesaff', not 'libhesaff')
        returns <libnames>: list of plausible library file names
        """
        if sys.platform.startswith('win32'):
            libnames = ['lib' + libname + '.dll', libname + '.dll']
        elif sys.platform.startswith('darwin'):
            libnames = ['lib' + libname + '.dylib']
        elif sys.platform.startswith('linux'):
            libnames = ['lib' + libname + '.so']
        else:
            raise Exception('Unknown operating system: %s' % sys.platform)
        return libnames

    def get_lib_dpath_list(root_dir):
        """
        input <root_dir>: deepest directory to look for a library (dll, so, dylib)
        returns <libnames>: list of plausible directories to look.
        """
        'returns possible lib locations'
        get_lib_dpath_list = [root_dir,
                              join(root_dir, 'lib'),
                              join(root_dir, 'build'),
                              join(root_dir, 'build', 'lib')]
        return get_lib_dpath_list

    lib_fname_list = get_lib_fname_list(libname)
    tried_fpaths = []
    while root_dir is not None:
        for lib_fname in lib_fname_list:
            for lib_dpath in get_lib_dpath_list(root_dir):
                lib_fpath = normpath(join(lib_dpath, lib_fname))
                if exists(lib_fpath):
                    if verbose:
                        print('\n[c] Checked: '.join(tried_fpaths))
                    if debug:
                        print('using: %r' % lib_fpath)
                    return lib_fpath
                else:
                    # Remember which candiate library fpaths did not exist
                    tried_fpaths.append(lib_fpath)
            _new_root = dirname(root_dir)
            if _new_root == root_dir:
                root_dir = None
                break
            else:
                root_dir = _new_root
        if not recurse_down:
            break

    msg = ('\n[C!] load_clib(libname=%r root_dir=%r, recurse_down=%r, verbose=%r)' %
           (libname, root_dir, recurse_down, verbose) +
           '\n[c!] Cannot FIND dynamic library')
    print(msg)
    print('\n[c!] Checked: '.join(tried_fpaths))
    raise ImportError(msg)
821332
def get_static_lib_paths():
    
    libs = []
    is_linux = sys.platform.startswith('linux')
    if is_linux:
        libs += ['-Wl,--start-group']
    libs += get_raw_static_lib_path()
    if is_linux:
        libs += ['-Wl,--end-group']
    return libs
1137737
def absolute_path(self, path, start):
        
        if posixpath.isabs(path):
            path = posixpath.join(staticfiles_storage.location, path)
        else:
            path = posixpath.join(start, path)
        return posixpath.normpath(path)
1133667
def load_library_permanently(filename):
    
    with ffi.OutputString() as outerr:
        if ffi.lib.LLVMPY_LoadLibraryPermanently(
                _encode_string(filename), outerr):
            raise RuntimeError(str(outerr))
301784
def load_library(self,libname):
        """"""
        paths = self.getpaths(libname)

        for path in paths:
            if os.path.exists(path):
                return self.load(path)

        raise ImportError("%s not found." % libname)
1134388
def _findSwiplDar():
    

    # If the exec is in path
    (path, swiHome) = _findSwiplFromExec()
    if path is not None:
        return (path, swiHome)

    # If it is not, use  find_library
    path = _findSwiplPathFromFindLib()
    if path is not None:
        return (path, swiHome)

    # Last guess, searching for the file
    paths = ['.', './lib', '/usr/lib/', '/usr/local/lib', '/opt/local/lib']
    names = ['libswipl.dylib', 'libpl.dylib']

    for name in names:
        for path in paths:
            path = os.path.join(path, name)
            if os.path.exists(path):
                return (path, None)

    return (None, None)