forked from microsoft/vscode-python-debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.ts
More file actions
72 lines (70 loc) · 2.34 KB
/
helpers.ts
File metadata and controls
72 lines (70 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Uri } from 'vscode';
import { PythonEnvironment } from '../../../extension/envExtApi';
/**
* Helper to build a simple PythonEnvironment object for tests.
* @param execPath string - path to the python executable
* @param version string - python version string (e.g. '3.9.0')
* @param sysPrefix string - sysPrefix value (optional)
*/
export function buildPythonEnvironment(execPath: string, version: string, sysPrefix: string = ''): PythonEnvironment {
const execUri = Uri.file(execPath);
return {
envId: {
id: execUri.fsPath,
managerId: 'Venv',
},
name: `Python ${version}`,
displayName: `Python ${version}`,
displayPath: execUri.fsPath,
version: version,
environmentPath: execUri,
execInfo: {
run: {
executable: execUri.fsPath,
args: [],
},
},
sysPrefix,
} as PythonEnvironment;
}
/**
* Helper to build a PythonEnvironment where activatedRun differs from run.
* This simulates environment managers like pixi or conda that set activatedRun
* to a wrapper command (e.g. 'pixi run python') while run.executable points to
* the actual Python binary.
*
* @param execPath string - path to the actual python executable (run.executable)
* @param activatedRunExecutable string - path/command for the wrapper (activatedRun.executable)
* @param version string - python version string (e.g. '3.9.0')
* @param activatedRunArgs string[] - optional args for activatedRun
*/
export function buildPythonEnvironmentWithActivatedRun(
execPath: string,
activatedRunExecutable: string,
version: string,
activatedRunArgs: string[] = [],
): PythonEnvironment {
const execUri = Uri.file(execPath);
return {
envId: {
id: execUri.fsPath,
managerId: 'Venv',
},
name: `Python ${version}`,
displayName: `Python ${version}`,
displayPath: execUri.fsPath,
version: version,
environmentPath: execUri,
execInfo: {
run: {
executable: execUri.fsPath,
args: [],
},
activatedRun: {
executable: activatedRunExecutable,
args: activatedRunArgs,
},
},
sysPrefix: '',
} as PythonEnvironment;
}