( workPath: string, env: NodeJS.ProcessEnv, systemPython: string )
| 15 | } |
| 16 | |
| 17 | export function useVirtualEnv( |
| 18 | workPath: string, |
| 19 | env: NodeJS.ProcessEnv, |
| 20 | systemPython: string |
| 21 | ): { pythonCmd: string; venvRoot?: string } { |
| 22 | const venvDirs = ['.venv', 'venv']; |
| 23 | let pythonCmd = systemPython; |
| 24 | for (const venv of venvDirs) { |
| 25 | const venvRoot = join(workPath, venv); |
| 26 | const binDir = |
| 27 | process.platform === 'win32' |
| 28 | ? join(venvRoot, 'Scripts') |
| 29 | : join(venvRoot, 'bin'); |
| 30 | const candidates = |
| 31 | process.platform === 'win32' |
| 32 | ? [join(binDir, 'python.exe'), join(binDir, 'python')] |
| 33 | : [join(binDir, 'python3'), join(binDir, 'python')]; |
| 34 | const found = candidates.find(p => fs.existsSync(p)); |
| 35 | if (found) { |
| 36 | pythonCmd = found; |
| 37 | env.VIRTUAL_ENV = venvRoot; |
| 38 | env.PATH = `${binDir}${pathDelimiter}${env.PATH || ''}`; |
| 39 | return { pythonCmd, venvRoot }; |
| 40 | } |
| 41 | } |
| 42 | return { pythonCmd }; |
| 43 | } |
| 44 | |
| 45 | export function createVenvEnv( |
| 46 | venvPath: string, |
no test coverage detected