Return torch.__version__ from the target venv (sys.executable), or None if torch is absent/unimportable. Cross-platform (unlike probe_torch_wheel_env, which is Linux-only); mirrors the subprocess probe in _ensure_cuda_torch.
()
| 156 | |
| 157 | |
| 158 | def _probe_installed_torch_version() -> str | None: |
| 159 | """Return torch.__version__ from the target venv (sys.executable), or None if |
| 160 | torch is absent/unimportable. Cross-platform (unlike probe_torch_wheel_env, |
| 161 | which is Linux-only); mirrors the subprocess probe in _ensure_cuda_torch. |
| 162 | """ |
| 163 | try: |
| 164 | probe = subprocess.run( |
| 165 | [ |
| 166 | sys.executable, |
| 167 | "-c", |
| 168 | "import torch, sys; sys.stdout.write(getattr(torch, '__version__', ''))", |
| 169 | ], |
| 170 | stdout = subprocess.PIPE, |
| 171 | stderr = subprocess.DEVNULL, |
| 172 | text = True, |
| 173 | timeout = 90, |
| 174 | **_windows_hidden_subprocess_kwargs(), |
| 175 | ) |
| 176 | except (OSError, subprocess.TimeoutExpired): |
| 177 | return None |
| 178 | if probe.returncode != 0: |
| 179 | return None |
| 180 | lines = [line.strip() for line in (probe.stdout or "").splitlines() if line.strip()] |
| 181 | return lines[-1] if lines else None |
| 182 | |
| 183 | |
| 184 | # constraints.txt caps new anyio resolutions at <4.14 (#6483), but an install |
no test coverage detected
searching dependent graphs…