Skip to content

Commit b0d6dbd

Browse files
committed
fix: make create environment options an optional argument
1 parent 8e1887a commit b0d6dbd

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

examples/sample1/src/api.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,18 @@ export type DidChangeEnvironmentsEventArgs = {
316316
*/
317317
export type ResolveEnvironmentContext = Uri;
318318

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+
319331
/**
320332
* Interface representing an environment manager.
321333
*/
@@ -360,12 +372,19 @@ export interface EnvironmentManager {
360372
*/
361373
readonly log?: LogOutputChannel;
362374

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+
363381
/**
364382
* Creates a new Python environment within the specified scope.
365383
* @param scope - The scope within which to create the environment.
384+
* @param options - Optional parameters for creating the Python environment.
366385
* @returns A promise that resolves to the created Python environment, or undefined if creation failed.
367386
*/
368-
create?(scope: CreateEnvironmentScope): Promise<PythonEnvironment | undefined>;
387+
create?(scope: CreateEnvironmentScope, options?: CreateEnvironmentOptions): Promise<PythonEnvironment | undefined>;
369388

370389
/**
371390
* Removes the specified Python environment.
@@ -705,6 +724,9 @@ export interface DidChangePythonProjectsEventArgs {
705724
removed: PythonProject[];
706725
}
707726

727+
/**
728+
* Options for package management.
729+
*/
708730
export type PackageManagementOptions =
709731
| {
710732
/**
@@ -747,6 +769,28 @@ export type PackageManagementOptions =
747769
uninstall: string[];
748770
};
749771

772+
/**
773+
* Options for creating a Python environment.
774+
*/
775+
export interface CreateEnvironmentOptions {
776+
/**
777+
* Provides some context about quick create based on user input.
778+
* - if true, the environment should be created without any user input or prompts.
779+
* - if false, the environment creation can show user input or prompts.
780+
* This also means user explicitly skipped the quick create option.
781+
* - if undefined, the environment creation can show user input or prompts.
782+
* You can show quick create option to the user if you support it.
783+
*/
784+
quickCreate?: boolean;
785+
/**
786+
* Packages to install in addition to the automatically picked packages as a part of creating environment.
787+
*/
788+
additionalPackages?: string[];
789+
}
790+
791+
/**
792+
* Object representing the process started using run in background API.
793+
*/
750794
export interface PythonProcess {
751795
/**
752796
* The process ID of the Python process.
@@ -807,9 +851,13 @@ export interface PythonEnvironmentManagementApi {
807851
* Create a Python environment using environment manager associated with the scope.
808852
*
809853
* @param scope Where the environment is to be created.
854+
* @param options Optional parameters for creating the Python environment.
810855
* @returns The Python environment created. `undefined` if not created.
811856
*/
812-
createEnvironment(scope: CreateEnvironmentScope): Promise<PythonEnvironment | undefined>;
857+
createEnvironment(
858+
scope: CreateEnvironmentScope,
859+
options?: CreateEnvironmentOptions,
860+
): Promise<PythonEnvironment | undefined>;
813861

814862
/**
815863
* 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.
@@ -788,6 +785,9 @@ export interface CreateEnvironmentOptions {
788785
additionalPackages?: string[];
789786
}
790787

788+
/**
789+
* Object representing the process started using run in background API.
790+
*/
791791
export interface PythonProcess {
792792
/**
793793
* The process ID of the Python process.
@@ -853,7 +853,7 @@ export interface PythonEnvironmentManagementApi {
853853
*/
854854
createEnvironment(
855855
scope: CreateEnvironmentScope,
856-
options: CreateEnvironmentOptions | undefined,
856+
options?: CreateEnvironmentOptions,
857857
): Promise<PythonEnvironment | undefined>;
858858

859859
/**

0 commit comments

Comments
 (0)