Skip to content

Commit f586845

Browse files
Add support for detecting $VIRTUAL_ENV (#181)
Addresses #180 (this is me writing rust for the first time 😬) Co-authored-by: Don Jayamanne <don.jayamanne@outlook.com>
1 parent f7e27dd commit f586845

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

crates/pet-global-virtualenvs/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,20 @@ fn get_global_virtualenv_dirs(
5656
}
5757

5858
pub fn list_global_virtual_envs_paths(
59+
virtual_env_env_var: Option<String>,
5960
work_on_home_env_var: Option<String>,
6061
xdg_data_home: Option<String>,
6162
user_home: Option<PathBuf>,
6263
) -> Vec<PathBuf> {
6364
let mut python_envs: Vec<PathBuf> = vec![];
65+
66+
if let Some(virtual_env) = virtual_env_env_var {
67+
let virtual_env = norm_case(expand_path(PathBuf::from(virtual_env)));
68+
if virtual_env.exists() {
69+
python_envs.push(virtual_env);
70+
}
71+
}
72+
6473
for root_dir in &get_global_virtualenv_dirs(work_on_home_env_var, xdg_data_home, user_home) {
6574
if let Ok(dirs) = fs::read_dir(root_dir) {
6675
python_envs.append(

crates/pet/src/find.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ pub fn find_and_report_envs(
160160

161161
let search_paths: Vec<PathBuf> = [
162162
list_global_virtual_envs_paths(
163+
environment.get_env_var("VIRTUAL_ENV".into()),
163164
environment.get_env_var("WORKON_HOME".into()),
164165
environment.get_env_var("XDG_DATA_HOME".into()),
165166
environment.get_user_home(),

0 commit comments

Comments
 (0)