diff --git a/src/managers/builtin/main.ts b/src/managers/builtin/main.ts index 7171b78f..f9b588b5 100644 --- a/src/managers/builtin/main.ts +++ b/src/managers/builtin/main.ts @@ -9,6 +9,8 @@ import { UvProjectCreator } from './uvProjectCreator'; import { isUvInstalled } from './helpers'; import { createFileSystemWatcher, onDidDeleteFiles } from '../../common/workspace.apis'; import { createSimpleDebounce } from '../../common/utils/debounce'; +import { onDidEndTerminalShellExecution } from '../../common/window.apis'; +import { isPipInstallCommand } from './pipUtils'; export async function registerSystemPythonFeatures( nativeFinder: NativePythonFinder, @@ -43,6 +45,18 @@ export async function registerSystemPythonFeatures( }), ); + disposables.push( + onDidEndTerminalShellExecution(async (e) => { + const cwd = e.terminal.shellIntegration?.cwd; + if (isPipInstallCommand(e.execution.commandLine.value) && cwd) { + const env = await venvManager.get(cwd); + if (env) { + await pkgManager.refresh(env); + } + } + }), + ); + setImmediate(async () => { if (await isUvInstalled(log)) { disposables.push(api.registerPythonProjectCreator(new UvProjectCreator(api, log))); diff --git a/src/managers/builtin/pipUtils.ts b/src/managers/builtin/pipUtils.ts index c6912ab1..f41682c7 100644 --- a/src/managers/builtin/pipUtils.ts +++ b/src/managers/builtin/pipUtils.ts @@ -207,3 +207,17 @@ export async function getProjectInstallable( ); return installable; } + +export function isPipInstallCommand(command: string): boolean { + // Regex to match pip install commands, capturing variations like: + // pip install package + // python -m pip install package + // pip3 install package + // py -m pip install package + // pip install -r requirements.txt + // uv pip install package + // poetry run pip install package + // pipx run pip install package + // Any other tool that might wrap pip install + return /(?:^|\s)(?:\S+\s+)*(?:pip\d*)\s+(install|uninstall)\b/.test(command); +}