Skip to content

Commit fd3c504

Browse files
author
yashksaini-coder
committed
Refactor VenvInfo initialization and expand virtual environment detection criteria
1 parent 4860188 commit fd3c504

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

src/scanner.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ pub struct VenvInfo {
1212

1313
impl VenvInfo {
1414
pub fn new(path: PathBuf) -> Option<Self> {
15-
// Check if this is really a virtualenv
1615
let pyvenv_cfg = path.join("pyvenv.cfg");
1716
if !pyvenv_cfg.exists() {
1817
return None;
1918
}
2019

21-
// Calculate size
2220
let size = get_dir_size(&path).unwrap_or(0);
2321

24-
// Get last modified time
2522
let metadata = fs::metadata(&path).ok()?;
2623
let modified = metadata.modified().ok()
2724
.and_then(|t| DateTime::<Local>::from(t).into());
@@ -34,7 +31,6 @@ impl VenvInfo {
3431
}
3532
}
3633

37-
/// Scan a directory recursively for potential Python virtualenv folders
3834
pub fn scan_for_venvs(root: &Path) -> Vec<VenvInfo> {
3935
let mut results = Vec::new();
4036

@@ -44,7 +40,7 @@ pub fn scan_for_venvs(root: &Path) -> Vec<VenvInfo> {
4440
}
4541

4642
let name = entry.file_name().to_string_lossy().to_lowercase();
47-
if name == "venv" || name == ".venv" || name == "env" {
43+
if name == "venv" || name == ".venv" || name == "env" || name == "virtualenv" || name == "pyenv" || name ==".env" {
4844
if let Some(venv) = VenvInfo::new(entry.path().to_path_buf()) {
4945
results.push(venv);
5046
}
@@ -54,7 +50,6 @@ pub fn scan_for_venvs(root: &Path) -> Vec<VenvInfo> {
5450
results
5551
}
5652

57-
/// Recursively calculate directory size in bytes
5853
fn get_dir_size(path: &Path) -> Result<u64, std::io::Error> {
5954
let mut size = 0;
6055

0 commit comments

Comments
 (0)