* Try to find Python using Windows 'where' command, filtering out Microsoft Store stubs.
()
| 65 | * Try to find Python using Windows 'where' command, filtering out Microsoft Store stubs. |
| 66 | */ |
| 67 | async function tryWindowsWhere(): Promise<string | null> { |
| 68 | try { |
| 69 | const result = await execFileAsync('where', ['python']); |
| 70 | const output = result.stdout.trim(); |
| 71 | |
| 72 | // Handle empty output |
| 73 | if (!output) { |
| 74 | logger.debug("Windows 'where python' returned empty output"); |
| 75 | return null; |
| 76 | } |
| 77 | |
| 78 | const paths = output.split('\n').filter((path) => path.trim()); |
| 79 | |
| 80 | for (const pythonPath of paths) { |
| 81 | const trimmedPath = pythonPath.trim(); |
| 82 | |
| 83 | // Skip Microsoft Store stubs and non-executables |
| 84 | if (trimmedPath.includes('WindowsApps') || !trimmedPath.endsWith('.exe')) { |
| 85 | continue; |
| 86 | } |
| 87 | |
| 88 | const validated = await tryPath(trimmedPath); |
| 89 | if (validated) { |
| 90 | return validated; |
| 91 | } |
| 92 | } |
| 93 | } catch (error) { |
| 94 | const errorMsg = error instanceof Error ? error.message : String(error); |
| 95 | logger.debug(`Windows 'where python' failed: ${errorMsg}`); |
| 96 | |
| 97 | // Log permission/access errors differently |
| 98 | if (errorMsg.includes('Access is denied') || errorMsg.includes('EACCES')) { |
| 99 | logger.warn(`Permission denied when searching for Python: ${errorMsg}`); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | return null; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Try Python commands to get sys.executable path. |
no test coverage detected
searching dependent graphs…