(pythonPath: Uri | undefined)
| 33 | |
| 34 | const interpreterInfoCache = new Map<string, Promise<PythonEnvironment | undefined>>(); |
| 35 | export async function getInterpreterInfo(pythonPath: Uri | undefined): Promise<PythonEnvironment | undefined> { |
| 36 | if (!pythonPath) { |
| 37 | return undefined; |
| 38 | } |
| 39 | const key = getComparisonKey(pythonPath); |
| 40 | if (interpreterInfoCache.has(key)) { |
| 41 | return interpreterInfoCache.get(key); |
| 42 | } |
| 43 | |
| 44 | const promise = (async () => { |
| 45 | try { |
| 46 | const cli = await getPythonCli(pythonPath); |
| 47 | const processService = new ProcessService(); |
| 48 | const argv = [...cli, fileToCommandArgument(path.join(SCRIPTS_DIR, 'interpreterInfo.py'))]; |
| 49 | const cmd = argv.reduce((p, c) => (p ? `${p} "${c}"` : `"${c.replace('\\', '/')}"`), ''); // CodeQL [SM02383] Replace just the first occurrence of \\ as this could be a UNC path. |
| 50 | const result = await processService.shellExec(cmd, { |
| 51 | timeout: executionTimeout, |
| 52 | env: process.env, |
| 53 | shell: defaultShell |
| 54 | }); |
| 55 | if (result.stderr && result.stderr.length) { |
| 56 | logger.error(`Failed to parse interpreter information for ${argv} stderr: ${result.stderr}`); |
| 57 | return; |
| 58 | } |
| 59 | const json: PythonEnvInfo = JSON.parse(result.stdout.trim()); |
| 60 | const rawVersion = `${json.versionInfo.slice(0, 3).join('.')}-${json.versionInfo[3]}`; |
| 61 | return { |
| 62 | id: json.exe, |
| 63 | uri: Uri.file(json.exe), |
| 64 | displayName: `Python${rawVersion}`, |
| 65 | version: parsePythonVersion(rawVersion) |
| 66 | }; |
| 67 | } catch (ex) { |
| 68 | logger.error('Failed to get Activated env Variables: ', ex); |
| 69 | return undefined; |
| 70 | } |
| 71 | })(); |
| 72 | interpreterInfoCache.set(key, promise); |
| 73 | return promise; |
| 74 | } |
| 75 | |
| 76 | const envVariables = new Map<string, Promise<NodeJS.ProcessEnv | undefined>>(); |
| 77 | export async function getActivatedEnvVariables(pythonPath: Uri): Promise<NodeJS.ProcessEnv | undefined> { |
nothing calls this directly
no test coverage detected