Skip to content

Commit cae81b4

Browse files
Update PET command to include submenu for find and resolve operations (#702)
This PR updates the "Python: Run Python Environment Tool (PET) in Terminal" command to provide a better user experience by adding a submenu that allows users to choose between different PET operations. ## Changes ### Before The command would directly run the PET executable without any options, requiring users to manually add arguments in the terminal. ### After The command now presents a QuickPick menu with two options: 1. **Find All Environments** - Runs `pet find --verbose` to discover and list all Python environments 2. **Resolve Environment...** - Prompts for a Python executable path, then runs `pet resolve <path>` to get detailed environment information ## User Experience Flow 1. User runs "Python: Run Python Environment Tool (PET) in Terminal..." 2. A menu appears with clear descriptions of each operation: - "Find All Environments": Finds all environments and reports them to standard output - "Resolve Environment...": Resolves & reports details of a specific environment 3. For "Find All Environments": Terminal opens and immediately runs the find command 4. For "Resolve Environment...": User enters a path to a Python executable, then the resolve command runs 5. All interactions support cancellation and include proper error handling ## Technical Details - Updated command title to include ellipsis ("...") to indicate additional user interaction - Implemented using VS Code's native QuickPick and InputBox APIs - Added input validation for the resolve path option - Maintained existing terminal creation and error handling patterns - All existing functionality preserved with no breaking changes The implementation follows the existing codebase patterns and includes comprehensive error handling for a smooth user experience. Fixes #701. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/microsoft/vscode-python-environments/issues/new?title=✨Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
1 parent 8afb007 commit cae81b4

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@
3636
"python-envs.terminal.deactivate.title": "Deactivate Environment in Current Terminal",
3737
"python-envs.uninstallPackage.title": "Uninstall Package",
3838
"python-envs.revealProjectInExplorer.title": "Reveal Project in Explorer",
39-
"python-envs.runPetInTerminal.title": "Run Python Environment Tool (PET) in Terminal"
39+
"python-envs.runPetInTerminal.title": "Run Python Environment Tool (PET) in Terminal..."
4040
}

src/extension.ts

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { EventNames } from './common/telemetry/constants';
99
import { sendManagerSelectionTelemetry } from './common/telemetry/helpers';
1010
import { sendTelemetryEvent } from './common/telemetry/sender';
1111
import { createDeferred } from './common/utils/deferred';
12+
import { isWindows } from './common/utils/platformUtils';
1213
import {
1314
activeTerminal,
1415
createLogOutputChannel,
@@ -57,8 +58,8 @@ import {
5758
import { ShellStartupActivationVariablesManagerImpl } from './features/terminal/shellStartupActivationVariablesManager';
5859
import { cleanupStartupScripts } from './features/terminal/shellStartupSetupHandlers';
5960
import { TerminalActivationImpl } from './features/terminal/terminalActivationState';
60-
import { TerminalManager, TerminalManagerImpl } from './features/terminal/terminalManager';
6161
import { TerminalEnvVarInjector } from './features/terminal/terminalEnvVarInjector';
62+
import { TerminalManager, TerminalManagerImpl } from './features/terminal/terminalManager';
6263
import { getAutoActivationType, getEnvironmentForTerminal } from './features/terminal/utils';
6364
import { EnvManagerView } from './features/views/envManagersView';
6465
import { ProjectView } from './features/views/projectView';
@@ -241,10 +242,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
241242
);
242243

243244
// Initialize terminal environment variable injection
244-
const terminalEnvVarInjector = new TerminalEnvVarInjector(
245-
context.environmentVariableCollection,
246-
envVarManager,
247-
);
245+
const terminalEnvVarInjector = new TerminalEnvVarInjector(context.environmentVariableCollection, envVarManager);
248246
context.subscriptions.push(terminalEnvVarInjector);
249247

250248
context.subscriptions.push(
@@ -450,12 +448,63 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
450448
commands.registerCommand('python-envs.runPetInTerminal', async () => {
451449
try {
452450
const petPath = await getNativePythonToolsPath();
451+
452+
// Show quick pick menu for PET operation selection
453+
const selectedOption = await window.showQuickPick(
454+
[
455+
{
456+
label: 'Find All Environments',
457+
description: 'Finds all environments and reports them to the standard output',
458+
detail: 'Runs: pet find --verbose',
459+
},
460+
{
461+
label: 'Resolve Environment...',
462+
description: 'Resolves & reports the details of the environment to the standard output',
463+
detail: 'Runs: pet resolve <path>',
464+
},
465+
],
466+
{
467+
placeHolder: 'Select a Python Environment Tool (PET) operation',
468+
ignoreFocusOut: true,
469+
},
470+
);
471+
472+
if (!selectedOption) {
473+
return; // User cancelled
474+
}
475+
453476
const terminal = createTerminal({
454477
name: 'Python Environment Tool (PET)',
455478
});
456479
terminal.show();
457-
terminal.sendText(`"${petPath}"`, true);
458-
traceInfo(`Running PET in terminal: ${petPath}`);
480+
481+
if (selectedOption.label === 'Find All Environments') {
482+
// Run pet find --verbose
483+
terminal.sendText(`"${petPath}" find --verbose`, true);
484+
traceInfo(`Running PET find command: ${petPath} find --verbose`);
485+
} else if (selectedOption.label === 'Resolve Environment...') {
486+
// Show input box for path
487+
const placeholder = isWindows() ? 'C:\\path\\to\\python\\executable' : '/path/to/python/executable';
488+
const inputPath = await window.showInputBox({
489+
prompt: 'Enter the path to the Python executable to resolve',
490+
placeHolder: placeholder,
491+
ignoreFocusOut: true,
492+
validateInput: (value) => {
493+
if (!value || value.trim().length === 0) {
494+
return 'Please enter a valid path';
495+
}
496+
return null;
497+
},
498+
});
499+
500+
if (!inputPath) {
501+
return; // User cancelled
502+
}
503+
504+
// Run pet resolve with the provided path
505+
terminal.sendText(`"${petPath}" resolve "${inputPath.trim()}"`, true);
506+
traceInfo(`Running PET resolve command: ${petPath} resolve "${inputPath.trim()}"`);
507+
}
459508
} catch (error) {
460509
traceError('Error running PET in terminal', error);
461510
window.showErrorMessage(`Failed to run Python Environment Tool: ${error}`);

0 commit comments

Comments
 (0)