Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Jun 17, 2024
1 parent 8b2c5bb commit 35a2730
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
24 changes: 14 additions & 10 deletions crates/uv-toolchain/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,9 @@ pub fn find_toolchains<'a>(
.filter(move |result| result_satisfies_system_python(result, system))
.filter(|result| match result {
Err(_) => true,
Ok((_source, interpreter)) => {
interpreter.implementation_name() == implementation.as_str()
}
Ok((_source, interpreter)) => interpreter
.implementation_name()
.eq_ignore_ascii_case(implementation.into()),
})
.map(|result| result.map(Toolchain::from_tuple).map(ToolchainResult::Ok))
}),
Expand All @@ -608,7 +608,9 @@ pub fn find_toolchains<'a>(
Err(_) => true,
Ok((_source, interpreter)) => {
version.matches_interpreter(interpreter)
&& interpreter.implementation_name() == implementation.as_str()
&& interpreter
.implementation_name()
.eq_ignore_ascii_case(implementation.into())
}
})
.map(|result| result.map(Toolchain::from_tuple).map(ToolchainResult::Ok))
Expand Down Expand Up @@ -937,7 +939,7 @@ impl ToolchainRequest {
for implementation in ImplementationName::iter() {
if let Some(remainder) = value
.to_ascii_lowercase()
.strip_prefix(implementation.as_str())
.strip_prefix(Into::<&str>::into(implementation))
{
// e.g. `pypy`
if remainder.is_empty() {
Expand Down Expand Up @@ -1069,12 +1071,14 @@ impl ToolchainRequest {
}
false
}
ToolchainRequest::Implementation(implementation) => {
interpreter.implementation_name() == implementation.as_str()
}
ToolchainRequest::Implementation(implementation) => interpreter
.implementation_name()
.eq_ignore_ascii_case(implementation.into()),
ToolchainRequest::ImplementationVersion(implementation, version) => {
version.matches_interpreter(interpreter)
&& interpreter.implementation_name() == implementation.as_str()
&& interpreter
.implementation_name()
.eq_ignore_ascii_case(implementation.into())
}
ToolchainRequest::Key(request) => request.satisfied_by_interpreter(interpreter),
}
Expand Down Expand Up @@ -1126,7 +1130,7 @@ impl VersionRequest {
.into_iter()
.flat_map(move |implementation| {
let extension = std::env::consts::EXE_SUFFIX;
let name = implementation.as_str();
let name: &str = implementation.into();
let (python, python3) = if extension.is_empty() {
(Cow::Borrowed(name), Cow::Owned(format!("{name}3")))
} else {
Expand Down
38 changes: 31 additions & 7 deletions crates/uv-toolchain/src/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,37 @@ impl ImplementationName {
NAMES.iter()
}

pub fn as_str(self) -> &'static str {
pub fn pretty(self) -> &'static str {
match self {
Self::CPython => "cpython",
Self::PyPy => "pypy",
Self::CPython => "CPython",
Self::PyPy => "PyPy",
}
}
}

impl LenientImplementationName {
pub fn pretty(&self) -> &str {
match self {
Self::Known(implementation) => implementation.pretty(),
Self::Unknown(name) => name,
}
}
}

impl From<&ImplementationName> for &'static str {
fn from(v: &ImplementationName) -> &'static str {
match v {
ImplementationName::CPython => "cpython",
ImplementationName::PyPy => "pypy",
}
}
}

impl<'a> From<&'a LenientImplementationName> for &'a str {
fn from(v: &'a LenientImplementationName) -> &'a str {
match v {
LenientImplementationName::Known(implementation) => implementation.into(),
LenientImplementationName::Unknown(name) => name,
}
}
}
Expand All @@ -52,10 +79,7 @@ impl FromStr for ImplementationName {

impl Display for ImplementationName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::CPython => f.write_str("cpython"),
Self::PyPy => f.write_str("pypy"),
}
f.write_str(self.into())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-toolchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod tests {
)
.replace("{FULL_VERSION}", &version.to_string())
.replace("{VERSION}", &version.without_patch().to_string())
.replace("{IMPLEMENTATION}", implementation.as_str());
.replace("{IMPLEMENTATION}", (&implementation).into());

fs_err::create_dir_all(path.parent().unwrap())?;
fs_err::write(
Expand Down
10 changes: 2 additions & 8 deletions crates/uv-toolchain/src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::discovery::{
ToolchainSources,
};
use crate::downloads::{DownloadResult, PythonDownload, PythonDownloadRequest};
use crate::implementation::{LenientImplementationName};
use crate::implementation::LenientImplementationName;
use crate::managed::{InstalledToolchain, InstalledToolchains};
use crate::platform::{Arch, Libc, Os};
use crate::{Error, Interpreter, PythonVersion, ToolchainSource};
Expand Down Expand Up @@ -313,13 +313,7 @@ impl fmt::Display for ToolchainKey {
write!(
f,
"{}-{}.{}.{}-{}-{}-{}",
self.implementation,
self.major,
self.minor,
self.patch,
self.os,
self.arch,
self.libc
self.implementation, self.major, self.minor, self.patch, self.os, self.arch, self.libc
)
}
}
Expand Down

0 comments on commit 35a2730

Please sign in to comment.