Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid misdetecting global Linux Python as virtualenv #197

Merged
merged 3 commits into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions crates/pet-virtualenv/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

use std::path::Path;
use std::path::{Path, PathBuf};

use pet_core::{
env::PythonEnv,
@@ -40,6 +40,19 @@ pub fn is_virtualenv_dir(path: &Path) -> bool {
path = path.join("bin");
}
}

// Never consider global locations to be virtualenvs
// in case there is a false positive match from checks below.
if [
PathBuf::from(r"/bin"),
PathBuf::from(r"/usr/bin"),
PathBuf::from(r"/usr/local/bin"),
]
.contains(&path)
{
return false;
}

// Check if there are any activate.* files in the same directory as the interpreter.
//
// env
@@ -62,7 +75,7 @@ pub fn is_virtualenv_dir(path: &Path) -> bool {
.unwrap_or_default()
.to_str()
.unwrap_or_default()
.starts_with("activate")
.starts_with("activate.")
{
return true;
}