Skip to content

Commit eff506f

Browse files
committed
API update
1 parent b902b82 commit eff506f

File tree

1 file changed

+151
-36
lines changed

1 file changed

+151
-36
lines changed

src/client/envExt/types.ts

Lines changed: 151 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Terminal,
1212
TaskExecution,
1313
TerminalOptions,
14+
FileChangeType,
1415
} from 'vscode';
1516

1617
/**
@@ -240,7 +241,7 @@ export type RefreshEnvironmentsScope = Uri | undefined;
240241

241242
/**
242243
* The scope for which environments are required.
243-
* - `undefined`/`"all"`: All environments.
244+
* - `"all"`: All environments.
244245
* - `"global"`: Python installations that are usually a base for creating virtual environments.
245246
* - {@link Uri}: Environments for the workspace/folder/file pointed to by the Uri.
246247
*/
@@ -296,23 +297,6 @@ export type DidChangeEnvironmentsEventArgs = {
296297
environment: PythonEnvironment;
297298
}[];
298299

299-
export type PythonIsKnownContext = Uri | string;
300-
301-
/**
302-
* Result of checking if a context is a known Python environment.
303-
*/
304-
export interface PythonIsKnownResult {
305-
/**
306-
* The confidence level of the result (low, moderate, or high).
307-
*/
308-
confidence: 'low' | 'moderate' | 'high';
309-
310-
/**
311-
* The Python environment match.
312-
*/
313-
result: 'unknown' | 'known' | 'canHandle';
314-
}
315-
316300
/**
317301
* Type representing the context for resolving a Python environment.
318302
*/
@@ -334,7 +318,9 @@ export interface EnvironmentManager {
334318

335319
/**
336320
* The preferred package manager ID for the environment manager.
337-
* @example 'ms-python.python:pip'
321+
*
322+
* @example
323+
* 'ms-python.python:pip'
338324
*/
339325
readonly preferredPackageManagerId: string;
340326

@@ -425,15 +411,6 @@ export interface EnvironmentManager {
425411
*/
426412
resolve(context: ResolveEnvironmentContext): Promise<PythonEnvironment | undefined>;
427413

428-
/**
429-
* Checks if the specified context is a known Python environment. The string/Uri can point to the environment root folder
430-
* or to python executable. It can also be a named environment.
431-
*
432-
* @param context - The URI/string context to check.
433-
* @returns A promise that resolves to the result of the check.
434-
*/
435-
isKnown?(context: PythonIsKnownContext): Promise<PythonIsKnownResult>;
436-
437414
/**
438415
* Clears the environment manager's cache.
439416
*
@@ -579,7 +556,7 @@ export interface PackageManager {
579556
/**
580557
* The log output channel for the package manager.
581558
*/
582-
logOutput?: LogOutputChannel;
559+
log?: LogOutputChannel;
583560

584561
/**
585562
* Installs packages in the specified Python environment.
@@ -617,9 +594,8 @@ export interface PackageManager {
617594
* @param environment The Python environment for which to get installable items.
618595
*
619596
* Note: An environment can be used by multiple projects, so the installable items returned.
620-
* should be for the environment. IF you want to do it for a particular project, then you may
621-
* shown a QuickPick to the user to select the project, and filter the installable items based
622-
* on the project.
597+
* should be for the environment. If you want to do it for a particular project, then you should
598+
* ask user to select a project, and filter the installable items based on the project.
623599
*/
624600
getInstallable?(environment: PythonEnvironment): Promise<Installable[]>;
625601

@@ -768,7 +744,8 @@ export interface Installable {
768744
readonly group?: string;
769745

770746
/**
771-
* Path to the requirements, version of the package, or any other project file path.
747+
* Description about the installable item. This can also be path to the requirements,
748+
* version of the package, or any other project file path.
772749
*/
773750
readonly description?: string;
774751

@@ -1048,17 +1025,70 @@ export interface PythonTerminalOptions extends TerminalOptions {
10481025
}
10491026

10501027
export interface PythonTerminalCreateApi {
1028+
/**
1029+
* Creates a terminal and activates any (activatable) environment for the terminal.
1030+
*
1031+
* @param environment The Python environment to activate.
1032+
* @param options Options for creating the terminal.
1033+
*
1034+
* Note: Non-activatable environments have no effect on the terminal.
1035+
*/
10511036
createTerminal(environment: PythonEnvironment, options: PythonTerminalOptions): Promise<Terminal>;
10521037
}
10531038

1039+
/**
1040+
* Options for running a Python script or module in a terminal.
1041+
*
1042+
* Example:
1043+
* * Running Script: `python myscript.py --arg1`
1044+
* ```typescript
1045+
* {
1046+
* args: ["myscript.py", "--arg1"]
1047+
* }
1048+
* ```
1049+
* * Running a module: `python -m my_module --arg1`
1050+
* ```typescript
1051+
* {
1052+
* args: ["-m", "my_module", "--arg1"]
1053+
* }
1054+
* ```
1055+
*/
10541056
export interface PythonTerminalExecutionOptions {
1057+
/**
1058+
* Current working directory for the terminal. This in only used to create the terminal.
1059+
*/
10551060
cwd: string | Uri;
1061+
1062+
/**
1063+
* Arguments to pass to the python executable.
1064+
*/
10561065
args?: string[];
1066+
1067+
/**
1068+
* Set `true` to show the terminal.
1069+
*/
10571070
show?: boolean;
10581071
}
10591072

10601073
export interface PythonTerminalRunApi {
1074+
/**
1075+
* Runs a Python script or module in a terminal. This API will create a terminal if one is not available to use.
1076+
* If a terminal is available, it will be used to run the script or module.
1077+
*
1078+
* Note:
1079+
* - If you restart VS Code, this will create a new terminal, this is a limitation of VS Code.
1080+
* - If you close the terminal, this will create a new terminal.
1081+
* - In cases of multi-root/project scenario, it will create a separate terminal for each project.
1082+
*/
10611083
runInTerminal(environment: PythonEnvironment, options: PythonTerminalExecutionOptions): Promise<Terminal>;
1084+
1085+
/**
1086+
* Runs a Python script or module in a dedicated terminal. This API will create a terminal if one is not available to use.
1087+
* If a terminal is available, it will be used to run the script or module. This terminal will be dedicated to the script,
1088+
* and selected based on the `terminalKey`.
1089+
*
1090+
* @param terminalKey A unique key to identify the terminal. For scripts you can use the Uri of the script file.
1091+
*/
10621092
runInDedicatedTerminal(
10631093
terminalKey: Uri | string,
10641094
environment: PythonEnvironment,
@@ -1067,6 +1097,7 @@ export interface PythonTerminalRunApi {
10671097
}
10681098

10691099
/**
1100+
* Options for running a Python task.
10701101
*
10711102
* Example:
10721103
* * Running Script: `python myscript.py --arg1`
@@ -1083,23 +1114,63 @@ export interface PythonTerminalRunApi {
10831114
* ```
10841115
*/
10851116
export interface PythonTaskExecutionOptions {
1086-
project?: PythonProject;
1117+
/**
1118+
* Name of the task to run.
1119+
*/
1120+
name: string;
1121+
1122+
/**
1123+
* Arguments to pass to the python executable.
1124+
*/
10871125
args: string[];
1126+
1127+
/**
1128+
* The Python project to use for the task.
1129+
*/
1130+
project?: PythonProject;
1131+
1132+
/**
1133+
* Current working directory for the task. Default is the project directory for the script being run.
1134+
*/
10881135
cwd?: string;
1136+
1137+
/**
1138+
* Environment variables to set for the task.
1139+
*/
10891140
env?: { [key: string]: string };
1090-
name: string;
10911141
}
10921142

10931143
export interface PythonTaskRunApi {
1144+
/**
1145+
* Run a Python script or module as a task.
1146+
*
1147+
*/
10941148
runAsTask(environment: PythonEnvironment, options: PythonTaskExecutionOptions): Promise<TaskExecution>;
10951149
}
10961150

1151+
/**
1152+
* Options for running a Python script or module in the background.
1153+
*/
10971154
export interface PythonBackgroundRunOptions {
1155+
/**
1156+
* The Python environment to use for running the script or module.
1157+
*/
10981158
args: string[];
1159+
1160+
/**
1161+
* Current working directory for the script or module. Default is the project directory for the script being run.
1162+
*/
10991163
cwd?: string;
1164+
1165+
/**
1166+
* Environment variables to set for the script or module.
1167+
*/
11001168
env?: { [key: string]: string | undefined };
11011169
}
11021170
export interface PythonBackgroundRunApi {
1171+
/**
1172+
* Run a Python script or module in the background. This API will create a new process to run the script or module.
1173+
*/
11031174
runInBackground(environment: PythonEnvironment, options: PythonBackgroundRunOptions): Promise<PythonProcess>;
11041175
}
11051176

@@ -1108,11 +1179,55 @@ export interface PythonExecutionApi
11081179
PythonTerminalRunApi,
11091180
PythonTaskRunApi,
11101181
PythonBackgroundRunApi {}
1182+
1183+
/**
1184+
* Event arguments for when the monitored `.env` files or any other sources change.
1185+
*/
1186+
export interface DidChangeEnvironmentVariablesEventArgs {
1187+
/**
1188+
* The URI of the file that changed. No `Uri` means a non-file source of environment variables changed.
1189+
*/
1190+
uri?: Uri;
1191+
1192+
/**
1193+
* The type of change that occurred.
1194+
*/
1195+
changeTye: FileChangeType;
1196+
}
1197+
1198+
export interface PythonEnvironmentVariablesApi {
1199+
/**
1200+
* Get environment variables for a workspace. This picks up `.env` file from the root of the
1201+
* workspace.
1202+
*
1203+
* Order of overrides:
1204+
* 1. `baseEnvVar` if given or `process.env`
1205+
* 2. `.env` file from the "python.envFile" setting in the workspace.
1206+
* 3. `.env` file at the root of the python project.
1207+
* 4. `overrides` in the order provided.
1208+
*
1209+
* @param uri The URI of the project, workspace or a file in a for which environment variables are required.
1210+
* @param overrides Additional environment variables to override the defaults.
1211+
* @param baseEnvVar The base environment variables that should be used as a starting point.
1212+
*/
1213+
getEnvironmentVariables(
1214+
uri: Uri,
1215+
overrides?: ({ [key: string]: string | undefined } | Uri)[],
1216+
baseEnvVar?: { [key: string]: string | undefined },
1217+
): Promise<{ [key: string]: string | undefined }>;
1218+
1219+
/**
1220+
* Event raised when `.env` file changes or any other monitored source of env variable changes.
1221+
*/
1222+
onDidChangeEnvironmentVariables: Event<DidChangeEnvironmentVariablesEventArgs>;
1223+
}
1224+
11111225
/**
11121226
* The API for interacting with Python environments, package managers, and projects.
11131227
*/
11141228
export interface PythonEnvironmentApi
11151229
extends PythonEnvironmentManagerApi,
11161230
PythonPackageManagerApi,
11171231
PythonProjectApi,
1118-
PythonExecutionApi {}
1232+
PythonExecutionApi,
1233+
PythonEnvironmentVariablesApi {}

0 commit comments

Comments
 (0)