Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 14, 2025

Overview

This PR implements support for UV-created virtual environments and adds a new setting to control when UV is used for managing virtual environments, as requested in the issue.

Changes

1. New Environment Kind: VenvUv

Added venvUv = 'Uv' to the NativePythonEnvironmentKind enum to represent virtual environments created with UV. This tag comes from PET's native locator when it detects uv_version in the pyvenv.cfg file.

2. New Setting: python-envs.alwaysUseUv

{
  "python-envs.alwaysUseUv": {
    "type": "boolean",
    "default": true,
    "scope": "machine",
    "description": "When set to true, uv will be used to manage all virtual environments if available. When set to false, uv will only manage virtual environments explicitly created by uv."
  }
}

3. Smart UV Detection Logic

Introduced a shouldUseUv() helper function that determines when to use UV:

  • VenvUv environments: Always use UV (if installed), regardless of the setting
  • Other environments: Use UV only if alwaysUseUv setting is true (if installed)

This ensures that UV-created environments always use UV for management, while giving users control over whether UV should manage standard venvs.

4. Updated Operations

All virtual environment and pip operations now respect the new setting:

  • Environment Discovery: findVirtualEnvironments() and resolveVenvPythonEnvironmentPath() now handle both Venv and Uv kinds
  • Environment Creation: createWithProgress() uses the setting to decide between uv venv and python -m venv
  • Package Management: refreshPipPackagesRaw() and managePackages() use the setting to decide between uv pip and python -m pip

Behavior

Environment Type alwaysUseUv = true alwaysUseUv = false
VenvUv (UV-created) ✅ Use UV ✅ Use UV
Venv (standard) ✅ Use UV ❌ Don't use UV

Copilot AI changed the title [WIP] Add setting to toggle using uv for venvs and support new uv tag Add VenvUv support and alwaysUseUv setting to control UV usage for virtual environments Oct 14, 2025
Copilot AI requested a review from eleanorjboyd October 14, 2025 02:18
Copilot finished work on behalf of eleanorjboyd October 14, 2025 02:18
Copilot AI and others added 8 commits October 16, 2025 16:06
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
@eleanorjboyd eleanorjboyd force-pushed the copilot/add-toggle-for-uv-venvs branch from 3a25051 to 11bfc6e Compare October 16, 2025 23:06
@eleanorjboyd eleanorjboyd added the feature-request Request for new features or functionality label Oct 17, 2025
@eleanorjboyd eleanorjboyd marked this pull request as ready for review October 17, 2025 20:48
@vs-code-engineering vs-code-engineering bot added this to the October 2025 milestone Oct 17, 2025
@eleanorjboyd eleanorjboyd removed their request for review October 17, 2025 22:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for UV-created virtual environments and introduces a configurable setting to control when UV is used for managing virtual environments. The implementation allows UV to always manage environments it creates while giving users control over whether UV manages standard venvs.

Key changes:

  • Added VenvUv environment kind to distinguish UV-created virtual environments
  • Introduced python-envs.alwaysUseUv setting (default: true) to control UV usage for non-UV environments
  • Implemented UV environment tracking system using persistent state
  • Updated all virtual environment operations to respect the new setting and environment type

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/managers/common/nativePythonFinder.ts Added venvUv enum value to identify UV-created environments
src/managers/builtin/uvEnvironments.ts New module implementing UV environment tracking with persistent state
src/managers/builtin/helpers.ts Added shouldUseUv() function and cache reset capability for UV detection
src/managers/builtin/venvUtils.ts Updated environment discovery, creation, and removal to handle UV environments
src/managers/builtin/utils.ts Updated package management operations to use the new UV detection logic
src/managers/builtin/pipManager.ts Reordered imports (no functional change)
package.json Added alwaysUseUv setting configuration
package.nls.json Added localization string for the new setting
src/test/managers/builtin/venvUtils.uvTracking.unit.test.ts Comprehensive tests for UV environment tracking functions
src/test/managers/builtin/helpers.shouldUseUv.unit.test.ts Tests for UV usage decision logic with various scenarios
src/test/managers/builtin/helpers.isUvInstalled.unit.test.ts Tests for UV installation detection and caching
.github/instructions/testing-workflow.instructions.md Added testing guidelines and learnings from this implementation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@eleanorjboyd
Copy link
Member

update to just search for Uv as tag from native locator to align with microsoft/python-environment-tools#263

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

Labels

feature-request Request for new features or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants