(prefix: Prefix, version: str)
| 173 | |
| 174 | |
| 175 | def health_check(prefix: Prefix, version: str) -> str | None: |
| 176 | envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version) |
| 177 | pyvenv_cfg = os.path.join(envdir, 'pyvenv.cfg') |
| 178 | |
| 179 | # created with "old" virtualenv |
| 180 | if not os.path.exists(pyvenv_cfg): |
| 181 | return 'pyvenv.cfg does not exist (old virtualenv?)' |
| 182 | |
| 183 | exe_name = win_exe('python') |
| 184 | py_exe = prefix.path(bin_dir(envdir), exe_name) |
| 185 | cfg = _read_pyvenv_cfg(pyvenv_cfg) |
| 186 | |
| 187 | if 'version_info' not in cfg: |
| 188 | return "created virtualenv's pyvenv.cfg is missing `version_info`" |
| 189 | |
| 190 | # always use uncached lookup here in case we replaced an unhealthy env |
| 191 | virtualenv_version = _version_info.__wrapped__(py_exe) |
| 192 | if virtualenv_version != cfg['version_info']: |
| 193 | return ( |
| 194 | f'virtualenv python version did not match created version:\n' |
| 195 | f'- actual version: {virtualenv_version}\n' |
| 196 | f'- expected version: {cfg["version_info"]}\n' |
| 197 | ) |
| 198 | |
| 199 | # made with an older version of virtualenv? skip `base-executable` check |
| 200 | if 'base-executable' not in cfg: |
| 201 | return None |
| 202 | |
| 203 | base_exe_version = _version_info(cfg['base-executable']) |
| 204 | if base_exe_version != cfg['version_info']: |
| 205 | return ( |
| 206 | f'base executable python version does not match created version:\n' |
| 207 | f'- base-executable version: {base_exe_version}\n' |
| 208 | f'- expected version: {cfg["version_info"]}\n' |
| 209 | ) |
| 210 | else: |
| 211 | return None |
| 212 | |
| 213 | |
| 214 | def install_environment( |
nothing calls this directly
no test coverage detected