Skip to content

Pass the environment directory to uv package commands - #1742

Merged
Eduardo Villalpando Mello (edvilme) merged 2 commits into
mainfrom
copilot/fix-package-manager-command-class-architecture
Aug 28, 2026
Merged

Pass the environment directory to uv package commands#1742
Eduardo Villalpando Mello (edvilme) merged 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

@StellaHuang95

Stella Huang (StellaHuang95) commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

🔒 Automated review in progress — Stella Huang (@StellaHuang95) is auto-reviewing this PR.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning · Non-blocking recommendation

📍 src/managers/builtin/commands/factory.ts:17
pythonExecutable now represents either an executable or, for UV, an environment directory. This is safe for current commands but weakens the constructor contract; track a follow-up to introduce an accurately named UV target before future commands assume this value is executable.

[verified]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

@StellaHuang95 Stella Huang (StellaHuang95) added the review-auto:approved Automated review: no blocking findings (approval posted). label Aug 28, 2026
@edvilme
Eduardo Villalpando Mello (edvilme) merged commit 7b1e096 into main Aug 28, 2026
85 of 86 checks passed
@edvilme
Eduardo Villalpando Mello (edvilme) deleted the copilot/fix-package-manager-command-class-architecture branch August 28, 2026 17:27
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 review-auto:approved Automated review: no blocking findings (approval posted).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants