Search for file give in "executable". If it is not found, we try the environment PATH.
        Returns either the absolute path to the found executable, or None if the executable
        couldn't be found.
771332
def _search_for_executable(self, executable):
        
        if os.path.isfile(executable):
            return os.path.abspath(executable)
        else:
            envpath = os.getenv('PATH')
            if envpath is None:
                return
            for path in envpath.split(os.pathsep):
                exe = os.path.join(path, executable)
                if os.path.isfile(exe):
                    return os.path.abspath(exe)
932640
def find_windows_executable(bin_path, exe_name):
    """"""
    requested_path = get_windows_path(bin_path, exe_name)
    if os.path.isfile(requested_path):
        return requested_path

    try:
        pathext = os.environ["PATHEXT"]
    except KeyError:
        pass
    else:
        for ext in pathext.split(os.pathsep):
            path = get_windows_path(bin_path, exe_name + ext.strip().lower())
            if os.path.isfile(path):
                return path

    return find_executable(exe_name)
350451
def get_absolute_tool_path(command):
    
    assert isinstance(command, basestring)
    if os.path.dirname(command):
        return os.path.dirname(command)
    else:
        programs = path.programs_path()
        m = path.glob(programs, [command, command + '.exe' ])
        if not len(m):
            if __debug_configuration:
                print "Could not find:", command, "in", programs
            return None
        return os.path.dirname(m[0])
91029
def scan_path(executable="mongod"):
    
    for path in os.environ.get("PATH", "").split(":"):
        path = os.path.abspath(path)
        executable_path = os.path.join(path, executable)
        if os.path.exists(executable_path):
            return executable_path
175236
def _find_path(self, search_dirs, file_name):
        
        for dir_path in search_dirs:
            file_path = os.path.join(dir_path, file_name)
            if os.path.exists(file_path):
                return file_path

        return None
1215100
def which(filename, interactive=False, verbose=False):
    
    exe = [e.lower() for e in os.environ.get('PATHEXT', '').split(';')]
    if sys.platform != 'win32':  # pragma: nocover
        exe.append('')

    name, ext = os.path.splitext(filename)
    has_extension = bool(ext)
    if has_extension and ext.lower() not in exe:
        raise ValueError("which can only search for executable files")

    def match(filenames):
        """Returns the sorted subset of ``filenames`` that matches ``filename``.
        """
        res = set()
        for fname in filenames:
            if fname == filename:  # pragma: nocover
                res.add(fname)  # exact match
                continue
            fname_name, fname_ext = os.path.splitext(fname)
            if fname_name == name and fname_ext.lower() in exe: # pragma: nocover
                res.add(fname)
        return sorted(res)

    returnset = set()
    found = False
    for pth in get_path_directories():
        if verbose:  # pragma: nocover
            print('checking pth..')

        fnames = _listdir(pth, exe)
        if not fnames:
            continue

        for m in match(fnames):
            found_file = _normalize(os.path.join(pth, m))
            if found_file not in returnset:  # pragma: nocover
                if is_executable(found_file):
                    yield found_file
                returnset.add(found_file)
        found = True

    if not found and interactive:  # pragma: nocover
        print("Couldn't find %r anywhere on the path.." % filename)
        sys.exit(1)
1176070
def __find_executables(path):
    

    success = False
    progs = {
        "dot": "",
        "twopi": "",
        "neato": "",
        "circo": "",
        "fdp": "",
        "sfdp": "",
    }

    was_quoted = False
    path = path.strip()
    if path.startswith('"') and path.endswith('"'):
        path = path[1:-1]
        was_quoted = True

    if not os.path.isdir(path):
        return None

    for prg in progs:
        if progs[prg]:
            continue

        prg_path = os.path.join(path, prg)
        prg_exe_path = prg_path + ".exe"

        if os.path.exists(prg_path):
            if was_quoted:
                prg_path = "\"{}\"".format(prg_path)
            progs[prg] = prg_path
            success = True

        elif os.path.exists(prg_exe_path):
            if was_quoted:
                prg_exe_path = "\"{}\"".format(prg_exe_path)
            progs[prg] = prg_exe_path
            success = True

    if success:
        return progs

    return None
847264
def rel_path(*file_path):
        '''
        
        '''
        if hasattr(sys, 'frozen'):
            if file_path[0] == '__file__':
                return sys.executable
            return os.path.join(os.path.dirname(sys.executable), *file_path)
        else:
            try:
                main_file = AppBuilder.main_file
            except AttributeError:
                # The first call setting up the instance
                main_file = inspect.stack()[1][1]
            if file_path[0] == '__file__':
                return os.path.realpath(main_file)
            return os.path.join(os.path.dirname(main_file), *file_path)
385793
def find_dotenv(filename='.env', raise_error_if_not_found=False, usecwd=False):
    
    if usecwd or '__file__' not in globals():
        # should work without __file__, e.g. in REPL or IPython notebook
        path = os.getcwd()
    else:
        # will work for .py files
        frame_filename = sys._getframe().f_back.f_code.co_filename
        path = os.path.dirname(os.path.abspath(frame_filename))

    for dirname in _walk_to_root(path):
        check_path = os.path.join(dirname, filename)
        if os.path.exists(check_path):
            return check_path

    if raise_error_if_not_found:
        raise IOError('File not found')

    return ''
662720
def which(program):
    
    def is_exe(fpath):
        found = os.path.isfile(fpath) and os.access(fpath, os.X_OK)
        if not found and sys.platform == 'win32':
            fpath = fpath + ".exe"
            found = os.path.isfile(fpath) and os.access(fpath, os.X_OK)
        return found

    fpath, _ = os.path.split(program)
    if fpath:
        if is_exe(program):
            logger.debug("found executable: " + str(program))
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = os.path.expandvars(os.path.expanduser(path)).strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                logger.debug("found executable in path: " + str(exe_file))
                return exe_file

    return None
1003641
def find_executable(name: str, flags=os.X_OK) -> List[str]:
    
    """
    result = []
    extensions = [x for x in os.environ.get("PATHEXT", "").split(os.pathsep) if x]
    path = os.environ.get("PATH", None)
    if path is None:
        return []
    for path in os.environ.get("PATH", "").split(os.pathsep):
        path = os.path.join(path, name)
        if os.access(path, flags):
            result.append(path)
        for extension in extensions:
            path_extension = path + extension
            if os.access(path_extension, flags):
                result.append(path_extension)
    return result
317029
def which(exe_name):
    
    def is_exe(file_path_name):
        return os.path.isfile(file_path_name) and os.access(file_path_name, os.X_OK)

    is_platform_windows = (platform.system() == 'Windows')

    fpath, _fname = os.path.split(exe_name)
    if fpath:
        if is_exe(exe_name):
            return exe_name
    else:
        for path in os.environ['PATH'].split(os.pathsep):
            exe_file_path_name = os.path.join(path, exe_name)
            if is_exe(exe_file_path_name):
                return exe_file_path_name

            if is_platform_windows:
                windows_exe_file_path_name = '%s.exe' % exe_file_path_name
                if is_exe(windows_exe_file_path_name):
                    return windows_exe_file_path_name

                windows_com_file_path_name = '%s.exe' % exe_file_path_name
                if is_exe(windows_com_file_path_name):
                    return windows_com_file_path_name

    return None
1254266
def check_file_path(self, path):
        
        if os.path.exists(path) is not True:
            msg = "File Not Found {}".format(path)
            raise OSError(msg)
383229
def _get_abs_filepath(self, ifile):
        
        assert ifile is not None
        ifile = ifile[7:] if ifile.startswith('file://') else ifile
        if ifile[0] != '/':
            basedir = os.path.abspath(os.path.dirname(self.config_file))
            ifile = os.path.join(basedir, ifile)
        return 'file://' + ifile
490178
def get_absolute_path(some_path):
    
    if os.path.isabs(some_path):
        return some_path
    else:
        return evaluate_relative_path(os.getcwd(), some_path)
393068
def find_exe(env_dir, name):
    """"""

    if platform.system() == "Windows":
        name = name + ".exe"

    # find the binary
    exe_name = os.path.join(env_dir, name)
    if not os.path.exists(exe_name):
        exe_name = os.path.join(env_dir, "bin", name)
        if not os.path.exists(exe_name):
            exe_name = os.path.join(env_dir, "Scripts", name)
            if not os.path.exists(exe_name):
                return None
    return exe_name
1025258
def find_project_file(start_dir, basename):
    ''''''
    prefix = os.path.abspath(start_dir)
    while True:
        candidate = os.path.join(prefix, basename)
        if os.path.isfile(candidate):
            return candidate
        if os.path.exists(candidate):
            raise PrintableError(
                "Found {}, but it's not a file.".format(candidate))
        if os.path.dirname(prefix) == prefix:
            # We've walked all the way to the top. Bail.
            raise PrintableError("Can't find " + basename)
        # Not found at this level. We must go...shallower.
        prefix = os.path.dirname(prefix)