Skip to content

Commit 388a30e

Browse files
karthiknadigeleanorjboyd
authored andcommitted
fix: detect terminal pip installs and refresh ui (#316)
fixes: #57
1 parent 57b187d commit 388a30e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/managers/builtin/main.ts

+14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { UvProjectCreator } from './uvProjectCreator';
99
import { isUvInstalled } from './helpers';
1010
import { createFileSystemWatcher, onDidDeleteFiles } from '../../common/workspace.apis';
1111
import { createSimpleDebounce } from '../../common/utils/debounce';
12+
import { onDidEndTerminalShellExecution } from '../../common/window.apis';
13+
import { isPipInstallCommand } from './pipUtils';
1214

1315
export async function registerSystemPythonFeatures(
1416
nativeFinder: NativePythonFinder,
@@ -43,6 +45,18 @@ export async function registerSystemPythonFeatures(
4345
}),
4446
);
4547

48+
disposables.push(
49+
onDidEndTerminalShellExecution(async (e) => {
50+
const cwd = e.terminal.shellIntegration?.cwd;
51+
if (isPipInstallCommand(e.execution.commandLine.value) && cwd) {
52+
const env = await venvManager.get(cwd);
53+
if (env) {
54+
await pkgManager.refresh(env);
55+
}
56+
}
57+
}),
58+
);
59+
4660
setImmediate(async () => {
4761
if (await isUvInstalled(log)) {
4862
disposables.push(api.registerPythonProjectCreator(new UvProjectCreator(api, log)));

src/managers/builtin/pipUtils.ts

+14
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,17 @@ export async function getProjectInstallable(
214214
);
215215
return installable;
216216
}
217+
218+
export function isPipInstallCommand(command: string): boolean {
219+
// Regex to match pip install commands, capturing variations like:
220+
// pip install package
221+
// python -m pip install package
222+
// pip3 install package
223+
// py -m pip install package
224+
// pip install -r requirements.txt
225+
// uv pip install package
226+
// poetry run pip install package
227+
// pipx run pip install package
228+
// Any other tool that might wrap pip install
229+
return /(?:^|\s)(?:\S+\s+)*(?:pip\d*)\s+(install|uninstall)\b/.test(command);
230+
}

0 commit comments

Comments
 (0)