Update the Toolchain::find_requested API to take a parsed request (#4215)

Pulled out of https://github.com/astral-sh/uv/pull/4206, need this for
#4214
This commit is contained in:
Zanie Blue 2024-06-10 16:07:45 -04:00 committed by GitHub
parent d7e10bb4a2
commit fd52fe74ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 6 deletions

View file

@ -33,7 +33,8 @@ impl Toolchain {
cache: &Cache, cache: &Cache,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
if let Some(python) = python { if let Some(python) = python {
Self::find_requested(python, system, preview, cache) let request = ToolchainRequest::parse(python);
Self::find_requested(&request, system, preview, cache)
} else if system.is_preferred() { } else if system.is_preferred() {
Self::find_default(preview, cache) Self::find_default(preview, cache)
} else { } else {
@ -60,14 +61,13 @@ impl Toolchain {
/// Find an installed [`Toolchain`] that satisfies a request. /// Find an installed [`Toolchain`] that satisfies a request.
pub fn find_requested( pub fn find_requested(
request: &str, request: &ToolchainRequest,
system: SystemPython, system: SystemPython,
preview: PreviewMode, preview: PreviewMode,
cache: &Cache, cache: &Cache,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let sources = ToolchainSources::from_settings(system, preview); let sources = ToolchainSources::from_settings(system, preview);
let request = ToolchainRequest::parse(request); let toolchain = find_toolchain(request, system, &sources, cache)??;
let toolchain = find_toolchain(&request, system, &sources, cache)??;
Ok(toolchain) Ok(toolchain)
} }

View file

@ -161,7 +161,8 @@ pub(crate) async fn pip_compile(
SystemPython::Allowed SystemPython::Allowed
}; };
let interpreter = if let Some(python) = python.as_ref() { let interpreter = if let Some(python) = python.as_ref() {
Toolchain::find_requested(python, system, preview, &cache) let request = ToolchainRequest::parse(python);
Toolchain::find_requested(&request, system, preview, &cache)
} else { } else {
// TODO(zanieb): The split here hints at a problem with the abstraction; we should be able to use // TODO(zanieb): The split here hints at a problem with the abstraction; we should be able to use
// `Toolchain::find(...)` here. // `Toolchain::find(...)` here.

View file

@ -49,7 +49,8 @@ pub(crate) async fn lock(
if request.satisfied(&interpreter, cache) { if request.satisfied(&interpreter, cache) {
interpreter interpreter
} else { } else {
Toolchain::find_requested(python, SystemPython::Allowed, preview, cache)? let request = ToolchainRequest::parse(python);
Toolchain::find_requested(&request, SystemPython::Allowed, preview, cache)?
.into_interpreter() .into_interpreter()
} }
} else { } else {