Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
"python-envs.terminal.deactivate.title": "Deactivate Environment in Current Terminal",
"python-envs.uninstallPackage.title": "Uninstall Package",
"python-envs.revealProjectInExplorer.title": "Reveal Project in Explorer",
"python-envs.runPetInTerminal.title": "Run Python Environment Tool (PET) in Terminal"
"python-envs.runPetInTerminal.title": "Run Python Environment Tool (PET) in Terminal..."
}
63 changes: 56 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EventNames } from './common/telemetry/constants';
import { sendManagerSelectionTelemetry } from './common/telemetry/helpers';
import { sendTelemetryEvent } from './common/telemetry/sender';
import { createDeferred } from './common/utils/deferred';
import { isWindows } from './common/utils/platformUtils';
import {
activeTerminal,
createLogOutputChannel,
Expand Down Expand Up @@ -57,8 +58,8 @@ import {
import { ShellStartupActivationVariablesManagerImpl } from './features/terminal/shellStartupActivationVariablesManager';
import { cleanupStartupScripts } from './features/terminal/shellStartupSetupHandlers';
import { TerminalActivationImpl } from './features/terminal/terminalActivationState';
import { TerminalManager, TerminalManagerImpl } from './features/terminal/terminalManager';
import { TerminalEnvVarInjector } from './features/terminal/terminalEnvVarInjector';
import { TerminalManager, TerminalManagerImpl } from './features/terminal/terminalManager';
import { getAutoActivationType, getEnvironmentForTerminal } from './features/terminal/utils';
import { EnvManagerView } from './features/views/envManagersView';
import { ProjectView } from './features/views/projectView';
Expand Down Expand Up @@ -241,10 +242,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
);

// Initialize terminal environment variable injection
const terminalEnvVarInjector = new TerminalEnvVarInjector(
context.environmentVariableCollection,
envVarManager,
);
const terminalEnvVarInjector = new TerminalEnvVarInjector(context.environmentVariableCollection, envVarManager);
context.subscriptions.push(terminalEnvVarInjector);

context.subscriptions.push(
Expand Down Expand Up @@ -450,12 +448,63 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
commands.registerCommand('python-envs.runPetInTerminal', async () => {
try {
const petPath = await getNativePythonToolsPath();

// Show quick pick menu for PET operation selection
const selectedOption = await window.showQuickPick(
[
{
label: 'Find All Environments',
description: 'Finds all environments and reports them to the standard output',
detail: 'Runs: pet find --verbose',
},
{
label: 'Resolve Environment...',
description: 'Resolves & reports the details of the environment to the standard output',
detail: 'Runs: pet resolve <path>',
},
],
{
placeHolder: 'Select a Python Environment Tool (PET) operation',
ignoreFocusOut: true,
},
);

if (!selectedOption) {
return; // User cancelled
}

const terminal = createTerminal({
name: 'Python Environment Tool (PET)',
});
terminal.show();
terminal.sendText(`"${petPath}"`, true);
traceInfo(`Running PET in terminal: ${petPath}`);

if (selectedOption.label === 'Find All Environments') {
// Run pet find --verbose
terminal.sendText(`"${petPath}" find --verbose`, true);
traceInfo(`Running PET find command: ${petPath} find --verbose`);
} else if (selectedOption.label === 'Resolve Environment...') {
// Show input box for path
const placeholder = isWindows() ? 'C:\\path\\to\\python\\executable' : '/path/to/python/executable';
const inputPath = await window.showInputBox({
prompt: 'Enter the path to the Python executable to resolve',
placeHolder: placeholder,
ignoreFocusOut: true,
validateInput: (value) => {
if (!value || value.trim().length === 0) {
return 'Please enter a valid path';
}
return null;
},
});

if (!inputPath) {
return; // User cancelled
}

// Run pet resolve with the provided path
terminal.sendText(`"${petPath}" resolve "${inputPath.trim()}"`, true);
traceInfo(`Running PET resolve command: ${petPath} resolve "${inputPath.trim()}"`);
}
} catch (error) {
traceError('Error running PET in terminal', error);
window.showErrorMessage(`Failed to run Python Environment Tool: ${error}`);
Expand Down
Loading