mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-27 02:17:08 +00:00
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:
parent
84afca2696
commit
1379fb7dcd
3 changed files with 513 additions and 78 deletions
|
|
@ -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())),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue