Skip to content

Commit e4993cb

Browse files
authored
Merge branch 'main' into update-readme
2 parents 33793c3 + ac0c8cd commit e4993cb

77 files changed

Lines changed: 4657 additions & 817 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.18.0

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"request": "launch",
1212
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
1313
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
14-
"preLaunchTask": "${defaultBuildTask}"
14+
"preLaunchTask": "npm: watch"
1515
},
1616
{
1717
"name": "Unit Tests",
@@ -30,7 +30,7 @@
3030
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
3131
"skipFiles": ["<node_internals>/**"],
3232
"outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"],
33-
"preLaunchTask": "tasks: watch-tests"
33+
"preLaunchTask": "npm: watch-tests"
3434
},
3535
{
3636
"name": "Extension Tests",
@@ -41,7 +41,7 @@
4141
"--extensionTestsPath=${workspaceFolder}/out/test/"
4242
],
4343
"outFiles": ["${workspaceFolder}/out/**/*.js", "${workspaceFolder}/dist/**/*.js"],
44-
"preLaunchTask": "tasks: watch-tests"
44+
"preLaunchTask": "${defaultBuildTask}"
4545
}
4646
]
4747
}

.vscode/settings.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
"typescript.tsc.autoDetect": "off",
1313
"editor.formatOnSave": true,
1414
"[typescript]": {
15-
"editor.defaultFormatter": "esbenp.prettier-vscode"
15+
"editor.defaultFormatter": "esbenp.prettier-vscode",
16+
"editor.codeActionsOnSave": {
17+
"source.organizeImports": "explicit"
18+
}
1619
},
1720
"[python]": {
1821
"editor.defaultFormatter": "charliermarsh.ruff",
19-
"diffEditor.ignoreTrimWhitespace": false
22+
"diffEditor.ignoreTrimWhitespace": false,
23+
"editor.codeActionsOnSave": {
24+
"source.organizeImports": "explicit"
25+
}
2026
},
2127
"prettier.tabWidth": 4,
2228
"python-envs.defaultEnvManager": "ms-python.python:venv",

