Add support for requesting pypy interpreters by implementation name (#3706)

Updates our executable name searches to support implementation names
i.e. `cpython` and `pypy` and adds support for PyPy.

We might want to _not_ support searching for `cpython` because that's
non-standard?
This commit is contained in:
Zanie Blue 2024-05-21 17:48:43 -04:00 committed by GitHub
parent 84afca2696
commit 1379fb7dcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 513 additions and 78 deletions

View file

@ -10,20 +10,24 @@ pub enum Error {
UnknownImplementation(String),
}
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
#[derive(Debug, Eq, PartialEq, Clone, Copy, Default)]
pub enum ImplementationName {
#[default]
CPython,
PyPy,
}
impl ImplementationName {
pub(crate) fn iter() -> impl Iterator<Item = &'static ImplementationName> {
static NAMES: &[ImplementationName] = &[ImplementationName::CPython];
static NAMES: &[ImplementationName] =
&[ImplementationName::CPython, ImplementationName::PyPy];
NAMES.iter()
}
pub fn as_str(&self) -> &str {
pub fn as_str(self) -> &'static str {
match self {
Self::CPython => "cpython",
Self::PyPy => "pypy",
}
}
}
@ -34,6 +38,7 @@ impl FromStr for ImplementationName {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_ascii_lowercase().as_str() {
"cpython" => Ok(Self::CPython),
"pypy" => Ok(Self::PyPy),
_ => Err(Error::UnknownImplementation(s.to_string())),
}
}