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

Run discovery on CI and adjust Conda env discovery #9

Merged
merged 16 commits into from
Jun 5, 2024
10 changes: 10 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@ jobs:
include:
- os: windows-latest
target: x86_64-pc-windows-msvc
run_cli: "yes"
- os: windows-latest
target: aarch64-pc-windows-msvc
run_cli: "no"
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
run_cli: "yes"
# - os: ubuntu-latest
# target: aarch64-unknown-linux-gnu
# - os: ubuntu-latest
# target: arm-unknown-linux-gnueabihf
- os: macos-latest
target: x86_64-apple-darwin
run_cli: "yes"
- os: macos-14
target: aarch64-apple-darwin
run_cli: "yes"
# - os: ubuntu-latest
# target: x86_64-unknown-linux-gnu
# - os: ubuntu-latest
Expand Down Expand Up @@ -130,6 +135,11 @@ jobs:
run: cargo test --frozen --all-features
shell: bash

- name: Find Environments
if: matrix.run_cli == 'yes'
run: cargo run --release --target ${{ matrix.target }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is harmless, given this runs in < 100ms
I want this running everytime so we can see the results.

shell: bash

- name: Build
run: cargo build --release --target ${{ matrix.target }}
shell: bash
Expand Down
4 changes: 4 additions & 0 deletions crates/pet-conda/src/conda_rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ impl Condarc {
}

#[cfg(windows)]
// Search paths documented here
// https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#searching-for-condarc
fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
let mut search_paths: Vec<PathBuf> = [
"C:\\ProgramData\\conda\\.condarc",
Expand Down Expand Up @@ -60,6 +62,8 @@ fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
}

#[cfg(unix)]
// Search paths documented here
// https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#searching-for-condarc
fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
let mut search_paths: Vec<PathBuf> = [
"/etc/conda/.condarc",
Expand Down
4 changes: 3 additions & 1 deletion crates/pet-conda/src/env_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct EnvVariables {
pub programdata: Option<String>,
pub homedrive: Option<String>,
pub conda_root: Option<String>,
pub conda: Option<String>,
pub conda_prefix: Option<String>,
pub condarc: Option<String>,
pub xdg_config_home: Option<String>,
Expand All @@ -33,7 +34,8 @@ impl EnvVariables {
allusersprofile: env.get_env_var("ALLUSERSPROFILE".to_string()),
programdata: env.get_env_var("PROGRAMDATA".to_string()),
homedrive: env.get_env_var("HOMEDRIVE".to_string()),
conda_root: env.get_env_var("ALLUSERSPROFILE".to_string()),
conda_root: env.get_env_var("CONDA_ROOT".to_string()),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First bug from real python on CI
Thanks for setting up Python @karthiknadig

conda: env.get_env_var("CONDA".to_string()),
conda_prefix: env.get_env_var("CONDA_PREFIX".to_string()),
condarc: env.get_env_var("CONDARC".to_string()),
xdg_config_home: env.get_env_var("XDG_CONFIG_HOME".to_string()),
Expand Down
92 changes: 73 additions & 19 deletions crates/pet-conda/src/environment_locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,29 @@ pub fn get_environments(conda_dir: &Path) -> Vec<PathBuf> {
envs.push(conda_dir.to_path_buf());

if let Ok(entries) = fs::read_dir(conda_dir.join("envs")) {
for entry in entries.filter_map(Result::ok) {
let path = entry.path();
if is_conda_env(&path) {
envs.push(path);
}
}
envs.append(
&mut entries
.filter_map(Result::ok)
.map(|e| e.path())
.filter(|p| is_conda_env(p))
.collect(),
);
}
} else if is_conda_env(conda_dir) {
envs.push(conda_dir.to_path_buf());
} else if fs::metadata(conda_dir.join("envs")).is_ok() {
// This could be a directory where conda environments are stored.
// I.e. its not necessarily the root conda install directory.
// E.g. C:\Users\donjayamanne\.conda
if let Ok(entries) = fs::read_dir(conda_dir.join("envs")) {
envs.append(
&mut entries
.filter_map(Result::ok)
.map(|e| e.path())
.filter(|p| is_conda_env(p))
.collect(),
);
}
}

envs.sort();
Expand Down Expand Up @@ -161,33 +175,73 @@ pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec<PathBuf
known_paths.push(Path::new(&home_drive).join("miniconda"));
known_paths.push(Path::new(&home_drive).join("miniforge3"));
}
if let Some(ref conda_root) = env_vars.conda_root {
known_paths.push(PathBuf::from(conda_root.clone()));
}
if let Some(ref conda_prefix) = env_vars.conda_prefix {
known_paths.push(PathBuf::from(conda_prefix.clone()));
}
if let Some(ref conda) = env_vars.conda {
let conda = PathBuf::from(conda);
if let Some(parent) = conda.parent() {
known_paths.push(parent.to_path_buf());
}
}
if let Some(home) = env_vars.clone().home {
known_paths.push(home.clone().join("anaconda3"));
known_paths.push(home.clone().join("miniconda3"));
known_paths.push(home.clone().join("miniforge3"));
// E.g. C:\Users\user name\.conda where we have `envs`` under this directory.
known_paths.push(home.join(".conda"));
// E.g. C:\Users\user name\AppData\Local\conda\conda\envs
known_paths.push(
home.join("AppData")
.join("Local")
.join("conda")
.join("conda"),
);
}
known_paths.sort();
known_paths.dedup();
known_paths
}

#[cfg(unix)]
pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec<PathBuf> {
let mut known_paths = vec![
PathBuf::from("/opt/anaconda3"),
PathBuf::from("/opt/miniconda3"),
PathBuf::from("/usr/local/anaconda3"),
PathBuf::from("/usr/local/miniconda3"),
PathBuf::from("/usr/anaconda3"),
PathBuf::from("/usr/miniconda3"),
PathBuf::from("/home/anaconda3"),
PathBuf::from("/home/miniconda3"),
PathBuf::from("/anaconda3"),
PathBuf::from("/miniconda3"),
PathBuf::from("/miniforge3"),
PathBuf::from("/miniforge3"),
let mut known_paths = vec![];
let directories_to_look_in = [
"/opt",
"/opt",
"/usr/share",
"/usr/local",
"/usr",
"/home",
"", // We need to look in `/anaconda3` and `/miniconda3` as well.
];
for directory in directories_to_look_in.iter() {
known_paths.push(PathBuf::from(format!("{}/anaconda", directory)));
known_paths.push(PathBuf::from(format!("{}/anaconda3", directory)));
known_paths.push(PathBuf::from(format!("{}/miniconda", directory)));
known_paths.push(PathBuf::from(format!("{}/miniconda3", directory)));
known_paths.push(PathBuf::from(format!("{}/miniforge", directory)));
known_paths.push(PathBuf::from(format!("{}/miniforge3", directory)));
}
if let Some(ref conda_root) = env_vars.conda_root {
known_paths.push(PathBuf::from(conda_root.clone()));
}
if let Some(ref conda_prefix) = env_vars.conda_prefix {
known_paths.push(PathBuf::from(conda_prefix.clone()));
}
if let Some(ref conda) = env_vars.conda {
let conda = PathBuf::from(conda);
if let Some(parent) = conda.parent() {
known_paths.push(parent.to_path_buf());
}
}
if let Some(ref home) = env_vars.home {
known_paths.push(home.clone().join("anaconda"));
known_paths.push(home.clone().join("anaconda3"));
known_paths.push(home.clone().join("miniconda"));
known_paths.push(home.clone().join("miniconda3"));
known_paths.push(home.clone().join("miniforge3"));
known_paths.push(home.join(".conda"));
Expand Down
18 changes: 18 additions & 0 deletions crates/pet-conda/tests/ci_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

mod common;

#[cfg(unix)]
#[test]
fn conda_ci() {
use pet_conda::Conda;
use pet_core::{os_environment::EnvironmentApi, Locator};

let env = EnvironmentApi::new();

let conda = Conda::from(&env);
let result = conda.find();
println!("SERVER CI Started");
println!("SERVER CI REsults{:?}", result);
}
1 change: 1 addition & 0 deletions crates/pet-conda/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn create_env_variables(home: PathBuf, root: PathBuf) -> EnvVariables {
allusersprofile: None,
conda_prefix: None,
conda_root: None,
conda: None,
condarc: None,
homedrive: None,
known_global_search_locations: vec![],
Expand Down