Skip to content

Commit 681287a

Browse files
Copiloteleanorjboyd
andcommitted
Add PET terminal command implementation
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
1 parent 85e51e6 commit 681287a

4 files changed

Lines changed: 27 additions & 3 deletions

File tree

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@
262262
"title": "%python-envs.revealProjectInExplorer.title%",
263263
"category": "Python Envs",
264264
"icon": "$(folder-opened)"
265+
},
266+
{
267+
"command": "python-envs.runPetInTerminal",
268+
"title": "%python-envs.runPetInTerminal.title%",
269+
"category": "Python",
270+
"icon": "$(terminal)",
271+
"when": "config.python.useEnvironmentsExtension != false"
265272
}
266273
],
267274
"menus": {

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
"python-envs.terminal.activate.title": "Activate Environment in Current Terminal",
3636
"python-envs.terminal.deactivate.title": "Deactivate Environment in Current Terminal",
3737
"python-envs.uninstallPackage.title": "Uninstall Package",
38-
"python-envs.revealProjectInExplorer.title": "Reveal Project in Explorer"
38+
"python-envs.revealProjectInExplorer.title": "Reveal Project in Explorer",
39+
"python-envs.runPetInTerminal.title": "Run Python Environment Tool (PET) in Terminal"
3940
}

src/extension.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { createDeferred } from './common/utils/deferred';
1212
import {
1313
activeTerminal,
1414
createLogOutputChannel,
15+
createTerminal,
1516
onDidChangeActiveTerminal,
1617
onDidChangeTerminalShellIntegration,
1718
} from './common/window.apis';
@@ -66,7 +67,7 @@ import { ProjectItem } from './features/views/treeViewItems';
6667
import { EnvironmentManagers, ProjectCreators, PythonProjectManager } from './internal.api';
6768
import { registerSystemPythonFeatures } from './managers/builtin/main';
6869
import { SysPythonManager } from './managers/builtin/sysPythonManager';
69-
import { createNativePythonFinder, NativePythonFinder } from './managers/common/nativePythonFinder';
70+
import { createNativePythonFinder, getNativePythonToolsPath, NativePythonFinder } from './managers/common/nativePythonFinder';
7071
import { IDisposable } from './managers/common/types';
7172
import { registerCondaFeatures } from './managers/conda/main';
7273
import { registerPoetryFeatures } from './managers/poetry/main';
@@ -429,6 +430,21 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
429430
window.showErrorMessage(`Failed to open issue reporter: ${error}`);
430431
}
431432
}),
433+
commands.registerCommand('python-envs.runPetInTerminal', async () => {
434+
try {
435+
const petPath = await getNativePythonToolsPath();
436+
const terminal = createTerminal({
437+
name: 'Python Environment Tool (PET)',
438+
shellPath: petPath,
439+
shellArgs: []
440+
});
441+
terminal.show();
442+
traceInfo(`Created terminal with PET: ${petPath}`);
443+
} catch (error) {
444+
traceError('Error running PET in terminal', error);
445+
window.showErrorMessage(`Failed to run Python Environment Tool: ${error}`);
446+
}
447+
}),
432448
terminalActivation.onDidChangeTerminalActivationState(async (e) => {
433449
await setActivateMenuButtonContext(e.terminal, e.environment, e.activated);
434450
}),

src/managers/common/nativePythonFinder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { traceVerbose } from '../../common/logging';
1414
import { isWindows } from '../../common/utils/platformUtils';
1515
import { getUserHomeDir, untildify } from '../../common/utils/pathUtils';
1616

17-
async function getNativePythonToolsPath(): Promise<string> {
17+
export async function getNativePythonToolsPath(): Promise<string> {
1818
const envsExt = getExtension(ENVS_EXTENSION_ID);
1919
if (envsExt) {
2020
const petPath = path.join(envsExt.extensionPath, 'python-env-tools', 'bin', isWindows() ? 'pet.exe' : 'pet');

0 commit comments

Comments
 (0)