Skip to content

fix: detect terminal pip installs and refresh ui #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2025
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
14 changes: 14 additions & 0 deletions src/managers/builtin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)));
Expand Down
14 changes: 14 additions & 0 deletions src/managers/builtin/pipUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}