Find the Visual Studio installation path, if it exists.
()
| 201 | |
| 202 | |
| 203 | def find_vs_path() -> pathlib.Path | None: |
| 204 | """Find the Visual Studio installation path, if it exists.""" |
| 205 | if platform.system() != "Windows": |
| 206 | return None |
| 207 | pf86: str = os.environ.get("ProgramFiles(x86)", r"C:\Program Files (x86)") |
| 208 | pf: str = os.environ.get("ProgramFiles", r"C:\Program Files") |
| 209 | try_paths: list[pathlib.Path] = [pathlib.Path(p) / "Microsoft Visual Studio" / "Installer" / "vswhere.exe" for p in [pf86, pf]] |
| 210 | vswhere: pathlib.Path | None = next((p for p in try_paths if p.exists()), None) |
| 211 | if vswhere is None: |
| 212 | return None |
| 213 | try: |
| 214 | install_root: str = subprocess.check_output( |
| 215 | [ |
| 216 | str(vswhere), |
| 217 | "-latest", |
| 218 | "-property", |
| 219 | "installationPath", |
| 220 | ], |
| 221 | text=True, |
| 222 | ).strip() |
| 223 | except subprocess.CalledProcessError: |
| 224 | return None |
| 225 | if install_root == "": |
| 226 | return None |
| 227 | return pathlib.Path(install_root) |
| 228 | |
| 229 | |
| 230 | def get_module_flags(name: str, module_output_path: pathlib.Path) -> list[str]: |