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

Use base Python for cached environments #11208

Merged
merged 1 commit into from
Feb 4, 2025
Merged

Use base Python for cached environments #11208

merged 1 commit into from
Feb 4, 2025

Conversation

charliermarsh
Copy link
Member

Summary

It turns out that we were returning slightly different interpreter paths on repeated uv run --with commands. This likely didn't affect many (or any?) users, but it does affect our test suite, since in the test suite, we use a symlinked interpreter.

The issue is that on first invocation, we create the virtual environment, and that returns the path to the python executable in the environment. On second invocation, we return the python3 executable, since that gets priority during discovery. This on its own is potentially ok. The issue is that these resolve to different sys._base_executable values in these flows... The latter gets the correct value (since it's read from the home key), but the former gets the incorrect value (since it's just the base_executable of the executable that created the virtualenv, which is the symlink).

We now use the same logic to determine the "cached interpreter" as in virtual environment creation, to ensure consistency between those paths.

@charliermarsh charliermarsh requested a review from zanieb February 4, 2025 01:21
@charliermarsh charliermarsh added the bug Something isn't working label Feb 4, 2025
Resolved 2 packages in [TIME]
Audited 1 package in [TIME]
Resolved 1 package in [TIME]
"###);
Copy link
Member Author

Choose a reason for hiding this comment

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

On main, this re-installs iniconfig.

/// considered the "base" for the virtual environment. This is typically the Python executable
/// from the [`Interpreter`]; however, if the interpreter is a virtual environment itself, then
/// the base Python executable is the Python executable of the interpreter's base interpreter.
pub fn to_base_python(&self) -> Result<PathBuf, io::Error> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Everything in this file is just moved from uv-virtualenv.

@charliermarsh charliermarsh merged commit 34552e2 into main Feb 4, 2025
73 checks passed
@charliermarsh charliermarsh deleted the charlie/base branch February 4, 2025 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants