Skip to content

Pass the environment directory to uv package commands - #1742

Open
Eduardo Villalpando Mello (edvilme) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-package-manager-command-class-architecture
Open

Pass the environment directory to uv package commands#1742
Eduardo Villalpando Mello (edvilme) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-package-manager-command-class-architecture

Conversation

Copilot AI commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

UV-backed package operations were constructed with environment.execInfo.run.executable. For symlinked virtual environments (e.g. Pipenv), that executable can resolve to a uv-managed base interpreter, so uv pip install --python <exe> operated on the externally managed base interpreter instead of the selected environment.

uv accepts an environment directory as its --python target, so the fix is to hand UV commands environment.environmentPath.fsPath at the pip/uv boundary. Ordinary pip commands still need the interpreter executable.

Changes

  • src/managers/builtin/commands/factory.ts: when shouldUseUv(...) selects uv, construct the UV command with a copy of the options whose pythonExecutable is environmentPath. Pip commands keep the original options.
  • src/test/managers/builtin/commands.unit.test.ts: stub shouldUseUv once in the existing setup and add regression coverage that UV install/uninstall/list/direct-names all pass the environment directory after --python and never the base interpreter, and that pip still runs runPython with the original interpreter.
if (await shouldUseUv(options.log, environmentPath)) {
    // uv accepts an environment directory as its `--python` target. A symlinked
    // environment executable (for example Pipenv) can resolve to the externally
    // managed base interpreter, so passing the environment directory preserves
    // the environment boundary. Pip commands keep using the interpreter itself.
    return { kind: 'uv', command: new UvCommand({ ...options, pythonExecutable: environmentPath }) };
}
return { kind: 'pip', command: new PipCommand(options) };

Fixing this centrally covers every factory-created UV operation without touching each command class. Call sites were reviewed: UvVersionCommand (uv --version) and UvAvailableVersionsCommand (uv tool run pip index versions …) don't reference pythonExecutable in their arguments, so they're unaffected.

This adapts the intent of #1673 to the command-class refactor merged later in #1686.

Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix command class architecture for package-manager operations Pass the environment directory to uv package commands Aug 27, 2026
@edvilme
Eduardo Villalpando Mello (edvilme) marked this pull request as ready for review August 27, 2026 16:16
@edvilme

Copy link
Copy Markdown
Contributor

Fixes #1674

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue identified by VS Code Team member as probable bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants