diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index f462e508..032123b8 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -132,14 +132,14 @@ jobs: shell: bash - name: Run Tests - run: cargo test --frozen --all-features + run: cargo test --frozen --all-features -- --nocapture shell: bash - name: Find Environments if: matrix.run_cli == 'yes' run: cargo run --release --target ${{ matrix.target }} shell: bash - + builds: name: Builds runs-on: ${{ matrix.os }} @@ -183,7 +183,9 @@ jobs: shell: bash - name: Run Tests - run: cargo test --frozen --all-features + # We do not want to run all features, CI is only for tests with Python + # Thats a separate job. + run: cargo test --frozen shell: bash - name: Build diff --git a/crates/pet-conda/Cargo.toml b/crates/pet-conda/Cargo.toml index aefc3235..69ae0395 100644 --- a/crates/pet-conda/Cargo.toml +++ b/crates/pet-conda/Cargo.toml @@ -11,3 +11,6 @@ pet-core = { path = "../pet-core" } pet-utils = { path = "../pet-utils" } log = "0.4.21" regex = "1.10.4" + +[features] +ci = [] \ No newline at end of file diff --git a/crates/pet-conda/src/environment_locations.rs b/crates/pet-conda/src/environment_locations.rs index 48f093ca..6d26a29e 100644 --- a/crates/pet-conda/src/environment_locations.rs +++ b/crates/pet-conda/src/environment_locations.rs @@ -182,10 +182,7 @@ pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec Vec, +} + +fn get_conda_exe() -> &'static str { + // On CI we expect conda to be in the current path. + "conda" +} + +fn get_conda_info() -> CondaInfo { + // Spawn `conda --version` to get the version of conda as a string + let output = std::process::Command::new(get_conda_exe()) + .args(["info", "--json"]) + .output() + .expect("Failed to execute command"); + let output = String::from_utf8(output.stdout).unwrap(); + let conda_info: CondaInfo = serde_json::from_str(&output).unwrap(); + conda_info +} + +enum CondaCreateEnvNameOrPath { + Name(String), + Path(PathBuf), +} + +fn create_conda_env(mode: &CondaCreateEnvNameOrPath, python_version: Option) { + let mut cli: Vec = vec!["create".to_string()]; + match mode { + CondaCreateEnvNameOrPath::Name(name) => { + cli.push("-n".to_string()); + cli.push(name.to_string()); + } + CondaCreateEnvNameOrPath::Path(path) => { + cli.push("-p".to_string()); + cli.push(path.to_str().unwrap().to_string()); + } + } + if let Some(ref python_version) = python_version { + cli.push(format!("python={}", python_version.as_str())); + } + cli.push("-y".to_string()); + // Spawn `conda --version` to get the version of conda as a string + let _ = std::process::Command::new(get_conda_exe()) + .args(cli) + .output() + .expect("Failed to execute command"); +} + +fn get_version(value: &String) -> String { + // Regex to extract just the d.d.d version from the full version string + let re = regex::Regex::new(r"\d+\.\d+\.\d+").unwrap(); + let captures = re.captures(value).unwrap(); + captures.get(0).unwrap().as_str().to_string() } diff --git a/crates/pet-conda/tests/environment_locations_test.rs b/crates/pet-conda/tests/environment_locations_test.rs index a20dff80..bf3c738d 100644 --- a/crates/pet-conda/tests/environment_locations_test.rs +++ b/crates/pet-conda/tests/environment_locations_test.rs @@ -117,25 +117,3 @@ fn list_conda_envs_in_install_location() { ] ); } - -// #[test] -// fn get_conda_environment_paths_test() { -// let now = SystemTime::now(); -// let env = EnvironmentApi {}; -// let envs = get_conda_environment_paths(&env); -// println!("{:?}", envs); -// println!("{:?}", envs); -// println!("{:?}", envs); -// println!("{:?}", envs); -// println!("{:?}", envs); -// match now.elapsed() { -// Ok(elapsed) => { -// println!("Native Locator took {} milliseconds.", elapsed.as_millis()); -// println!("Native Locator took {} milliseconds.", elapsed.as_millis()); -// println!("Native Locator took {} milliseconds.", elapsed.as_millis()); -// } -// Err(e) => { -// log::error!("Error getting elapsed time: {:?}", e); -// } -// } -// } diff --git a/crates/pet/src/main.rs b/crates/pet/src/main.rs index c2952ebf..f94bf3e2 100644 --- a/crates/pet/src/main.rs +++ b/crates/pet/src/main.rs @@ -21,7 +21,6 @@ enum Commands { fn main() { let cli = Cli::parse(); - println!("{:?}", cli); match cli.command { Some(Commands::Server) => find_and_report_envs_jsonrpc(),