(
version, # type: str
latest_pip=True, # type: bool
system_site_packages=False, # type: bool
tmpdir=None, # type: Optional[Tempdir]
)
| 793 | |
| 794 | |
| 795 | def ensure_python_venv( |
| 796 | version, # type: str |
| 797 | latest_pip=True, # type: bool |
| 798 | system_site_packages=False, # type: bool |
| 799 | tmpdir=None, # type: Optional[Tempdir] |
| 800 | ): |
| 801 | # type: (...) -> Virtualenv |
| 802 | pyenv_distribution = ensure_python_distribution(version) |
| 803 | venv = tmpdir.join("{version}.venv".format(version=version)) if tmpdir else safe_mkdtemp() |
| 804 | if _ALL_PY_VERSIONS_TO_VERSION_INFO[version][0] == 3: |
| 805 | args = [pyenv_distribution.binary, "-m", "venv", venv] |
| 806 | if system_site_packages: |
| 807 | args.append("--system-site-packages") |
| 808 | subprocess.check_call(args=args) |
| 809 | else: |
| 810 | subprocess.check_call(args=[pyenv_distribution.pip, "install", "virtualenv==16.7.10"]) |
| 811 | args = [pyenv_distribution.binary, "-m", "virtualenv", venv, "-q"] |
| 812 | if system_site_packages: |
| 813 | args.append("--system-site-packages") |
| 814 | subprocess.check_call(args=args) |
| 815 | python, pip = tuple(os.path.join(venv, "bin", exe) for exe in ("python", "pip")) |
| 816 | if latest_pip: |
| 817 | subprocess.check_call(args=[pip, "install", "-U", "pip"]) |
| 818 | return Virtualenv(venv) |
| 819 | |
| 820 | |
| 821 | def ensure_python_interpreter(version): |
searching dependent graphs…