use ruff_db::system::{System, SystemPathBuf};
use ruff_db::vendored::VendoredFileSystem;
use crate::path::SearchPathError;
use crate::resolve::SearchPaths;
use crate::strategy::MisconfigurationStrategy;
use crate::typeshed::TypeshedVersionsParseError;
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct SearchPathSettings {
pub extra_paths: Vec<SystemPathBuf>,
pub src_roots: Vec<SystemPathBuf>,
pub custom_typeshed: Option<SystemPathBuf>,
pub site_packages_paths: Vec<SystemPathBuf>,
pub real_stdlib_path: Option<SystemPathBuf>,
}
impl SearchPathSettings {
pub fn new(src_roots: Vec<SystemPathBuf>) -> Self {
Self {
src_roots,
..SearchPathSettings::empty()
}
}
pub fn empty() -> Self {
SearchPathSettings {
src_roots: vec![],
extra_paths: vec![],
custom_typeshed: None,
site_packages_paths: vec![],
real_stdlib_path: None,
}
}
pub fn to_search_paths<Strategy: MisconfigurationStrategy>(
&self,
system: &dyn System,
vendored: &VendoredFileSystem,
strategy: &Strategy,
) -> Result<SearchPaths, Strategy::Error<SearchPathSettingsError>> {
SearchPaths::from_settings(self, system, vendored, strategy)
}
}
#[derive(Debug, thiserror::Error)]
pub enum SearchPathSettingsError {
#[error(transparent)]
InvalidSearchPath(#[from] SearchPathError),
#[error("Failed to read the custom typeshed versions file '{path}'")]
FailedToReadVersionsFile {
path: SystemPathBuf,
#[source]
error: std::io::Error,
},
#[error(transparent)]
VersionsParseError(#[from] TypeshedVersionsParseError),
}