Skip to content

[typespec-python] Add support for uv package manager alongside pip#3116

Merged
msyyc merged 6 commits intomainfrom
copilot/fix-3115
Jul 1, 2025
Merged

[typespec-python] Add support for uv package manager alongside pip#3116
msyyc merged 6 commits intomainfrom
copilot/fix-3115

Conversation

Copy link
Contributor

Copilot AI commented Jul 1, 2025

This PR adds support for the uv package manager alongside pip in the typespec-python scripts, resolving issues where the emitter would fail when working in uv-created virtual environments that don't have pip installed as a dependency.

Problem

Users working with tsp inside uv-created virtual environments encountered failures because the emitter hardcoded pip usage, even though uv could handle the package management more efficiently.

Solution

Implemented automatic package manager detection that:

  • Prefers uv when available (faster, more modern)
  • Falls back to pip when uv is not available
  • Maintains full backward compatibility with existing pip-only environments
  • Provides clear error messaging when no package manager is found

Changes Made

New Package Manager Abstraction (package_manager.py)

# Auto-detects best available package manager
package_manager = detect_package_manager()  # Returns 'uv', 'pip', or 'python -m pip'

# Provides unified installation interface
install_packages(['black'], package_manager)

Updated Installation Scripts

  • install.py: Now detects and uses either uv or pip for package installations
  • prepare.py: Uses package manager abstraction for dev requirements installation
  • venvtools.py: Simplified by removing redundant functions while maintaining compatibility
  • run_tsp.py: Made error message package manager agnostic

Usage Examples

With uv available:

# Automatically uses uv commands (faster)
uv pip install -U black

With only pip available:

# Falls back to pip (unchanged behavior)
pip install -U black

Benefits

  • uv environments work out of the box - no need to install pip as dependency
  • Performance improvement - uv installations are significantly faster
  • Zero breaking changes - existing pip workflows unchanged
  • Better error messages - clearer guidance when package managers unavailable

Testing

Comprehensive testing validates:

  • Package manager detection across different environments
  • Command generation for both uv and pip
  • Integration with all modified scripts
  • Backward compatibility with pip-only setups
  • End-to-end workflow functionality

Fixes #3115.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copilot AI changed the title [WIP] [Copilot] Add support for uv package manager alongside pip [typespec-python] Add support for uv package manager alongside pip Jul 1, 2025
Copilot finished work on behalf of msyyc July 1, 2025 02:40
Copilot AI requested a review from msyyc July 1, 2025 02:40
@msyyc
Copy link
Member

msyyc commented Jul 1, 2025

fix microsoft/typespec#7502

@msyyc msyyc marked this pull request as ready for review July 1, 2025 03:01
@msyyc msyyc requested review from iscai-msft and tadelesh as code owners July 1, 2025 03:01
msyyc and others added 3 commits July 1, 2025 03:03
…traction

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 1, 2025

fix microsoft/typespec#7502

Fixed TypeSpec issue #7502 by completing the uv package manager support. Updated run_tsp.py to use the package manager abstraction instead of hardcoded pip dependency, ensuring the emitter works seamlessly in uv-created virtual environments. (58bfc70)

Copilot finished work on behalf of msyyc July 1, 2025 03:07
@msyyc msyyc enabled auto-merge (squash) July 1, 2025 03:24
@msyyc msyyc merged commit 7bc84fc into main Jul 1, 2025
14 checks passed
@msyyc msyyc deleted the copilot/fix-3115 branch July 1, 2025 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Copilot] Add support for uv package manager alongside pip

3 participants