use std::path::PathBuf;
use serde::Serialize;
use crate::error::Result;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum SourceType {
Pyenv,
VirtualenvWrapper,
Conda,
}
impl std::fmt::Display for SourceType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Pyenv => write!(f, "pyenv"),
Self::VirtualenvWrapper => write!(f, "virtualenvwrapper"),
Self::Conda => write!(f, "conda"),
}
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(tag = "status", rename_all = "snake_case")]
pub enum EnvironmentStatus {
Ready,
NameConflict { existing: PathBuf },
PythonEol { version: String },
Corrupted { reason: String },
}
#[derive(Debug, Clone, Serialize)]
pub struct SourceEnvironment {
pub name: String,
pub python_version: String,
pub path: PathBuf,
pub source_type: SourceType,
pub size_bytes: Option<u64>,
pub status: EnvironmentStatus,
}
pub trait EnvironmentSource: Send + Sync {
fn source_type(&self) -> SourceType;
fn scan_environments(&self) -> Result<Vec<SourceEnvironment>>;
fn find_environment(&self, name: &str) -> Result<SourceEnvironment>;
}