Skip to content

Commit b71dfe0

Browse files
authored
fix: show back button with create environment (#323)
fixes: #321 The following fields are supported when using `python-envs.createAny` command: ``` /** * Default `false`. If `true` the creation provider should show back button when showing QuickPick or QuickInput. */ showBackButton?: boolean; /** * Default `true`. If `true`, the environment after creation will be selected. */ selectEnvironment?: boolean; ```
1 parent 3dc50f0 commit b71dfe0

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ The Python Environments and Package Manager extension for VS Code helps you mana
1212

1313
<img src=https://raw.githubusercontent.com/microsoft/vscode-python-environments/main/images/python-envs-overview.gif width=734 height=413>
1414

15-
1615
### Environment Management
1716

1817
This extension provides an Environments view, which can be accessed via the VS Code Activity Bar, where you can manage your Python environments. Here, you can create, delete, and switch between environments, as well as install and uninstall packages within the selected environment. It also provides APIs for extension developers to contribute their own environment managers.
@@ -54,19 +53,44 @@ See [api.ts](https://github.com/microsoft/vscode-python-environments/blob/main/s
5453
To consume these APIs you can look at the example here:
5554
https://github.com/microsoft/vscode-python-environments/blob/main/examples/README.md
5655

56+
### Callable Commands
57+
58+
The extension provides a set of callable commands that can be used to interact with the environment and package managers. These commands can be invoked from other extensions or from the command palette.
59+
60+
#### `python-envs.createAny`
61+
62+
Create a new environment using any of the available environment managers. This command will prompt the user to select the environment manager to use. Following options are available on this command:
63+
64+
```typescript
65+
{
66+
/**
67+
* Default `false`. If `true` the creation provider should show back button when showing QuickPick or QuickInput.
68+
*/
69+
showBackButton?: boolean;
70+
71+
/**
72+
* Default `true`. If `true`, the environment after creation will be selected.
73+
*/
74+
selectEnvironment?: boolean;
75+
}
76+
```
77+
78+
usage: `await vscode.commands.executeCommand('python-envs.createAny', options);`
5779

5880
## Extension Dependency
5981

60-
This section provides an overview of how the Python extension interacts with the Python Environments extension and other tool-specific extensions. The Python Environments extension allows users to create, manage, and remove Python environments and packages. It also provides an API that other extensions can use to support environment management or consume it for running Python tools or projects.
82+
This section provides an overview of how the Python extension interacts with the Python Environments extension and other tool-specific extensions. The Python Environments extension allows users to create, manage, and remove Python environments and packages. It also provides an API that other extensions can use to support environment management or consume it for running Python tools or projects.
6183

6284
Tools that may rely on these APIs in their own extensions include:
63-
- **Debuggers** (e.g., `debugpy`)
64-
- **Linters** (e.g., Pylint, Flake8, Mypy)
65-
- **Formatters** (e.g., Black, autopep8)
66-
- **Language Server extensions** (e.g., Pylance, Jedi)
67-
- **Environment and Package Manager extensions** (e.g., Pixi, Conda, Hatch)
85+
86+
- **Debuggers** (e.g., `debugpy`)
87+
- **Linters** (e.g., Pylint, Flake8, Mypy)
88+
- **Formatters** (e.g., Black, autopep8)
89+
- **Language Server extensions** (e.g., Pylance, Jedi)
90+
- **Environment and Package Manager extensions** (e.g., Pixi, Conda, Hatch)
6891

6992
### API Dependency
93+
7094
The relationship between these extensions can be represented as follows:
7195

7296
<img src=https://raw.githubusercontent.com/microsoft/vscode-python-environments/refs/heads/main/images/extension_relationships.png width=734 height=413>
@@ -75,7 +99,7 @@ Users who do not need to execute code or work in **Virtual Workspaces** can use
7599

76100
### Trust Relationship Between Python and Python Environments Extensions
77101

78-
VS Code supports trust management, allowing extensions to function in either **trusted** or **untrusted** scenarios. Code execution and tools that can modify the user’s environment are typically unavailable in untrusted scenarios.
102+
VS Code supports trust management, allowing extensions to function in either **trusted** or **untrusted** scenarios. Code execution and tools that can modify the user’s environment are typically unavailable in untrusted scenarios.
79103

80104
The relationship is illustrated below:
81105

src/common/pickers/managers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function getDescription(mgr: InternalEnvironmentManager | InternalPackageManager
2121
export async function pickEnvironmentManager(
2222
managers: InternalEnvironmentManager[],
2323
defaultManagers?: InternalEnvironmentManager[],
24+
showBackButton?: boolean,
2425
): Promise<string | undefined> {
2526
if (managers.length === 0) {
2627
return;
@@ -72,6 +73,7 @@ export async function pickEnvironmentManager(
7273
const item = await showQuickPickWithButtons(items, {
7374
placeHolder: Pickers.Managers.selectEnvironmentManager,
7475
ignoreFocusOut: true,
76+
showBackButton,
7577
});
7678
return (item as QuickPickItem & { id: string })?.id;
7779
}

src/features/envCommands.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export async function createEnvironmentCommand(
115115
export async function createAnyEnvironmentCommand(
116116
em: EnvironmentManagers,
117117
pm: PythonProjectManager,
118-
options?: CreateEnvironmentOptions & { selectEnvironment: boolean },
118+
options?: CreateEnvironmentOptions & { selectEnvironment?: boolean; showBackButton?: boolean },
119119
): Promise<PythonEnvironment | undefined> {
120120
const select = options?.selectEnvironment;
121121
const projects = pm.getProjects();
@@ -130,7 +130,7 @@ export async function createAnyEnvironmentCommand(
130130
return env;
131131
}
132132
} else if (projects.length > 0) {
133-
const selected = await pickProjectMany(projects);
133+
const selected = await pickProjectMany(projects, options?.showBackButton);
134134

135135
if (selected && selected.length > 0) {
136136
const defaultManagers: InternalEnvironmentManager[] = [];
@@ -151,6 +151,7 @@ export async function createAnyEnvironmentCommand(
151151
let managerId = await pickEnvironmentManager(
152152
em.managers.filter((m) => m.supportsCreate),
153153
defaultManagers,
154+
options?.showBackButton,
154155
);
155156
if (managerId?.startsWith('QuickCreate#')) {
156157
quickCreate = true;

0 commit comments

Comments
 (0)