-
Notifications
You must be signed in to change notification settings - Fork 415
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
Add internal options for managing toolchain discovery preferences #4416
Conversation
028ae18
to
c0411bf
Compare
c0411bf
to
0edfbad
Compare
× No interpreter found for Python 3.100 in search path | ||
× No interpreter found for Python 3.100 in system toolchains |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is less clear but will address separately.
crates/uv/tests/pip_sync.rs
Outdated
success: false | ||
exit_code: 2 | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
error: No Python interpreters found in virtual environments | ||
Resolved 1 package in [TIME] | ||
Audited 1 package in [TIME] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting regression... will investigate this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are not properly isolated from managed toolchains because they aren't following our TestContext
pattern :sigh:
if let Some(request) = python { | ||
Self::find_requested(&request, system, preview, cache) | ||
} else if system.is_preferred() { | ||
Self::find_default(preview, cache) | ||
} else { | ||
// First check for a parent interpreter | ||
// We gate this check to avoid an extra log message when it is not set | ||
if std::env::var_os("UV_INTERNAL__PARENT_INTERPRETER").is_some() { | ||
match Self::find_parent_interpreter(system, cache) { | ||
Ok(env) => return Ok(env), | ||
Err(Error::NotFound(_)) => {} | ||
Err(err) => return Err(err), | ||
} | ||
} | ||
|
||
// Then a virtual environment | ||
match Self::find_virtualenv(cache) { | ||
Ok(venv) => Ok(venv), | ||
Err(Error::NotFound(_)) if system.is_allowed() => { | ||
Self::find_default(preview, cache) | ||
} | ||
Err(err) => Err(err), | ||
} | ||
} | ||
let request = python.unwrap_or_default(); | ||
Self::find_requested(&request, environments, preference, cache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a big plus. We don't need to do multiple discovery attempts to get a different ordering. We just say what we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it.
0edfbad
to
82af472
Compare
.env("UV_TEST_PYTHON_PATH", &context.python_path()) | ||
.env("UV_TOOLCHAIN_DIR", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addresses #4416 (comment)
In preparation for changing the order dynamically in #4416
82af472
to
e722d0e
Compare
e722d0e
to
f971ee4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Was this the refactor you were talking about in DMs? I know you mentioned it being exploratory, but one thing that I find can help here is to put things like type/function renames into one commit separate from the other changes. The renames can touch a lot of code and add a lot of noise to the diff. When split out, the "more interesting" changes can be seen in a different commit.
(I know this isn't always feasible, especially in a more exploratory refactor. But I thought it might be valuable to throw it out there.)
if let Some(request) = python { | ||
Self::find_requested(&request, system, preview, cache) | ||
} else if system.is_preferred() { | ||
Self::find_default(preview, cache) | ||
} else { | ||
// First check for a parent interpreter | ||
// We gate this check to avoid an extra log message when it is not set | ||
if std::env::var_os("UV_INTERNAL__PARENT_INTERPRETER").is_some() { | ||
match Self::find_parent_interpreter(system, cache) { | ||
Ok(env) => return Ok(env), | ||
Err(Error::NotFound(_)) => {} | ||
Err(err) => return Err(err), | ||
} | ||
} | ||
|
||
// Then a virtual environment | ||
match Self::find_virtualenv(cache) { | ||
Ok(venv) => Ok(venv), | ||
Err(Error::NotFound(_)) if system.is_allowed() => { | ||
Self::find_default(preview, cache) | ||
} | ||
Err(err) => Err(err), | ||
} | ||
} | ||
let request = python.unwrap_or_default(); | ||
Self::find_requested(&request, environments, preference, cache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it.
Yeah this is a part of what I was mentioning. A lot of the exploration is figuring out how to add this setting while moving the API towards something that's easy to use correctly. I generally do try to split out renames, but yeah I didn't do a great job of that here :) |
Restores the `PythonEnvironment::find` API which was removed a while back in favor of `Toolchain::find`. As mentioned in #4416, I'm attempting to separate the case where you want an active environment from the case where you want an installed toolchain in order to create environments. I wanted to drop `EnvironmentPreference` from `Toolchain::find` and just have us consistently consider (or not consider) virtual environments when discovering toolchains for creating environments. Unfortunately this caused a few things to break so I reverted that change and will explore it separately. Because I was exploring that change, there are some minor changes to the `Toolchain` API here.
In preparation for changing the order dynamically in astral-sh#4416
…tral-sh#4416) Adds support for the toolchain discovery preferences outlined in astral-sh#4198 but we don't expose this to users yet, I'll do that next to make it easier to review. I've made some refactors in the toolchain discovery implementation to enable this behavior and move us towards clearer abstractions. There's still remaining work here, but I'd prefer tackle things in follow-ups instead of expanding this pull request. I plan on opening a couple before merging this. I'd like to shift the public toolchain API to focus on discovering either an **environment** or a **toolchain**. The first would be used by commands that operate on an environment, while the latter would be used by commands that just need an interpreter to create environments. I haven't changed this here, but some of the refactors are in preparation for supporting this idea. In brief: - We now allow different ordering of installed toolchain discovery based on a `ToolchainPreference` type. This is the type we will expose to users. - `SystemPython` was changed into an `EnvironmentPreference` which is used to determine if we should prefer virtual or system Python environments. - We drop the whole `ToolchainSources` selection concept, it was confusing and the error messages from it were awkward. Most of the functionality is now captured by the preference enums, but you can't do things like "only find a toolchain from the parent interpreter" as easily anymore.
Restores the `PythonEnvironment::find` API which was removed a while back in favor of `Toolchain::find`. As mentioned in astral-sh#4416, I'm attempting to separate the case where you want an active environment from the case where you want an installed toolchain in order to create environments. I wanted to drop `EnvironmentPreference` from `Toolchain::find` and just have us consistently consider (or not consider) virtual environments when discovering toolchains for creating environments. Unfortunately this caused a few things to break so I reverted that change and will explore it separately. Because I was exploring that change, there are some minor changes to the `Toolchain` API here.
Adds support for the toolchain discovery preferences outlined in #4198 but we don't expose this to users yet, I'll do that next to make it easier to review.
I've made some refactors in the toolchain discovery implementation to enable this behavior and move us towards clearer abstractions. There's still remaining work here, but I'd prefer tackle things in follow-ups instead of expanding this pull request. I plan on opening a couple before merging this.
I'd like to shift the public toolchain API to focus on discovering either an environment or a toolchain. The first would be used by commands that operate on an environment, while the latter would be used by commands that just need an interpreter to create environments. I haven't changed this here, but some of the refactors are in preparation for supporting this idea.
In brief:
ToolchainPreference
type. This is the type we will expose to users.SystemPython
was changed into anEnvironmentPreference
which is used to determine if we should prefer virtual or system Python environments.ToolchainSources
selection concept, it was confusing and the error messages from it were awkward. Most of the functionality is now captured by the preference enums, but you can't do things like "only find a toolchain from the parent interpreter" as easily anymore.