diff --git a/package.json b/package.json index f7956c3d..7886ed16 100644 --- a/package.json +++ b/package.json @@ -262,6 +262,13 @@ "title": "%python-envs.revealProjectInExplorer.title%", "category": "Python Envs", "icon": "$(folder-opened)" + }, + { + "command": "python-envs.runPetInTerminal", + "title": "%python-envs.runPetInTerminal.title%", + "category": "Python", + "icon": "$(terminal)", + "when": "config.python.useEnvironmentsExtension != false" } ], "menus": { diff --git a/package.nls.json b/package.nls.json index 81b8c1cb..f365cfa4 100644 --- a/package.nls.json +++ b/package.nls.json @@ -35,5 +35,6 @@ "python-envs.terminal.activate.title": "Activate Environment in Current Terminal", "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.revealProjectInExplorer.title": "Reveal Project in Explorer", + "python-envs.runPetInTerminal.title": "Run Python Environment Tool (PET) in Terminal" } diff --git a/src/extension.ts b/src/extension.ts index 4c5d596d..76944e93 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -12,6 +12,7 @@ import { createDeferred } from './common/utils/deferred'; import { activeTerminal, createLogOutputChannel, + createTerminal, onDidChangeActiveTerminal, onDidChangeTerminalShellIntegration, } from './common/window.apis'; @@ -66,7 +67,11 @@ import { ProjectItem } from './features/views/treeViewItems'; import { EnvironmentManagers, ProjectCreators, PythonProjectManager } from './internal.api'; import { registerSystemPythonFeatures } from './managers/builtin/main'; import { SysPythonManager } from './managers/builtin/sysPythonManager'; -import { createNativePythonFinder, NativePythonFinder } from './managers/common/nativePythonFinder'; +import { + createNativePythonFinder, + getNativePythonToolsPath, + NativePythonFinder, +} from './managers/common/nativePythonFinder'; import { IDisposable } from './managers/common/types'; import { registerCondaFeatures } from './managers/conda/main'; import { registerPoetryFeatures } from './managers/poetry/main'; @@ -429,6 +434,20 @@ export async function activate(context: ExtensionContext): Promise { + try { + const petPath = await getNativePythonToolsPath(); + const terminal = createTerminal({ + name: 'Python Environment Tool (PET)', + }); + terminal.show(); + terminal.sendText(`"${petPath}"`, true); + traceInfo(`Running PET in terminal: ${petPath}`); + } catch (error) { + traceError('Error running PET in terminal', error); + window.showErrorMessage(`Failed to run Python Environment Tool: ${error}`); + } + }), terminalActivation.onDidChangeTerminalActivationState(async (e) => { await setActivateMenuButtonContext(e.terminal, e.environment, e.activated); }), diff --git a/src/managers/common/nativePythonFinder.ts b/src/managers/common/nativePythonFinder.ts index a3630417..61f019ed 100644 --- a/src/managers/common/nativePythonFinder.ts +++ b/src/managers/common/nativePythonFinder.ts @@ -1,20 +1,20 @@ +import * as ch from 'child_process'; import * as fs from 'fs-extra'; import * as path from 'path'; +import { PassThrough } from 'stream'; +import { Disposable, ExtensionContext, LogOutputChannel, Uri } from 'vscode'; import * as rpc from 'vscode-jsonrpc/node'; -import * as ch from 'child_process'; +import { PythonProjectApi } from '../../api'; import { ENVS_EXTENSION_ID, PYTHON_EXTENSION_ID } from '../../common/constants'; import { getExtension } from '../../common/extension.apis'; -import { noop } from './utils'; -import { Disposable, ExtensionContext, LogOutputChannel, Uri } from 'vscode'; -import { PassThrough } from 'stream'; -import { PythonProjectApi } from '../../api'; -import { getConfiguration } from '../../common/workspace.apis'; -import { createRunningWorkerPool, WorkerPool } from '../../common/utils/workerPool'; import { traceVerbose } from '../../common/logging'; -import { isWindows } from '../../common/utils/platformUtils'; import { getUserHomeDir, untildify } from '../../common/utils/pathUtils'; +import { isWindows } from '../../common/utils/platformUtils'; +import { createRunningWorkerPool, WorkerPool } from '../../common/utils/workerPool'; +import { getConfiguration } from '../../common/workspace.apis'; +import { noop } from './utils'; -async function getNativePythonToolsPath(): Promise { +export async function getNativePythonToolsPath(): Promise { const envsExt = getExtension(ENVS_EXTENSION_ID); if (envsExt) { const petPath = path.join(envsExt.extensionPath, 'python-env-tools', 'bin', isWindows() ? 'pet.exe' : 'pet');