.vscode/tasks.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525
"presentation": {
2626
"reveal": "never",
2727
"group": "watchers"
28-
},
29-
"group": "build"
28+
}
3029
},
3130
{
32-
"label": "tasks: watch-tests",
31+
"label": "tasks: build",
3332
"dependsOn": ["npm: watch", "npm: watch-tests"],
34-
"problemMatcher": []
33+
"problemMatcher": [],
34+
"presentation": {
35+
"reveal": "never",
36+
"group": "watchers"
37+
}
3538
},
3639
{
3740
"type": "npm",

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,34 @@ See [api.ts](https://github.com/microsoft/vscode-python-environments/blob/main/s
9999

100100
To consume these APIs you can look at the example here: [API Consumption Examples](https://github.com/microsoft/vscode-python-environments/blob/main/examples/README.md)
101101

102+
### Callable Commands
103+
104+
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.
105+
106+
#### `python-envs.createAny`
107+
108+
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:
109+
110+
```typescript
111+
{
112+
/**
113+
* Default `false`. If `true` the creation provider should show back button when showing QuickPick or QuickInput.
114+
*/
115+
showBackButton?: boolean;
116+
117+
/**
118+
* Default `true`. If `true`, the environment after creation will be selected.
119+
*/
120+
selectEnvironment?: boolean;
121+
}
122+
```
123+
124+
usage: `await vscode.commands.executeCommand('python-envs.createAny', options);`
125+
126+
102127
## Extension Dependency
103128

104-
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.
129+
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.
105130

106131
Tools that may rely on these APIs in their own extensions include:
107132

@@ -121,7 +146,7 @@ Users who do not need to execute code or work in **Virtual Workspaces** can use
121146

122147
### Trust Relationship Between Python and Python Environments Extensions
123148

124-
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.
149+
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.
125150

126151
The relationship is illustrated below:
127152

package.json

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@
8686
"onExP",
8787
"preview"
8888
]
89+
},
90+
"python-envs.terminal.autoActivationType": {
91+
"type": "string",
92+
"markdownDescription": "%python-envs.terminal.autoActivationType.description%",
93+
"default": "command",
94+
"enum": [
95+
"command",
96+
"shellStartup",
97+
"off"
98+
],
99+
"markdownEnumDescriptions": [
100+
"%python-envs.terminal.autoActivationType.command%",
101+
"%python-envs.terminal.autoActivationType.shellStartup%",
102+
"%python-envs.terminal.autoActivationType.off%"
103+
],
104+
"scope": "machine"
89105
}
90106
}
91107
},
@@ -228,14 +244,16 @@
228244
"title": "%python-envs.copyProjectPath.title%",
229245
"category": "Python Envs",
230246
"icon": "$(copy)"
247+
},
248+
{
249+
"command": "python-envs.terminal.revertStartupScriptChanges",
250+
"title": "%python-envs.terminal.revertStartupScriptChanges.title%",
251+
"category": "Python Envs",
252+
"icon": "$(discard)"
231253
}
232254
],
233255
"menus": {
234256
"commandPalette": [
235-
{
236-
"command": "python-envs.packages",
237-
"when": "false"
238-
},
239257
{
240258
"command": "python-envs.refreshAllManagers",
241259
"when": "false"
@@ -491,22 +509,53 @@
491509
],
492510
"languageModelTools": [
493511
{
494-
"name": "python_get_packages",
495-
"displayName": "Get Python Packages",
496-
"modelDescription": "Returns the packages installed in the given Python file's environment. You should call this when you want to generate Python code to determine the users preferred packages. Also call this to determine if you need to provide installation instructions in a response.",
497-
"toolReferenceName": "pythonGetPackages",
512+
"name": "python_environment",
513+
"userDescription": "Get Python environment info for a file or path, including version, packages, and the command to run it.",
514+
"displayName": "Get Python Environment Information",
515+
"modelDescription": "Provides details about the Python environment for a specified file or workspace, including environment type, Python version, run command, and installed packages with their versions. Use this tool to determine the correct command for executing Python code in this workspace.",
516+
"toolReferenceName": "pythonGetEnvironmentInfo",
498517
"tags": [],
499518
"icon": "$(files)",
519+
"canBeReferencedInPrompt": true,
500520
"inputSchema": {
501521
"type": "object",
502522
"properties": {
503-
"filePath": {
523+
"resourcePath": {
504524
"type": "string"
505525
}
506526
},
507-
"description": "The path to the Python file or workspace to get the installed packages for.",
527+
"description": "The path to the Python file or workspace to get the environment information for.",
528+
"required": [
529+
"resourcePath"
530+
]
531+
}
532+
},
533+
{
534+
"name": "python_install_package",
535+
"displayName": "Install Python Package",
536+
"modelDescription": "Installs Python packages in the given workspace. Use this tool to install packages in the user's chosen environment.",
537+
"toolReferenceName": "pythonInstallPackage",
538+
"tags": [],
539+
"icon": "$(package)",
540+
"canBeReferencedInPrompt": true,
541+
"inputSchema": {
542+
"type": "object",
543+
"properties": {
544+
"packageList": {
545+
"type": "array",
546+
"items": {
547+
"type": "string"
548+
},
549+
"description": "The list of packages to install."
550+
},
551+
"resourcePath": {
552+
"type": "string",
553+
"description": "The path to the Python file or workspace to get the environment information for."
554+
}
555+
},
508556
"required": [
509-
"filePath"
557+
"packageList",
558+
"resourcePath"
510559
]
511560
}
512561
}

package.nls.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
"python-envs.pythonProjects.envManager.description": "The environment manager for creating and managing environments for this project.",
77
"python-envs.pythonProjects.packageManager.description": "The package manager for managing packages in environments for this project.",
88
"python-envs.terminal.showActivateButton.description": "Whether to show the 'Activate' button in the terminal menu",
9+
"python-envs.terminal.autoActivationType.description": "The type of activation to use when activating an environment in the terminal",
10+
"python-envs.terminal.autoActivationType.command": "Activation by executing a command in the terminal.",
11+
"python-envs.terminal.autoActivationType.shellStartup": "Activation by modifying the terminal shell startup script. To use this feature we will need to modify your shell startup scripts.",
12+
"python-envs.terminal.autoActivationType.off": "No automatic activation of environments.",
13+
"python-envs.terminal.revertStartupScriptChanges.title": "Revert Shell Startup Script Changes",
914
"python-envs.setEnvManager.title": "Set Environment Manager",
1015
"python-envs.setPkgManager.title": "Set Package Manager",
1116
"python-envs.addPythonProject.title": "Add Python Project",

src/api.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
// Licensed under the MIT License.
33

44
import {
5-
Uri,
65
Disposable,
7-
MarkdownString,
86
Event,
7+
FileChangeType,
98
LogOutputChannel,
10-
ThemeIcon,
11-
Terminal,
9+
MarkdownString,
1210
TaskExecution,
11+
Terminal,
1312
TerminalOptions,
14-
FileChangeType,
13+
ThemeIcon,
14+
Uri,
1515
} from 'vscode';
1616

1717
/**
@@ -333,7 +333,7 @@ export interface QuickCreateConfig {
333333
*/
334334
export interface EnvironmentManager {
335335
/**
336-
* The name of the environment manager.
336+
* The name of the environment manager. Allowed characters (a-z, A-Z, 0-9, -, _).
337337
*/
338338
readonly name: string;
339339

@@ -374,7 +374,7 @@ export interface EnvironmentManager {
374374

375375
/**
376376
* The quick create details for the environment manager. Having this method also enables the quick create feature
377-
* for the environment manager.
377+
* for the environment manager. Should Implement {@link EnvironmentManager.create} to support quick create.
378378
*/
379379
quickCreateConfig?(): QuickCreateConfig | undefined;
380380

@@ -564,7 +564,7 @@ export interface DidChangePackagesEventArgs {
564564
*/
565565
export interface PackageManager {
566566
/**
567-
* The name of the package manager.
567+
* The name of the package manager. Allowed characters (a-z, A-Z, 0-9, -, _).
568568
*/
569569
name: string;
570570

@@ -596,7 +596,7 @@ export interface PackageManager {
596596
/**
597597
* Installs/Uninstall packages in the specified Python environment.
598598
* @param environment - The Python environment in which to install packages.
599-
* @param packages - The packages to install.
599+
* @param options - Options for managing packages.
600600
* @returns A promise that resolves when the installation is complete.
601601
*/
602602
manage(environment: PythonEnvironment, options: PackageManagementOptions): Promise<void>;
@@ -667,9 +667,14 @@ export interface PythonProjectCreatorOptions {
667667
name: string;
668668

669669
/**
670-
* Optional path that may be provided as a root for the project.
670+
* Path provided as the root for the project.
671671
*/
672-
uri?: Uri;
672+
rootUri: Uri;
673+
674+
/**
675+
* Boolean indicating whether the project should be created without any user input.
676+
*/
677+
quickCreate?: boolean;
673678
}
674679

675680
/**
@@ -702,11 +707,20 @@ export interface PythonProjectCreator {
702707
readonly iconPath?: IconPath;
703708

704709
/**
705-
* Creates a new Python project or projects.
706-
* @param options - Optional parameters for creating the Python project.
707-
* @returns A promise that resolves to a Python project, an array of Python projects, or undefined.
710+
* Creates a new Python project(s) or, if files are not a project, returns Uri(s) to the created files.
711+
* Anything that needs its own python environment constitutes a project.
712+
* @param options Optional parameters for creating the Python project.
713+
* @returns A promise that resolves to one of the following:
714+
* - PythonProject or PythonProject[]: when a single or multiple projects are created.
715+
* - Uri or Uri[]: when files are created that do not constitute a project.
716+
* - undefined: if project creation fails.
717+
*/
718+
create(options?: PythonProjectCreatorOptions): Promise<PythonProject | PythonProject[] | Uri | Uri[] | undefined>;
719+
720+
/**
721+
* A flag indicating whether the project creator supports quick create where no user input is required.
708722
*/
709-
create(options?: PythonProjectCreatorOptions): Promise<PythonProject | PythonProject[] | undefined>;
723+
readonly supportsQuickCreate?: boolean;
710724
}
711725

712726
/**

src/common/command.api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { commands } from 'vscode';
3+
import { Disposable } from 'vscode-jsonrpc';
4+
5+
export function registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable {
6+
return commands.registerCommand(command, callback, thisArg);
7+
}
38

49
export function executeCommand<T = unknown>(command: string, ...rest: any[]): Thenable<T> {
510
return commands.executeCommand(command, ...rest);

src/common/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export namespace Commands {
2+
export const viewLogs = 'python-envs.viewLogs';
3+
}

0 commit comments

Comments
 (0)