From 115d49f34a5927984e0bfe27c36dd9ffb593472a Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 14:02:12 +1000 Subject: [PATCH 01/16] Conda on CI --- crates/pet-conda/tests/ci_test.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 crates/pet-conda/tests/ci_test.rs diff --git a/crates/pet-conda/tests/ci_test.rs b/crates/pet-conda/tests/ci_test.rs new file mode 100644 index 00000000..a0623878 --- /dev/null +++ b/crates/pet-conda/tests/ci_test.rs @@ -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); +} From dc024e80e5b67cf9113cb2073e9a4517c0f64690 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 14:11:39 +1000 Subject: [PATCH 02/16] Lets find everything --- .github/workflows/pr-check.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 97e507cf..0aaf58f4 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -130,6 +130,9 @@ jobs: run: cargo test --frozen --all-features shell: bash + - name: Find Environments + run: cargo run --release --target ${{ matrix.target }} + - name: Build run: cargo build --release --target ${{ matrix.target }} shell: bash From 44661d0dcbe60bfe0f073998a6d802b98815d1f1 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 14:12:01 +1000 Subject: [PATCH 03/16] Display output as well --- .github/workflows/pr-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 0aaf58f4..db63db5c 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -127,7 +127,7 @@ jobs: shell: bash - name: Run Tests - run: cargo test --frozen --all-features + run: cargo test --frozen --all-features --nocapture shell: bash - name: Find Environments From 840bd06cf478c21810e87eb2489fc4b3254932c4 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 14:18:40 +1000 Subject: [PATCH 04/16] oop --- .github/workflows/pr-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index db63db5c..1c0dcbc1 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -127,7 +127,7 @@ jobs: shell: bash - name: Run Tests - run: cargo test --frozen --all-features --nocapture + run: cargo test --frozen --all-features -- --nocapture shell: bash - name: Find Environments From ca12c88b8694a88a881fa1874ec4fe67a61f2e2c Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 14:30:01 +1000 Subject: [PATCH 05/16] oops --- .github/workflows/pr-check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 1c0dcbc1..9cf888ae 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -132,6 +132,7 @@ jobs: - name: Find Environments run: cargo run --release --target ${{ matrix.target }} + shell: bash - name: Build run: cargo build --release --target ${{ matrix.target }} From 6bed471a713c9df54d52ad7ced618aff6e9bbbf4 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 14:48:21 +1000 Subject: [PATCH 06/16] Add more search paths and fix CONDA_ROOT env variable --- crates/pet-conda/src/env_variables.rs | 2 +- crates/pet-conda/src/environment_locations.rs | 35 ++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/crates/pet-conda/src/env_variables.rs b/crates/pet-conda/src/env_variables.rs index af3e5e8f..d724203f 100644 --- a/crates/pet-conda/src/env_variables.rs +++ b/crates/pet-conda/src/env_variables.rs @@ -33,7 +33,7 @@ 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()), 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()), diff --git a/crates/pet-conda/src/environment_locations.rs b/crates/pet-conda/src/environment_locations.rs index 6d9ee1f2..e4963211 100644 --- a/crates/pet-conda/src/environment_locations.rs +++ b/crates/pet-conda/src/environment_locations.rs @@ -172,22 +172,31 @@ pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec Vec { - 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 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")); From 3c1cd10e193769fcc33011fc0246b7c27fd9d889 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 14:50:05 +1000 Subject: [PATCH 07/16] extract conda dir from the CONDA env variable as well --- crates/pet-conda/src/env_variables.rs | 2 ++ crates/pet-conda/src/environment_locations.rs | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/crates/pet-conda/src/env_variables.rs b/crates/pet-conda/src/env_variables.rs index d724203f..08056ba6 100644 --- a/crates/pet-conda/src/env_variables.rs +++ b/crates/pet-conda/src/env_variables.rs @@ -17,6 +17,7 @@ pub struct EnvVariables { pub programdata: Option, pub homedrive: Option, pub conda_root: Option, + pub conda: Option, pub conda_prefix: Option, pub condarc: Option, pub xdg_config_home: Option, @@ -34,6 +35,7 @@ impl EnvVariables { programdata: env.get_env_var("PROGRAMDATA".to_string()), homedrive: env.get_env_var("HOMEDRIVE".to_string()), conda_root: env.get_env_var("CONDA_ROOT".to_string()), + 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()), diff --git a/crates/pet-conda/src/environment_locations.rs b/crates/pet-conda/src/environment_locations.rs index e4963211..04c26470 100644 --- a/crates/pet-conda/src/environment_locations.rs +++ b/crates/pet-conda/src/environment_locations.rs @@ -193,6 +193,15 @@ pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec Date: Wed, 5 Jun 2024 14:58:30 +1000 Subject: [PATCH 08/16] more directories on windows --- crates/pet-conda/src/environment_locations.rs | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/crates/pet-conda/src/environment_locations.rs b/crates/pet-conda/src/environment_locations.rs index 04c26470..ee42501d 100644 --- a/crates/pet-conda/src/environment_locations.rs +++ b/crates/pet-conda/src/environment_locations.rs @@ -107,15 +107,29 @@ pub fn get_environments(conda_dir: &Path) -> Vec { 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(); @@ -165,7 +179,15 @@ pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec Date: Wed, 5 Jun 2024 14:59:08 +1000 Subject: [PATCH 09/16] more paths --- crates/pet-conda/src/environment_locations.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/pet-conda/src/environment_locations.rs b/crates/pet-conda/src/environment_locations.rs index ee42501d..bbc096be 100644 --- a/crates/pet-conda/src/environment_locations.rs +++ b/crates/pet-conda/src/environment_locations.rs @@ -175,6 +175,18 @@ pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec Date: Wed, 5 Jun 2024 14:59:32 +1000 Subject: [PATCH 10/16] deduplicate --- crates/pet-conda/src/environment_locations.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/pet-conda/src/environment_locations.rs b/crates/pet-conda/src/environment_locations.rs index bbc096be..48f093ca 100644 --- a/crates/pet-conda/src/environment_locations.rs +++ b/crates/pet-conda/src/environment_locations.rs @@ -201,6 +201,8 @@ pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec Date: Wed, 5 Jun 2024 15:01:44 +1000 Subject: [PATCH 11/16] Add comments --- crates/pet-conda/src/conda_rc.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/pet-conda/src/conda_rc.rs b/crates/pet-conda/src/conda_rc.rs index 4cb1b6ba..27d7a84f 100644 --- a/crates/pet-conda/src/conda_rc.rs +++ b/crates/pet-conda/src/conda_rc.rs @@ -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 { let mut search_paths: Vec = [ "C:\\ProgramData\\conda\\.condarc", @@ -60,6 +62,8 @@ fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec { } #[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 { let mut search_paths: Vec = [ "/etc/conda/.condarc", From f387801fdd549964f46a12c623cf5760d4cb521d Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 15:04:00 +1000 Subject: [PATCH 12/16] Skip outputs --- .github/workflows/pr-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 9cf888ae..033b4e9c 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -127,7 +127,7 @@ jobs: shell: bash - name: Run Tests - run: cargo test --frozen --all-features -- --nocapture + run: cargo test --frozen --all-features shell: bash - name: Find Environments From 6fc436e33c8d1ef4624f2783b6722cfd28b6485c Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 15:04:50 +1000 Subject: [PATCH 13/16] Fix compilation error --- crates/pet-conda/tests/common.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/pet-conda/tests/common.rs b/crates/pet-conda/tests/common.rs index 97d8211a..befd8a22 100644 --- a/crates/pet-conda/tests/common.rs +++ b/crates/pet-conda/tests/common.rs @@ -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![], From b2cbe18a414ae6acf3da40e5944eb388c39a93db Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 15:13:19 +1000 Subject: [PATCH 14/16] Run cli only on some platforms --- .github/workflows/pr-check.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 033b4e9c..e00b5366 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -10,6 +10,15 @@ on: - release-* jobs: + # Make sure to cancel previous runs on a push + cancel_previous_runs: + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.12.0 + with: + access_token: ${{ github.token }} + tests: name: Tests runs-on: ${{ matrix.os }} @@ -19,18 +28,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 @@ -131,6 +145,7 @@ jobs: shell: bash - name: Find Environments + if: matrix.run_cli == 'yes' run: cargo run --release --target ${{ matrix.target }} shell: bash From 0b0786939b18d768da6725f03a9fe12e12ba267a Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 15:17:11 +1000 Subject: [PATCH 15/16] empty From 88b625d19d641d97f3122048ce16e6021fa8429e Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 15:18:44 +1000 Subject: [PATCH 16/16] Revert --- .github/workflows/pr-check.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index e00b5366..e9c7a7b3 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -10,15 +10,6 @@ on: - release-* jobs: - # Make sure to cancel previous runs on a push - cancel_previous_runs: - runs-on: ubuntu-latest - steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.12.0 - with: - access_token: ${{ github.token }} - tests: name: Tests runs-on: ${{ matrix.os }}