MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / getInterpreterInfo

Function getInterpreterInfo

src/test/interpreters/index.node.ts:35–74  ·  view source on GitHub ↗
(pythonPath: Uri | undefined)

Source from the content-addressed store, hash-verified

33
34const interpreterInfoCache = new Map<string, Promise<PythonEnvironment | undefined>>();
35export 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
76const envVariables = new Map<string, Promise<NodeJS.ProcessEnv | undefined>>();
77export async function getActivatedEnvVariables(pythonPath: Uri): Promise<NodeJS.ProcessEnv | undefined> {

Callers

nothing calls this directly

Calls 12

shellExecMethod · 0.95
fileToCommandArgumentFunction · 0.90
parsePythonVersionFunction · 0.90
getPythonCliFunction · 0.85
joinMethod · 0.80
hasMethod · 0.65
getMethod · 0.65
errorMethod · 0.65
parseMethod · 0.65
setMethod · 0.65
replaceMethod · 0.45
fileMethod · 0.45

Tested by

no test coverage detected