def where()

in builder/core/util.py [0:0]


def where(exe, path=None, resolve_symlinks=True):
    """ Platform agnostic `where executable` command """

    if exe is None:
        return None
    if path is None:
        path = os.environ['PATH']
    path_split = ':' if sys.platform != 'win32' else ';'
    paths = path.split(path_split)
    extlist = ['']

    def is_executable(path):
        return os.path.isfile(path) and os.access(path, os.X_OK)

    if sys.platform == 'win32':
        pathext = os.environ['PATHEXT'].lower().split(os.pathsep)
        (base, ext) = os.path.splitext(exe)
        if ext.lower() not in pathext:
            extlist = pathext
    for ext in extlist:
        exe_name = exe + ext
        for p in paths:
            exe_path = os.path.join(p, exe_name)
            if is_executable(exe_path):
                # Remove any symlinks
                return os.path.realpath(exe_path) if resolve_symlinks else os.path.abspath(exe_path)

    return None