mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 12:14:43 +00:00
Update env.rs
This commit is contained in:
parent
429a7ac7b1
commit
4d77dc88c6
1 changed files with 20 additions and 12 deletions
|
@ -7,11 +7,19 @@ use crate::python_util::get_sys_path;
|
|||
use crate::style::colors::*;
|
||||
use crate::style::RESET;
|
||||
|
||||
fn fallback_erg_path() -> PathBuf {
|
||||
#[allow(deprecated)]
|
||||
std::env::home_dir().map_or(PathBuf::from(".erg"), |path| path.join(".erg"))
|
||||
}
|
||||
|
||||
fn _erg_path() -> PathBuf {
|
||||
let path = var("ERG_PATH").unwrap_or_else(|_| env!("CARGO_ERG_PATH").to_string());
|
||||
PathBuf::from(path).canonicalize().unwrap_or_else(|_| {
|
||||
eprintln!("{RED}[ERR] ERG_PATH not found{RESET}");
|
||||
PathBuf::from(".")
|
||||
let fallback = fallback_erg_path();
|
||||
if !fallback.exists() {
|
||||
eprintln!("{RED}[ERR] ERG_PATH not found{RESET}");
|
||||
}
|
||||
fallback
|
||||
})
|
||||
}
|
||||
fn _erg_std_path() -> PathBuf {
|
||||
|
@ -21,7 +29,7 @@ fn _erg_std_path() -> PathBuf {
|
|||
.canonicalize()
|
||||
.unwrap_or_else(|_| {
|
||||
eprintln!("{RED}[ERR] ERG_PATH/lib/std not found{RESET}");
|
||||
PathBuf::from("lib/std/")
|
||||
fallback_erg_path().join("lib/std")
|
||||
})
|
||||
}
|
||||
fn _erg_std_decl_path() -> PathBuf {
|
||||
|
@ -31,7 +39,7 @@ fn _erg_std_decl_path() -> PathBuf {
|
|||
.canonicalize()
|
||||
.unwrap_or_else(|_| {
|
||||
eprintln!("{RED}[ERR] ERG_PATH/lib/std.d not found {RESET}");
|
||||
PathBuf::from("lib/std.d/")
|
||||
fallback_erg_path().join("lib/std.d")
|
||||
})
|
||||
}
|
||||
fn _erg_pystd_path() -> PathBuf {
|
||||
|
@ -41,7 +49,7 @@ fn _erg_pystd_path() -> PathBuf {
|
|||
.canonicalize()
|
||||
.unwrap_or_else(|_| {
|
||||
eprintln!("{RED}[ERR] ERG_PATH/lib/pystd not found {RESET}");
|
||||
PathBuf::from("lib/pystd/")
|
||||
fallback_erg_path().join("lib/pystd")
|
||||
})
|
||||
}
|
||||
fn _erg_external_lib_path() -> PathBuf {
|
||||
|
@ -51,7 +59,7 @@ fn _erg_external_lib_path() -> PathBuf {
|
|||
.canonicalize()
|
||||
.unwrap_or_else(|_| {
|
||||
eprintln!("{RED}[ERR] ERG_PATH/lib/external not found {RESET}");
|
||||
PathBuf::from("lib/external/")
|
||||
fallback_erg_path().join("lib/external")
|
||||
})
|
||||
}
|
||||
fn _python_site_packages() -> impl Iterator<Item = PathBuf> {
|
||||
|
@ -62,7 +70,7 @@ fn _python_site_packages() -> impl Iterator<Item = PathBuf> {
|
|||
.map(|p| {
|
||||
p.canonicalize().unwrap_or_else(|_| {
|
||||
eprintln!("{RED}[ERR] ERG_PATH/lib/external not found {RESET}");
|
||||
PathBuf::from("lib/external/")
|
||||
fallback_erg_path().join("lib/external")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -74,27 +82,27 @@ pub static ERG_PYSTD_PATH: OnceLock<PathBuf> = OnceLock::new();
|
|||
pub static ERG_EXTERNAL_LIB_PATH: OnceLock<PathBuf> = OnceLock::new();
|
||||
pub static PYTHON_SITE_PACKAGES: OnceLock<Vec<PathBuf>> = OnceLock::new();
|
||||
|
||||
/// == `Path::new(".")` if ERG_PATH is not set
|
||||
/// == `Path::new("~/.erg")` if ERG_PATH is not set
|
||||
pub fn erg_path() -> &'static PathBuf {
|
||||
ERG_PATH.get_or_init(|| normalize_path(_erg_path())) // .with(|s| s.clone())
|
||||
}
|
||||
|
||||
/// == `Path::new("lib/std")` if ERG_PATH is not set
|
||||
/// == `Path::new("~/.erg/lib/std")` if ERG_PATH is not set
|
||||
pub fn erg_std_path() -> &'static PathBuf {
|
||||
ERG_STD_PATH.get_or_init(|| normalize_path(_erg_std_path()))
|
||||
}
|
||||
|
||||
/// == `Path::new("lib/std.d")` if ERG_PATH is not set
|
||||
/// == `Path::new("~/.erg/lib/std.d")` if ERG_PATH is not set
|
||||
pub fn erg_std_decl_path() -> &'static PathBuf {
|
||||
ERG_STD_DECL_PATH.get_or_init(|| normalize_path(_erg_std_decl_path()))
|
||||
}
|
||||
|
||||
/// == `Path::new("lib/pystd")` if ERG_PATH is not set
|
||||
/// == `Path::new("~/.erg/lib/pystd")` if ERG_PATH is not set
|
||||
pub fn erg_pystd_path() -> &'static PathBuf {
|
||||
ERG_PYSTD_PATH.get_or_init(|| normalize_path(_erg_pystd_path()))
|
||||
}
|
||||
|
||||
/// == `Path::new("lib/external")` if ERG_PATH is not set
|
||||
/// == `Path::new("~/.erg/lib/external")` if ERG_PATH is not set
|
||||
pub fn erg_py_external_lib_path() -> &'static PathBuf {
|
||||
ERG_EXTERNAL_LIB_PATH.get_or_init(|| normalize_path(_erg_external_lib_path()))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue