Skip to content

Commit 8ea2f30

Browse files
Armd04DonJayamanne
andauthored
Changed the order of locaters (#136)
Closes #135 Rearranged the order of locater since Homebrew can be used to install Poetry, Anoconda, etc. --------- Co-authored-by: Don Jayamanne <[email protected]>
1 parent f8fa71c commit 8ea2f30

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pet-conda/src/environment_locations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub fn get_conda_envs_from_environment_txt(env_vars: &EnvVariables) -> Vec<PathB
235235
if let Ok(reader) = fs::read_to_string(environment_txt.clone()) {
236236
trace!("Found environments.txt file {:?}", environment_txt);
237237
for line in reader.lines() {
238-
let line = norm_case(&PathBuf::from(line.to_string()));
238+
let line = norm_case(PathBuf::from(line.to_string()));
239239
trace!("Conda env in environments.txt file {:?}", line);
240240
if line.exists() {
241241
envs.push(line);

crates/pet-homebrew/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ msvc_spectre_libs = { version = "0.1.1", features = ["error"] }
1010
pet-fs = { path = "../pet-fs" }
1111
pet-python-utils = { path = "../pet-python-utils" }
1212
pet-virtualenv = { path = "../pet-virtualenv" }
13+
pet-conda = { path = "../pet-conda" }
1314
serde = { version = "1.0.152", features = ["derive"] }
1415
serde_json = "1.0.93"
1516
lazy_static = "1.4.0"

crates/pet-homebrew/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use env_variables::EnvVariables;
55
use environment_locations::get_homebrew_prefix_bin;
66
use environments::get_python_info;
7+
use pet_conda::utils::is_conda_env;
78
use pet_core::{
89
env::PythonEnv,
910
os_environment::Environment,
@@ -47,6 +48,20 @@ fn from(env: &PythonEnv) -> Option<PythonEnvironment> {
4748
return None;
4849
}
4950

51+
if let Some(prefix) = &env.prefix {
52+
if is_conda_env(prefix) {
53+
return None;
54+
}
55+
}
56+
// Possible this is a root conda env (hence parent directory is conda install dir).
57+
if is_conda_env(env.executable.parent()?) {
58+
return None;
59+
}
60+
// Possible this is a conda env (hence parent directory is Scripts/bin dir).
61+
if is_conda_env(env.executable.parent()?.parent()?) {
62+
return None;
63+
}
64+
5065
// Note: Sometimes if Python 3.10 was installed by other means (e.g. from python.org or other)
5166
// & then you install Python 3.10 via Homebrew, then some files will get installed via homebrew,
5267
// However everything (symlinks, Python executable `sys.executable`, `sys.prefix`) eventually point back to the existing installation.

crates/pet/src/locators.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,11 @@ pub fn create_locators(
4747
}
4848
// 3. Pyenv Python
4949
locators.push(Arc::new(PyEnv::from(environment, conda_locator.clone())));
50-
// 4. Homebrew Python
51-
if cfg!(unix) {
52-
#[cfg(unix)]
53-
use pet_homebrew::Homebrew;
54-
#[cfg(unix)]
55-
let homebrew_locator = Homebrew::from(environment);
56-
#[cfg(unix)]
57-
locators.push(Arc::new(homebrew_locator));
58-
}
59-
// 5. Conda Python
50+
51+
// 4. Conda Python
6052
locators.push(conda_locator);
61-
// 6. Support for Virtual Envs
53+
54+
// 5. Support for Virtual Envs
6255
// The order of these matter.
6356
// Basically PipEnv is a superset of VirtualEnvWrapper, which is a superset of Venv, which is a superset of VirtualEnv.
6457
locators.push(poetry_locator);
@@ -68,6 +61,16 @@ pub fn create_locators(
6861
// VirtualEnv is the most generic, hence should be the last.
6962
locators.push(Arc::new(VirtualEnv::new()));
7063

64+
// 6. Homebrew Python
65+
if cfg!(unix) {
66+
#[cfg(unix)]
67+
use pet_homebrew::Homebrew;
68+
#[cfg(unix)]
69+
let homebrew_locator = Homebrew::from(environment);
70+
#[cfg(unix)]
71+
locators.push(Arc::new(homebrew_locator));
72+
}
73+
7174
// 7. Global Mac Python
7275
// 8. CommandLineTools Python & xcode
7376
if std::env::consts::OS == "macos" {

0 commit comments

Comments
 (0)