| 103 | return self._site_packages[self.python_path] |
| 104 | |
| 105 | def create(self, pip_args: list[str], verbose: bool = False) -> None: |
| 106 | if not self.is_valid: |
| 107 | with animate("creating shared libraries", not verbose): |
| 108 | create_process = run_subprocess( |
| 109 | [DEFAULT_PYTHON, "-m", "venv", "--clear", self.root], run_dir=str(self.root) |
| 110 | ) |
| 111 | subprocess_post_check(create_process) |
| 112 | |
| 113 | # ignore installed packages to ensure no unexpected patches from the OS vendor |
| 114 | # are used |
| 115 | pip_args = pip_args or [] |
| 116 | pip_args.append("--force-reinstall") |
| 117 | self.upgrade(pip_args=pip_args, verbose=verbose, raises=True) |
| 118 | |
| 119 | # Remove setuptools from shared libs to prevent it from leaking into |
| 120 | # app venvs via the .pth file. On Python < 3.12, venv bundles setuptools |
| 121 | # via ensurepip, but a 3.10 setuptools breaks when imported under 3.12+ |
| 122 | # because distutils was removed from the stdlib. |
| 123 | run_subprocess( |
| 124 | [self.python_path, "-m", "pip", "--no-input", "uninstall", "-y", "setuptools"], |
| 125 | capture_stderr=False, |
| 126 | ) |
| 127 | |
| 128 | @property |
| 129 | def is_valid(self) -> bool: |