Skip to content
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

Allow passing a venv to uv pip --python #3064

Merged
merged 6 commits into from
Apr 16, 2024

Conversation

pfmoore
Copy link
Contributor

@pfmoore pfmoore commented Apr 16, 2024

Fixes #3060

Summary

Allows passing a virtual environment (the path to the directory, rather than the path to the Python interpreter within the directory) to the --python option of the uv pip command.

Test Plan

Tested manually to confirm that the expected new functionality works. The test suite still passes after this change.

I don't know how to add tests for a new feature like this. I would be happy to do so if someone can give me some pointers on how to do it.

@charliermarsh charliermarsh self-assigned this Apr 16, 2024
@charliermarsh charliermarsh added the enhancement New feature or request label Apr 16, 2024
Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

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

Thanks! I tweaked the control flow to use a single metadata lookup.

@charliermarsh
Copy link
Member

I think this also closes #3062?

};
Interpreter::query(executable, cache).map(Some)
}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
Copy link
Member

Choose a reason for hiding this comment

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

We could consider erroring here if the request contains a separator, though I suppose it's not strictly necessary? The error in that case looks like error: Failed to locate Python interpreter at .venv/foo/python`` already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I don't think it's worth a special check.

@charliermarsh charliermarsh changed the title Allow passing a venv to uv pip --python Allow passing a venv to uv pip --python Apr 16, 2024
@charliermarsh
Copy link
Member

Will fix the failure, need #3072 first.

@charliermarsh charliermarsh enabled auto-merge (squash) April 16, 2024 18:33
@charliermarsh charliermarsh merged commit 8e37625 into astral-sh:main Apr 16, 2024
38 checks passed
Cow::Owned(path.join("Scripts/python.exe"))
} else {
Cow::Owned(path.join("bin/python"))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't personally care, but this probably won't handle environments like cygwin or mingw64, as I think they use a bin directory, because they are emulating Unix. They will presumably still have a .exe suffix, though, as that's a Windows requirement.

I suspect it's better to ignore this problem until someone using one of those environments speaks up, because they will be able to give better information than my guesses...

Copy link
Member

Choose a reason for hiding this comment

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

Yeah makes total sense. I think we already have this problem in a few places so I'm okay with using the same pattern until we fix it holistically...

Copy link
Contributor Author

@pfmoore pfmoore left a comment

Choose a reason for hiding this comment

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

Looks like you merged while I was commenting!

@pfmoore pfmoore deleted the python_venv branch April 16, 2024 18:45
@charliermarsh
Copy link
Member

Oh sorry, I set to auto-merge.

@pfmoore
Copy link
Contributor Author

pfmoore commented Apr 16, 2024

Not a problem. And thanks for (improving and) merging this - glad my beginner-level Rust was worth it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow the --python flag in uv pip install to take the location of a venv
2 participants