mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-02 15:01:16 +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 {
|
||||
/// 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(
|
||||
python: Option<&str>,
|
||||
system: SystemPython,
|
||||
|
|
|
@ -20,9 +20,7 @@ use uv_configuration::{ConfigSettings, IndexStrategy, NoBinary, NoBuild, SetupPy
|
|||
use uv_dispatch::BuildDispatch;
|
||||
use uv_fs::Simplified;
|
||||
use uv_git::GitResolver;
|
||||
use uv_interpreter::{
|
||||
find_default_interpreter, find_interpreter, InterpreterRequest, SourceSelector,
|
||||
};
|
||||
use uv_interpreter::{PythonEnvironment, SystemPython};
|
||||
use uv_resolver::{ExcludeNewer, FlatIndex, InMemoryIndex, OptionsBuilder};
|
||||
use uv_types::{BuildContext, BuildIsolation, HashStrategy, InFlight};
|
||||
|
||||
|
@ -121,16 +119,15 @@ async fn venv_impl(
|
|||
cache: &Cache,
|
||||
printer: Printer,
|
||||
) -> miette::Result<ExitStatus> {
|
||||
// Locate the Python interpreter.
|
||||
let interpreter = if let Some(python) = python_request.as_ref() {
|
||||
let system = uv_interpreter::SystemPython::Required;
|
||||
let request = InterpreterRequest::parse(python);
|
||||
let sources = SourceSelector::from_settings(system, preview);
|
||||
find_interpreter(&request, system, &sources, cache)
|
||||
// Locate the Python interpreter to use in the environment
|
||||
// If a specific interpreter is requested, it is required to come from the system.
|
||||
// Otherwise, we'll allow the interpeter from a virtual environment to be used.
|
||||
let system = if python_request.is_some() {
|
||||
SystemPython::Required
|
||||
} else {
|
||||
find_default_interpreter(preview, cache)
|
||||
}
|
||||
.into_diagnostic()?
|
||||
SystemPython::Allowed
|
||||
};
|
||||
let interpreter = PythonEnvironment::find(python_request, system, preview, cache)
|
||||
.into_diagnostic()?
|
||||
.into_interpreter();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue