mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-03 07:14:35 +00:00
Refactor project interpreter request for requires-python
specifiers (#4216)
Refactor following #4214 to avoid parsing the specifiers again
This commit is contained in:
parent
68abf85f0d
commit
f296ef08d6
1 changed files with 20 additions and 10 deletions
|
@ -21,7 +21,7 @@ use uv_git::GitResolver;
|
||||||
use uv_installer::{SatisfiesResult, SitePackages};
|
use uv_installer::{SatisfiesResult, SitePackages};
|
||||||
use uv_requirements::{RequirementsSource, RequirementsSpecification};
|
use uv_requirements::{RequirementsSource, RequirementsSpecification};
|
||||||
use uv_resolver::{FlatIndex, InMemoryIndex, Options, RequiresPython};
|
use uv_resolver::{FlatIndex, InMemoryIndex, Options, RequiresPython};
|
||||||
use uv_toolchain::{PythonEnvironment, SystemPython, Toolchain, ToolchainRequest};
|
use uv_toolchain::{PythonEnvironment, SystemPython, Toolchain, ToolchainRequest, VersionRequest};
|
||||||
use uv_types::{BuildIsolation, HashStrategy, InFlight};
|
use uv_types::{BuildIsolation, HashStrategy, InFlight};
|
||||||
use uv_warnings::warn_user;
|
use uv_warnings::warn_user;
|
||||||
|
|
||||||
|
@ -125,15 +125,25 @@ pub(crate) fn init_environment(
|
||||||
Err(e) => return Err(e.into()),
|
Err(e) => return Err(e.into()),
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(konsti): Extend `VersionRequest` to support `VersionSpecifiers`.
|
let interpreter = if let Some(request) = python.map(ToolchainRequest::parse).or(requires_python
|
||||||
let requires_python_str = requires_python.map(ToString::to_string);
|
.map(|specifiers| ToolchainRequest::Version(VersionRequest::Range(specifiers.clone()))))
|
||||||
let interpreter = Toolchain::find(
|
{
|
||||||
python.or(requires_python_str.as_deref()),
|
Toolchain::find_requested(
|
||||||
|
&request,
|
||||||
// Otherwise we'll try to use the venv we just deleted.
|
// Otherwise we'll try to use the venv we just deleted.
|
||||||
SystemPython::Required,
|
SystemPython::Required,
|
||||||
preview,
|
preview,
|
||||||
cache,
|
cache,
|
||||||
)?
|
)
|
||||||
|
} else {
|
||||||
|
Toolchain::find(
|
||||||
|
None,
|
||||||
|
// Otherwise we'll try to use the venv we just deleted.
|
||||||
|
SystemPython::Required,
|
||||||
|
preview,
|
||||||
|
cache,
|
||||||
|
)
|
||||||
|
}?
|
||||||
.into_interpreter();
|
.into_interpreter();
|
||||||
|
|
||||||
if let Some(requires_python) = requires_python {
|
if let Some(requires_python) = requires_python {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue