Rename `project::FoundInterpreter` to `ProjectInterpreter` (#7874)

This commit is contained in:
Zanie Blue 2024-10-02 13:10:29 -05:00 committed by GitHub
parent 5ff7dc99cb
commit 64c74ac552
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 14 deletions

View File

@ -18,7 +18,7 @@ use uv_workspace::{DiscoveryOptions, MemberDiscovery, VirtualProject, Workspace}
use crate::commands::pip::loggers::DefaultResolveLogger;
use crate::commands::project::lock::do_safe_lock;
use crate::commands::project::{FoundInterpreter, ProjectError};
use crate::commands::project::{ProjectError, ProjectInterpreter};
use crate::commands::{diagnostics, pip, ExitStatus, OutputWriter};
use crate::printer::Printer;
use crate::settings::ResolverSettings;
@ -74,7 +74,7 @@ pub(crate) async fn export(
};
// Find an interpreter for the project
let interpreter = FoundInterpreter::discover(
let interpreter = ProjectInterpreter::discover(
project.workspace(),
python.as_deref().map(PythonRequest::parse),
python_preference,

View File

@ -35,7 +35,9 @@ use uv_warnings::{warn_user, warn_user_once};
use uv_workspace::{DiscoveryOptions, Workspace};
use crate::commands::pip::loggers::{DefaultResolveLogger, ResolveLogger, SummaryResolveLogger};
use crate::commands::project::{find_requires_python, FoundInterpreter, ProjectError, SharedState};
use crate::commands::project::{
find_requires_python, ProjectError, ProjectInterpreter, SharedState,
};
use crate::commands::{diagnostics, pip, ExitStatus};
use crate::printer::Printer;
use crate::settings::{ResolverSettings, ResolverSettingsRef};
@ -84,7 +86,7 @@ pub(crate) async fn lock(
let workspace = Workspace::discover(project_dir, &DiscoveryOptions::default()).await?;
// Find an interpreter for the project
let interpreter = FoundInterpreter::discover(
let interpreter = ProjectInterpreter::discover(
&workspace,
python.as_deref().map(PythonRequest::parse),
python_preference,

View File

@ -280,10 +280,13 @@ pub(crate) fn validate_requires_python(
}
}
/// An interpreter suitable for the project.
#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum FoundInterpreter {
pub(crate) enum ProjectInterpreter {
/// An interpreter from outside the project, to create a new project virtual environment.
Interpreter(Interpreter),
/// An interpreter from an existing project virtual environment.
Environment(PythonEnvironment),
}
@ -351,7 +354,7 @@ impl WorkspacePython {
}
}
impl FoundInterpreter {
impl ProjectInterpreter {
/// Discover the interpreter to use in the current [`Workspace`].
pub(crate) async fn discover(
workspace: &Workspace,
@ -478,11 +481,11 @@ impl FoundInterpreter {
Ok(Self::Interpreter(interpreter))
}
/// Convert the [`FoundInterpreter`] into an [`Interpreter`].
/// Convert the [`ProjectInterpreter`] into an [`Interpreter`].
pub(crate) fn into_interpreter(self) -> Interpreter {
match self {
FoundInterpreter::Interpreter(interpreter) => interpreter,
FoundInterpreter::Environment(venv) => venv.into_interpreter(),
ProjectInterpreter::Interpreter(interpreter) => interpreter,
ProjectInterpreter::Environment(venv) => venv.into_interpreter(),
}
}
}
@ -498,7 +501,7 @@ pub(crate) async fn get_or_init_environment(
cache: &Cache,
printer: Printer,
) -> Result<PythonEnvironment, ProjectError> {
match FoundInterpreter::discover(
match ProjectInterpreter::discover(
workspace,
python,
python_preference,
@ -511,10 +514,10 @@ pub(crate) async fn get_or_init_environment(
.await?
{
// If we found an existing, compatible environment, use it.
FoundInterpreter::Environment(environment) => Ok(environment),
ProjectInterpreter::Environment(environment) => Ok(environment),
// Otherwise, create a virtual environment with the discovered interpreter.
FoundInterpreter::Interpreter(interpreter) => {
ProjectInterpreter::Interpreter(interpreter) => {
let venv = workspace.venv();
// Avoid removing things that are not virtual environments

View File

@ -12,7 +12,7 @@ use uv_workspace::{DiscoveryOptions, Workspace};
use crate::commands::pip::loggers::DefaultResolveLogger;
use crate::commands::pip::resolution_markers;
use crate::commands::project::FoundInterpreter;
use crate::commands::project::ProjectInterpreter;
use crate::commands::{project, ExitStatus};
use crate::printer::Printer;
use crate::settings::ResolverSettings;
@ -45,7 +45,7 @@ pub(crate) async fn tree(
let workspace = Workspace::discover(project_dir, &DiscoveryOptions::default()).await?;
// Find an interpreter for the project
let interpreter = FoundInterpreter::discover(
let interpreter = ProjectInterpreter::discover(
&workspace,
python.as_deref().map(PythonRequest::parse),
python_preference,