mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-03 07:14:35 +00:00
Use PythonEnvironment
API in uv venv
(#4029)
There's no reason to be reaching into the lower-level `find_interpreter` manually here.
This commit is contained in:
parent
b05a39c735
commit
db3c36dbcc
2 changed files with 14 additions and 15 deletions
|
@ -26,7 +26,9 @@ struct PythonEnvironmentShared {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PythonEnvironment {
|
impl PythonEnvironment {
|
||||||
/// Create a [`PythonEnvironment`] from a user request.
|
/// Find a [`PythonEnvironment`].
|
||||||
|
///
|
||||||
|
/// This is the standard interface for discovering a Python environment for use with uv.
|
||||||
pub fn find(
|
pub fn find(
|
||||||
python: Option<&str>,
|
python: Option<&str>,
|
||||||
system: SystemPython,
|
system: SystemPython,
|
||||||
|
|
|
@ -20,9 +20,7 @@ use uv_configuration::{ConfigSettings, IndexStrategy, NoBinary, NoBuild, SetupPy
|
||||||
use uv_dispatch::BuildDispatch;
|
use uv_dispatch::BuildDispatch;
|
||||||
use uv_fs::Simplified;
|
use uv_fs::Simplified;
|
||||||
use uv_git::GitResolver;
|
use uv_git::GitResolver;
|
||||||
use uv_interpreter::{
|
use uv_interpreter::{PythonEnvironment, SystemPython};
|
||||||
find_default_interpreter, find_interpreter, InterpreterRequest, SourceSelector,
|
|
||||||
};
|
|
||||||
use uv_resolver::{ExcludeNewer, FlatIndex, InMemoryIndex, OptionsBuilder};
|
use uv_resolver::{ExcludeNewer, FlatIndex, InMemoryIndex, OptionsBuilder};
|
||||||
use uv_types::{BuildContext, BuildIsolation, HashStrategy, InFlight};
|
use uv_types::{BuildContext, BuildIsolation, HashStrategy, InFlight};
|
||||||
|
|
||||||
|
@ -121,16 +119,15 @@ async fn venv_impl(
|
||||||
cache: &Cache,
|
cache: &Cache,
|
||||||
printer: Printer,
|
printer: Printer,
|
||||||
) -> miette::Result<ExitStatus> {
|
) -> miette::Result<ExitStatus> {
|
||||||
// Locate the Python interpreter.
|
// Locate the Python interpreter to use in the environment
|
||||||
let interpreter = if let Some(python) = python_request.as_ref() {
|
// If a specific interpreter is requested, it is required to come from the system.
|
||||||
let system = uv_interpreter::SystemPython::Required;
|
// Otherwise, we'll allow the interpeter from a virtual environment to be used.
|
||||||
let request = InterpreterRequest::parse(python);
|
let system = if python_request.is_some() {
|
||||||
let sources = SourceSelector::from_settings(system, preview);
|
SystemPython::Required
|
||||||
find_interpreter(&request, system, &sources, cache)
|
|
||||||
} else {
|
} else {
|
||||||
find_default_interpreter(preview, cache)
|
SystemPython::Allowed
|
||||||
}
|
};
|
||||||
.into_diagnostic()?
|
let interpreter = PythonEnvironment::find(python_request, system, preview, cache)
|
||||||
.into_diagnostic()?
|
.into_diagnostic()?
|
||||||
.into_interpreter();
|
.into_interpreter();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue