def test_is_exe(temporary_working_dir): # type: (str) -> None touch("all_exe") chmod_plus_x("all_exe") assert is_exe("all_exe") touch("other_exe") os.chmod("other_exe", 0o665) assert not is_exe("other_exe") touch("not_exe") assert not is_exe("not_exe") os.mkdir("exe_dir") chmod_plus_x("exe_dir") assert not is_exe("exe_dir")
def iter_base_candidate_binary_paths(interpreter): # type: (PythonInterpreter) -> Iterator[str] bin_dir = os.path.join(interpreter._identity.base_prefix, "bin") for candidate_binary in candidate_binaries: candidate_binary_path = os.path.join(bin_dir, candidate_binary) if is_exe(candidate_binary_path): yield candidate_binary_path
def python( self, pyenv_version, # type: str binary_name=None, # type: Optional[str] ): # type: (...) -> Optional[str] """Return the path of the python binary for the given pyenv version. Returns `None` if the given pyenv version is not installed. """ # N.B.: Pyenv creates a 'python' symlink for both the CPython and PyPy versions it installs; # so counting on 'python' is OK here. We do resolve the symlink though to return a canonical # direct path to the python binary. binary_name = binary_name or "python" python = os.path.realpath( os.path.join(self.root, "versions", pyenv_version, "bin", binary_name) ) return python if is_exe(python) else None
def find(cls): # type: () -> Optional[Pyenv] """Finds the active pyenv installation if any.""" with TRACER.timed("Searching for pyenv root...", V=3): pyenv_root = os.environ.get("PYENV_ROOT", "") if not pyenv_root: for path_entry in os.environ.get("PATH", "").split(os.pathsep): pyenv_exe = os.path.join(path_entry, "pyenv") if is_exe(pyenv_exe): process = subprocess.Popen(args=[pyenv_exe, "root"], stdout=subprocess.PIPE) stdout, _ = process.communicate() if process.returncode == 0: pyenv_root = str(stdout).strip() break if pyenv_root: pyenv = cls(pyenv_root) TRACER.log("A pyenv installation was found: {}".format(pyenv), V=6) return pyenv TRACER.log("No pyenv installation was found.", V=6) return None
def _iter_executables(directory): # type: (str) -> Iterator[str] for entry in os.listdir(directory): path = os.path.join(directory, entry) if is_exe(path): yield path
def iter_executables(self): # type: () -> Iterator[str] for path in _iter_files(self._bin_dir): if is_exe(path): yield path