* Parse the `version` field from a pyvenv.cfg file and return the * "major.minor" string. Returns null if the file * cannot be read or the version line is missing.
( pyvenvCfgPath: string )
| 65 | * cannot be read or the version line is missing. |
| 66 | */ |
| 67 | async function readVenvPythonVersion( |
| 68 | pyvenvCfgPath: string |
| 69 | ): Promise<string | null> { |
| 70 | try { |
| 71 | const content = await fs.promises.readFile(pyvenvCfgPath, 'utf-8'); |
| 72 | const match = content.match(/^version\s*=\s*(\d+)\.(\d+)/m); |
| 73 | return match ? `${match[1]}.${match[2]}` : null; |
| 74 | } catch { |
| 75 | return null; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | export async function ensureVenv({ |
| 80 | pythonVersion, |