forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
151 lines (121 loc) · 4.73 KB
/
index.ts
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as path from 'path';
import { _SCRIPTS_DIR } from './constants';
const SCRIPTS_DIR = _SCRIPTS_DIR;
// "scripts" contains everything relevant to the scripts found under
// the top-level "pythonFiles" directory. Each of those scripts has
// a function in this module which matches the script's filename.
// Each function provides the commandline arguments that should be
// used when invoking a Python executable, whether through spawn/exec
// or a terminal.
//
// Where relevant (nearly always), the function also returns a "parse"
// function that may be used to deserialize the stdout of the script
// into the corresponding object or objects. "parse()" takes a single
// string as the stdout text and returns the relevant data.
//
// Some of the scripts are located in subdirectories of "pythonFiles".
// For each of those subdirectories there is a sub-module where
// those scripts' functions may be found.
//
// In some cases one or more types related to a script are exported
// from the same module in which the script's function is located.
// These types typically relate to the return type of "parse()".
//
// ignored scripts:
// * install_debugpy.py (used only for extension development)
export * as testingTools from './testing_tools';
// interpreterInfo.py
type ReleaseLevel = 'alpha' | 'beta' | 'candidate' | 'final';
type PythonVersionInfo = [number, number, number, ReleaseLevel, number];
export type InterpreterInfoJson = {
versionInfo: PythonVersionInfo;
sysPrefix: string;
sysVersion: string;
is64Bit: boolean;
};
export const OUTPUT_MARKER_SCRIPT = path.join(_SCRIPTS_DIR, 'get_output_via_markers.py');
export function interpreterInfo(): [string[], (out: string) => InterpreterInfoJson] {
const script = path.join(SCRIPTS_DIR, 'interpreterInfo.py');
const args = [script];
function parse(out: string): InterpreterInfoJson {
try {
return JSON.parse(out);
} catch (ex) {
throw Error(`python ${args} returned bad JSON (${out}) (${ex})`);
}
}
return [args, parse];
}
// normalizeSelection.py
export function normalizeSelection(): [string[], (out: string) => string] {
const script = path.join(SCRIPTS_DIR, 'normalizeSelection.py');
const args = [script];
function parse(out: string) {
// The text will be used as-is.
return out;
}
return [args, parse];
}
// printEnvVariables.py
export function printEnvVariables(): [string[], (out: string) => NodeJS.ProcessEnv] {
const script = path.join(SCRIPTS_DIR, 'printEnvVariables.py').fileToCommandArgumentForPythonExt();
const args = [script];
function parse(out: string): NodeJS.ProcessEnv {
return JSON.parse(out);
}
return [args, parse];
}
// shell_exec.py
// eslint-disable-next-line camelcase
export function shell_exec(command: string, lockfile: string, shellArgs: string[]): string[] {
const script = path.join(SCRIPTS_DIR, 'shell_exec.py');
// We don't bother with a "parse" function since the output
// could be anything.
return [
script,
command.fileToCommandArgumentForPythonExt(),
// The shell args must come after the command
// but before the lockfile.
...shellArgs,
lockfile.fileToCommandArgumentForPythonExt(),
];
}
// testlauncher.py
export function testlauncher(testArgs: string[]): string[] {
const script = path.join(SCRIPTS_DIR, 'testlauncher.py');
// There is no output to parse, so we do not return a function.
return [script, ...testArgs];
}
// visualstudio_py_testlauncher.py
// eslint-disable-next-line camelcase
export function visualstudio_py_testlauncher(testArgs: string[]): string[] {
const script = path.join(SCRIPTS_DIR, 'visualstudio_py_testlauncher.py');
// There is no output to parse, so we do not return a function.
return [script, ...testArgs];
}
// execution.py
// eslint-disable-next-line camelcase
export function execution_py_testlauncher(testArgs: string[]): string[] {
const script = path.join(SCRIPTS_DIR, 'unittestadapter', 'execution.py');
return [script, ...testArgs];
}
// tensorboard_launcher.py
export function tensorboardLauncher(args: string[]): string[] {
const script = path.join(SCRIPTS_DIR, 'tensorboard_launcher.py');
return [script, ...args];
}
// linter.py
export function linterScript(): string {
const script = path.join(SCRIPTS_DIR, 'linter.py');
return script;
}
export function createVenvScript(): string {
const script = path.join(SCRIPTS_DIR, 'create_venv.py');
return script;
}
export function createCondaScript(): string {
const script = path.join(SCRIPTS_DIR, 'create_conda.py');
return script;
}