Skip to content

Commit 069159c

Browse files
committed
fix: make create environment options an optional argument
1 parent a414275 commit 069159c

3 files changed

Lines changed: 74 additions & 33 deletions

File tree

examples/sample1/src/api.ts

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,6 @@ export interface PythonCommandRunConfiguration {
4848
args?: string[];
4949
}
5050

51-
export enum TerminalShellType {
52-
powershell = 'powershell',
53-
powershellCore = 'powershellCore',
54-
commandPrompt = 'commandPrompt',
55-
gitbash = 'gitbash',
56-
bash = 'bash',
57-
zsh = 'zsh',
58-
ksh = 'ksh',
59-
fish = 'fish',
60-
cshell = 'cshell',
61-
tcshell = 'tcshell',
62-
nushell = 'nushell',
63-
wsl = 'wsl',
64-
xonsh = 'xonsh',
65-
unknown = 'unknown',
66-
}
67-
6851
/**
6952
* Contains details on how to use a particular python environment
7053
*
@@ -73,7 +56,7 @@ export enum TerminalShellType {
7356
* 2. If {@link PythonEnvironmentExecutionInfo.activatedRun} is not provided, then:
7457
* - If {@link PythonEnvironmentExecutionInfo.shellActivation} is provided and shell type is known, then that will be used.
7558
* - If {@link PythonEnvironmentExecutionInfo.shellActivation} is provided and shell type is not known, then:
76-
* - {@link TerminalShellType.unknown} will be used if provided.
59+
* - 'unknown' will be used if provided.
7760
* - {@link PythonEnvironmentExecutionInfo.activation} will be used otherwise.
7861
* - If {@link PythonEnvironmentExecutionInfo.shellActivation} is not provided, then {@link PythonEnvironmentExecutionInfo.activation} will be used.
7962
* - If {@link PythonEnvironmentExecutionInfo.activation} is not provided, then {@link PythonEnvironmentExecutionInfo.run} will be used.
@@ -82,7 +65,7 @@ export enum TerminalShellType {
8265
* 1. If {@link PythonEnvironmentExecutionInfo.shellActivation} is provided and shell type is known, then that will be used.
8366
* 2. If {@link PythonEnvironmentExecutionInfo.shellActivation} is provided and shell type is not known, then {@link PythonEnvironmentExecutionInfo.activation} will be used.
8467
* 3. If {@link PythonEnvironmentExecutionInfo.shellActivation} is not provided, then:
85-
* - {@link TerminalShellType.unknown} will be used if provided.
68+
* - 'unknown' will be used if provided.
8669
* - {@link PythonEnvironmentExecutionInfo.activation} will be used otherwise.
8770
* 4. If {@link PythonEnvironmentExecutionInfo.activation} is not provided, then {@link PythonEnvironmentExecutionInfo.run} will be used.
8871
*
@@ -107,11 +90,11 @@ export interface PythonEnvironmentExecutionInfo {
10790
/**
10891
* Details on how to activate an environment using a shell specific command.
10992
* If set this will override the {@link PythonEnvironmentExecutionInfo.activation}.
110-
* {@link TerminalShellType.unknown} is used if shell type is not known.
111-
* If {@link TerminalShellType.unknown} is not provided and shell type is not known then
93+
* 'unknown' is used if shell type is not known.
94+
* If 'unknown' is not provided and shell type is not known then
11295
* {@link PythonEnvironmentExecutionInfo.activation} if set.
11396
*/
114-
shellActivation?: Map<TerminalShellType, PythonCommandRunConfiguration[]>;
97+
shellActivation?: Map<string, PythonCommandRunConfiguration[]>;
11598

11699
/**
117100
* Details on how to deactivate an environment.
@@ -121,11 +104,11 @@ export interface PythonEnvironmentExecutionInfo {
121104
/**
122105
* Details on how to deactivate an environment using a shell specific command.
123106
* If set this will override the {@link PythonEnvironmentExecutionInfo.deactivation} property.
124-
* {@link TerminalShellType.unknown} is used if shell type is not known.
125-
* If {@link TerminalShellType.unknown} is not provided and shell type is not known then
107+
* 'unknown' is used if shell type is not known.
108+
* If 'unknown' is not provided and shell type is not known then
126109
* {@link PythonEnvironmentExecutionInfo.deactivation} if set.
127110
*/
128-
shellDeactivation?: Map<TerminalShellType, PythonCommandRunConfiguration[]>;
111+
shellDeactivation?: Map<string, PythonCommandRunConfiguration[]>;
129112
}
130113

131114
/**
@@ -333,6 +316,18 @@ export type DidChangeEnvironmentsEventArgs = {
333316
*/
334317
export type ResolveEnvironmentContext = Uri;
335318

319+
export interface QuickCreateConfig {
320+
/**
321+
* The description of the quick create step.
322+
*/
323+
readonly description: string;
324+
325+
/**
326+
* The detail of the quick create step.
327+
*/
328+
readonly detail?: string;
329+
}
330+
336331
/**
337332
* Interface representing an environment manager.
338333
*/
@@ -377,12 +372,19 @@ export interface EnvironmentManager {
377372
*/
378373
readonly log?: LogOutputChannel;
379374

375+
/**
376+
* The quick create details for the environment manager. Having this method also enables the quick create feature
377+
* for the environment manager.
378+
*/
379+
quickCreateConfig?(): QuickCreateConfig | undefined;
380+
380381
/**
381382
* Creates a new Python environment within the specified scope.
382383
* @param scope - The scope within which to create the environment.
384+
* @param options - Optional parameters for creating the Python environment.
383385
* @returns A promise that resolves to the created Python environment, or undefined if creation failed.
384386
*/
385-
create?(scope: CreateEnvironmentScope): Promise<PythonEnvironment | undefined>;
387+
create?(scope: CreateEnvironmentScope, options?: CreateEnvironmentOptions): Promise<PythonEnvironment | undefined>;
386388

387389
/**
388390
* Removes the specified Python environment.
@@ -738,8 +740,35 @@ export interface PackageInstallOptions {
738740
* Upgrade the packages if it is already installed.
739741
*/
740742
upgrade?: boolean;
743+
744+
/**
745+
* Show option to skip package installation
746+
*/
747+
showSkipOption?: boolean;
748+
}
749+
750+
/**
751+
* Options for creating a Python environment.
752+
*/
753+
export interface CreateEnvironmentOptions {
754+
/**
755+
* Provides some context about quick create based on user input.
756+
* - if true, the environment should be created without any user input or prompts.
757+
* - if false, the environment creation can show user input or prompts.
758+
* This also means user explicitly skipped the quick create option.
759+
* - if undefined, the environment creation can show user input or prompts.
760+
* You can show quick create option to the user if you support it.
761+
*/
762+
quickCreate?: boolean;
763+
/**
764+
* Packages to install in addition to the automatically picked packages as a part of creating environment.
765+
*/
766+
additionalPackages?: string[];
741767
}
742768

769+
/**
770+
* Object representing the process started using run in background API.
771+
*/
743772
export interface PythonProcess {
744773
/**
745774
* The process ID of the Python process.
@@ -800,9 +829,13 @@ export interface PythonEnvironmentManagementApi {
800829
* Create a Python environment using environment manager associated with the scope.
801830
*
802831
* @param scope Where the environment is to be created.
832+
* @param options Optional parameters for creating the Python environment.
803833
* @returns The Python environment created. `undefined` if not created.
804834
*/
805-
createEnvironment(scope: CreateEnvironmentScope): Promise<PythonEnvironment | undefined>;
835+
createEnvironment(
836+
scope: CreateEnvironmentScope,
837+
options?: CreateEnvironmentOptions,
838+
): Promise<PythonEnvironment | undefined>;
806839

807840
/**
808841
* Remove a Python environment.

examples/sample1/src/sampleEnvManager.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MarkdownString, LogOutputChannel, Event } from 'vscode';
22
import {
3+
CreateEnvironmentOptions,
34
CreateEnvironmentScope,
45
DidChangeEnvironmentEventArgs,
56
DidChangeEnvironmentsEventArgs,
@@ -8,6 +9,7 @@ import {
89
GetEnvironmentsScope,
910
IconPath,
1011
PythonEnvironment,
12+
QuickCreateConfig,
1113
RefreshEnvironmentsScope,
1214
ResolveEnvironmentContext,
1315
SetEnvironmentScope,
@@ -31,7 +33,13 @@ export class SampleEnvManager implements EnvironmentManager {
3133
this.log = log;
3234
}
3335

34-
create?(scope: CreateEnvironmentScope): Promise<PythonEnvironment | undefined> {
36+
quickCreateConfig(): QuickCreateConfig | undefined {
37+
// Code to provide quick create configuration goes here
38+
39+
throw new Error('Method not implemented.');
40+
}
41+
42+
create?(scope: CreateEnvironmentScope, options?: CreateEnvironmentOptions): Promise<PythonEnvironment | undefined> {
3543
// Code to handle creating environments goes here
3644

3745
throw new Error('Method not implemented.');

src/api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,7 @@ export interface EnvironmentManager {
384384
* @param options - Optional parameters for creating the Python environment.
385385
* @returns A promise that resolves to the created Python environment, or undefined if creation failed.
386386
*/
387-
create?(
388-
scope: CreateEnvironmentScope,
389-
options: CreateEnvironmentOptions | undefined,
390-
): Promise<PythonEnvironment | undefined>;
387+
create?(scope: CreateEnvironmentScope, options?: CreateEnvironmentOptions): Promise<PythonEnvironment | undefined>;
391388

392389
/**
393390
* Removes the specified Python environment.
@@ -769,6 +766,9 @@ export interface CreateEnvironmentOptions {
769766
additionalPackages?: string[];
770767
}
771768

769+
/**
770+
* Object representing the process started using run in background API.
771+
*/
772772
export interface PythonProcess {
773773
/**
774774
* The process ID of the Python process.
@@ -834,7 +834,7 @@ export interface PythonEnvironmentManagementApi {
834834
*/
835835
createEnvironment(
836836
scope: CreateEnvironmentScope,
837-
options: CreateEnvironmentOptions | undefined,
837+
options?: CreateEnvironmentOptions,
838838
): Promise<PythonEnvironment | undefined>;
839839

840840
/**

0 commit comments

Comments
 (0)