Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename PythonRequest::Any -> PythonRequest::Default #7514

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions crates/uv-python/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ use crate::{Interpreter, PythonVersion};
/// See [`PythonRequest::from_str`].
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum PythonRequest {
/// Use any discovered Python installation
/// Use an appropriate default Python installation
///
/// This may skip some Python installations, such as pre-release versions or alternative
/// implementations.
#[default]
Any,
Default,
/// A Python version without an implementation name e.g. `3.10` or `>=3.12,<3.13`
Version(VersionRequest),
/// A path to a directory containing a Python installation, e.g. `.venv`
Expand Down Expand Up @@ -776,7 +779,7 @@ pub fn find_python_installations<'a>(
))))
}
}
PythonRequest::Any => Box::new({
PythonRequest::Default => Box::new({
debug!("Searching for Python interpreter in {preference}");
python_interpreters(None, None, environments, preference, cache).map(|result| {
result
Expand Down Expand Up @@ -976,7 +979,7 @@ pub fn find_best_python_installation(

// If a Python version was requested but cannot be fulfilled, just take any version
debug!("Looking for Python installation with any version");
let request = PythonRequest::Any;
let request = PythonRequest::Default;
Ok(
find_python_installation(&request, environments, preference, cache)?.map_err(|err| {
// Use a more general error in this case since we looked for multiple versions
Expand Down Expand Up @@ -1142,7 +1145,7 @@ impl PythonRequest {
pub fn parse(value: &str) -> Self {
// e.g. `any`
if value.eq_ignore_ascii_case("any") {
return Self::Any;
return Self::Default;
}

// e.g. `3.12.1`, `312`, or `>=3.12`
Expand Down Expand Up @@ -1246,7 +1249,7 @@ impl PythonRequest {
}

match self {
PythonRequest::Any => true,
PythonRequest::Default => true,
PythonRequest::Version(version_request) => {
version_request.matches_interpreter(interpreter)
}
Expand Down Expand Up @@ -1330,7 +1333,7 @@ impl PythonRequest {

pub(crate) fn allows_prereleases(&self) -> bool {
match self {
Self::Any => false,
Self::Default => false,
Self::Version(version) => version.allows_prereleases(),
Self::Directory(_) | Self::File(_) | Self::ExecutableName(_) => true,
Self::Implementation(_) => false,
Expand All @@ -1348,7 +1351,7 @@ impl PythonRequest {
/// [`Self::parse`] should always return the same request when given the output of this method.
pub fn to_canonical_string(&self) -> String {
match self {
Self::Any => "any".to_string(),
Self::Default => "any".to_string(),
Self::Version(version) => version.to_string(),
Self::Directory(path) => path.display().to_string(),
Self::File(path) => path.display().to_string(),
Expand Down Expand Up @@ -1801,7 +1804,7 @@ impl fmt::Display for VersionRequest {
impl fmt::Display for PythonRequest {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Any => write!(f, "any Python"),
Self::Default => write!(f, "any Python"),
Self::Version(version) => write!(f, "Python {version}"),
Self::Directory(path) => write!(f, "directory `{}`", path.user_display()),
Self::File(path) => write!(f, "path `{}`", path.user_display()),
Expand Down Expand Up @@ -1883,7 +1886,7 @@ impl fmt::Display for PythonNotFound {
};

match self.request {
PythonRequest::Any => {
PythonRequest::Default => {
write!(f, "No interpreter found in {sources}")
}
_ => {
Expand Down Expand Up @@ -1961,7 +1964,7 @@ mod tests {

#[test]
fn interpreter_request_from_str() {
assert_eq!(PythonRequest::parse("any"), PythonRequest::Any);
assert_eq!(PythonRequest::parse("any"), PythonRequest::Default);
assert_eq!(
PythonRequest::parse("3.12"),
PythonRequest::Version(VersionRequest::from_str("3.12").unwrap())
Expand Down Expand Up @@ -2123,7 +2126,7 @@ mod tests {

#[test]
fn interpreter_request_to_canonical_string() {
assert_eq!(PythonRequest::Any.to_canonical_string(), "any");
assert_eq!(PythonRequest::Default.to_canonical_string(), "any");
assert_eq!(
PythonRequest::Version(VersionRequest::from_str("3.12").unwrap()).to_canonical_string(),
"3.12"
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-python/src/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl PythonDownloadRequest {
.with_version(version.clone()),
),
PythonRequest::Key(request) => Some(request.clone()),
PythonRequest::Any => Some(Self::default()),
PythonRequest::Default => Some(Self::default()),
// We can't download a managed installation for these request kinds
PythonRequest::Directory(_)
| PythonRequest::ExecutableName(_)
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-python/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl fmt::Display for EnvironmentNotFound {
EnvironmentPreference::OnlyVirtual => SearchType::Virtual,
};

if matches!(self.request, PythonRequest::Any) {
if matches!(self.request, PythonRequest::Default) {
write!(f, "No {search_type} found")?;
} else {
write!(f, "No {search_type} found for {}", self.request)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-python/src/installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl PythonInstallation {
cache: &Cache,
reporter: Option<&dyn Reporter>,
) -> Result<Self, Error> {
let request = request.unwrap_or_else(|| &PythonRequest::Any);
let request = request.unwrap_or_else(|| &PythonRequest::Default);

// Search for the installation
match Self::find(request, environments, preference, cache) {
Expand Down
Loading
Loading