Skip to content

python: add uv to New Project Wizard #7723

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 11 commits into from
May 22, 2025
Merged

python: add uv to New Project Wizard #7723

merged 11 commits into from
May 22, 2025

Conversation

austin3dickey
Copy link
Contributor

@austin3dickey austin3dickey commented May 15, 2025

Addresses #5165.

This PR adds support for using uv, if it's installed, to create venvs in:

  • the New Project Wizard when you create a Python project
  • the Python: Create Environment and Python: Select Interpreter commands

Release Notes

New Features

Bug Fixes

  • N/A

QA Notes

I added a new e2e test in this PR.

When testing this, try out a few scenarios:

  • on different OSes (I haven't tried Windows yet 🙏)
  • create it as a git workspace or not
  • try selecting a couple different Python versions
  • try without uv installed on your system; you should get an informative error
  • try the two Python: commands I mentioned above

@:extensions @:new-project-wizard @:vscode-settings @:win

Copy link

github-actions bot commented May 15, 2025

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:extensions @:new-project-wizard @:vscode-settings @:win

readme  valid tags

Copy link
Contributor

@Copilot 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 using uv as an option for creating Python virtual environments in the New Project Wizard and via Python commands. Key changes include updating configuration options and state management to include uv, introducing new utilities and a uv creation provider, and updating test and command registrations to support uv.

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

File Description
test/e2e/pages/newProjectWizard.ts Updated test options to include uv for Python environment creation.
src/vs/workbench/services/positronNewProjectService.ts Updated service to check for uvPythonVersion in the project configuration.
src/vs/workbench/browser/positronNewProjectWizard/* Added and updated utilities, state management, and components to support uv environments.
extensions/positron-python/* Integrated uv support in environment creation, provider registration, and command definitions.
Comments suppressed due to low confidence (1)

src/vs/workbench/browser/positronNewProjectWizard/utilities/pythonEnvironmentStepUtils.ts:31

  • [nitpick] Using '.venv' as the default directory for non-Conda providers means that uv environments will share the same folder name as venv environments. Consider using a distinct folder name (e.g., '.uv') for uv environments if that aligns with the design requirements.
const envDir = envProviderName === PythonEnvironmentProvider.Conda ? '.conda' : '.venv';

@austin3dickey austin3dickey changed the title WIP: python: add uv to New Project Wizard python: add uv to New Project Wizard May 16, 2025
@austin3dickey austin3dickey marked this pull request as ready for review May 16, 2025 19:21
Copy link
Contributor

@isabelizimm isabelizimm left a comment

Choose a reason for hiding this comment

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

Tried things out a bit for a first pass-- this is looking great! Everything seems to work as I expect.

Some thoughts for you to consider: would it be possible to hide uv as an option from the dropdown if it is not installed, rather than showing it and then giving an error? Alternatively (or maybe additionally), could uv be moved to the bottom of the list so venv can have the top spot? We know everyone who has Python will have venv, but not everyone will have uv.

I'll look through the actual code on Monday for feedback there.

@austin3dickey
Copy link
Contributor Author

yes - hiding it from the list is a great idea!

Testing it locally, it feels like a much better experience than venv. I didn't even have to implement the progress-tracking functionality that venv and conda do, because it only takes a moment to generate the environment. So I think if it's installed, I'd rather keep it at the top as the recommended selection.

testlabauto
testlabauto previously approved these changes May 19, 2025
Copy link
Contributor

@testlabauto testlabauto left a comment

Choose a reason for hiding this comment

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

E2E test looks great! I will check later this week if we can turn it and the others in the file on for WEB.

type: ProjectType.PYTHON_PROJECT,
title: projectTitle,
status: 'new',
pythonEnv: 'uv', // test relies on uv already installed on machine
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have uv in all our CI tests now, or will we need to add it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's in all our testing setups now 💜 thanks @testlabauto !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I just found out it's not on windows. So now we don't run this test on windows. This seems like a good forcing function for me to set up my new windows laptop and test this out :)

@isabelizimm
Copy link
Contributor

Ah-- it looks like we do not have precedent for hiding if uninstalled: see Conda below. With that in mind, if it's a pain, I think it's fine if we change that in a follow up PR.

Screenshot 2025-05-19 at 3 41 17 PM

@austin3dickey
Copy link
Contributor Author

if it's a pain, I think it's fine if we change that in a follow up PR.

Right, your comment reminded me that's why I did this in the first place 😂 I still think it's strange to have the first thing that shows up not work, so it shouldn't be too hard to just reorder to venv first if uv doesn't exist.

Copy link
Member

@sharon-wang sharon-wang left a comment

Choose a reason for hiding this comment

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

This is working well for me on Desktop and Server Web on Mac 👌 The .venv creation feels almost instant ⚡

One more test update! Could you please update extensions/positron-python/src/test/positron/createEnvApi.unit.test.ts to include a couple Uv additions:

    const envOptionsWithInfo = {
        withInterpreterPath: { ...envOptions },
        withCondaPythonVersion: { ...envOptions, interpreterPath: undefined, condaPythonVersion: '3.12' },
        withUvPythonVersion: { ...envOptions, interpreterPath: undefined, uvPythonVersion: '3.13' }, // <-- add this line
    };
    const envOptionsMissingInfo = {
        noProviderId: { ...envOptions, providerId: undefined },
        noPythonSpecified: { ...envOptions, interpreterPath: undefined, condaPythonVersion: undefined, uvPythonVersion: undefined }, // <-- add `uvPythonVersion` here
    };

If you'd like some Windows testing before merging, we could run the @:win suite on this PR

@austin3dickey
Copy link
Contributor Author

Cool, I was able to implement "put uv at the bottom of the list if it's not installed" and "flesh out the unit tests some more". Thanks for the feedback! Check it out whenever you have a chance

@jonvanausdeln
Copy link
Contributor

I just tried on Windows 11 and it looks good! I checked:

  • Golden Path, creating a new UV project
  • New project git init
  • 3 different Python versions

I did not try without uv installed.

isabelizimm
isabelizimm previously approved these changes May 21, 2025
Copy link
Contributor

@isabelizimm isabelizimm left a comment

Choose a reason for hiding this comment

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

lgtm with the new changes! 👾

Copy link
Member

@sharon-wang sharon-wang left a comment

Choose a reason for hiding this comment

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

some small things, otherwise LGTM too!

sharon-wang
sharon-wang previously approved these changes May 22, 2025
Copy link
Member

@sharon-wang sharon-wang left a comment

Choose a reason for hiding this comment

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

LGTM!

@austin3dickey austin3dickey merged commit 5a5a664 into main May 22, 2025
28 checks passed
@austin3dickey austin3dickey deleted the aus/uvw branch May 22, 2025 19:11
@github-actions github-actions bot locked and limited conversation to collaborators May 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants