| 695 | |
| 696 | @attr.s(frozen=True) |
| 697 | class PyenvPythonDistribution(PythonDistribution): |
| 698 | pyenv_root = attr.ib() # type: str |
| 699 | _pyenv_script = attr.ib() # type: str |
| 700 | |
| 701 | def pyenv_env(self, **extra_env): |
| 702 | # type: (**str) -> Dict[str, str] |
| 703 | env = os.environ.copy() |
| 704 | env.update(extra_env) |
| 705 | env["PYENV_ROOT"] = self.pyenv_root |
| 706 | env["PATH"] = os.pathsep.join( |
| 707 | [os.path.join(self.pyenv_root, path) for path in ("bin", "shims")] |
| 708 | + os.getenv("PATH", os.defpath).split(os.pathsep) |
| 709 | ) |
| 710 | return env |
| 711 | |
| 712 | def run_pyenv( |
| 713 | self, |
| 714 | args, # type: Iterable[str] |
| 715 | **popen_kwargs # type: Any |
| 716 | ): |
| 717 | # type: (...) -> Text |
| 718 | return cast( |
| 719 | "Text", |
| 720 | subprocess.check_output( |
| 721 | args=[self._pyenv_script] + list(args), |
| 722 | env=self.pyenv_env(**popen_kwargs.pop("env", {})), |
| 723 | **popen_kwargs |
| 724 | ).decode("utf-8"), |
| 725 | ) |
| 726 | |
| 727 | |
| 728 | def ensure_python_distribution( |
no outgoing calls
no test coverage detected
searching dependent graphs…