diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 0a5161e0..75ddb280 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -32,12 +32,12 @@ jobs: - os: ubuntu-latest target: x86_64-unknown-linux-musl run_cli: "yes" - - os: macos-latest - target: x86_64-apple-darwin - run_cli: "yes" - - os: macos-14 - target: aarch64-apple-darwin - run_cli: "yes" + # - os: macos-latest + # target: x86_64-apple-darwin + # run_cli: "yes" + # - os: macos-14 + # target: aarch64-apple-darwin + # run_cli: "yes" steps: - name: Checkout uses: actions/checkout@v4 @@ -211,287 +211,287 @@ jobs: RUST_LOG: trace shell: bash - isolated-tests: - # Some of these tests are very specific and need to be run in isolation. - # E.g. we need to ensure we have a poetry project setup correctly (without .venv created using `pip -m venv .venv`). - # We can try to use the previous `tests` job, but that gets very complicated. - name: Env Tests - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - include: - - feature: ci-poetry-global # Poetry tests with envs stored in standard location - os: ubuntu-latest - target: x86_64-unknown-linux-musl - - feature: ci-poetry-project # Poetry tests, with poetry envs in project - os: ubuntu-latest - target: x86_64-unknown-linux-musl - - feature: ci-poetry-custom # Poetry tests with envs stored in a custom location - os: ubuntu-latest - target: x86_64-unknown-linux-musl - - feature: ci-poetry-global # Poetry tests with envs stored in standard location - os: windows-latest - target: x86_64-pc-windows-msvc - - feature: ci-poetry-project # Poetry tests, with poetry envs in project - os: windows-latest - target: x86_64-pc-windows-msvc - - feature: ci-poetry-custom # Poetry tests with envs stored in a custom location - os: windows-latest - target: x86_64-pc-windows-msvc - steps: - - name: Checkout - uses: actions/checkout@v4 - - # region Setup Poetry - - name: Set Python 3.x to PATH - if: startsWith( matrix.feature, 'ci-poetry') - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - - name: Set Python 3.12 to PATH - if: startsWith( matrix.feature, 'ci-poetry') - id: setupPython312 - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - - name: Set Python 3.11 to PATH - if: startsWith( matrix.feature, 'ci-poetry') - id: setupPython311 - uses: actions/setup-python@v5 - with: - python-version: "3.11" - - - name: Python 3.12 Path - if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'windows') - run: echo "PYTHON_3_12_PATH=${{ steps.setupPython312.outputs.python-path }}" >> $GITHUB_ENV - shell: bash - - - name: Python 3.12 Path - if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'windows') - run: echo $PYTHON_3_12_PATH - shell: bash - - - name: Python 3.11 Path - if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'windows') - run: echo "PYTHON_3_11_PATH=${{ steps.setupPython311.outputs.python-path }}" >> $GITHUB_ENV - shell: bash - - - name: Install Poetry (envs globally) - if: startsWith( matrix.feature, 'ci-poetry-global') - uses: snok/install-poetry@93ada01c735cc8a383ce0ce2ae205a21c415379b - with: - virtualenvs-create: true - virtualenvs-in-project: false - installer-parallel: true - - - name: Install Poetry (env locally) - if: startsWith( matrix.feature, 'ci-poetry-project') - uses: snok/install-poetry@93ada01c735cc8a383ce0ce2ae205a21c415379b - with: - virtualenvs-create: true - virtualenvs-in-project: true - installer-parallel: true - - - name: Install Poetry (env locally) - if: startsWith( matrix.feature, 'ci-poetry-custom') - uses: snok/install-poetry@93ada01c735cc8a383ce0ce2ae205a21c415379b - with: - virtualenvs-create: true - virtualenvs-in-project: false - virtualenvs-path: ~/my-custom-path - installer-parallel: true - - - name: Poetry exe - if: startsWith( matrix.feature, 'ci-poetry') - run: which poetry - shell: bash - - - name: Poetry config - if: startsWith( matrix.feature, 'ci-poetry') - run: poetry config --list - shell: bash - - - name: Poetry setup - if: startsWith( matrix.feature, 'ci-poetry') - # We want to have 2 envs for this poetry project 3.12 and 3.11. - run: poetry init --name=pet-test --python=^3.11 -q -n - shell: bash - - - name: Poetry virtual env setup 3.12 - if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'ubuntu') - run: poetry env use 3.12 - shell: bash - - - name: Poetry virtual env setup 3.12 - if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'windows') - run: poetry env use $PYTHON_3_12_PATH - shell: bash - - - name: Poetry virtual env setup 3.11 - if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'ubuntu') - run: poetry env use 3.11 - shell: bash - - - name: Poetry virtual env setup 3.11 - if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'windows') - run: poetry env use $PYTHON_3_11_PATH - shell: bash - - - name: Poetry list envs - if: startsWith( matrix.feature, 'ci-poetry') - run: poetry env list - shell: bash - - - name: Poetry pyproject.toml - if: startsWith( matrix.feature, 'ci-poetry') - run: cat pyproject.toml - shell: bash - - # # Dump env vars - # - name: Env - # run: set - # shell: bash - - # endregion - - # Rust - - name: Rust Tool Chain setup - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - targets: ${{ matrix.target }} - - - name: Cargo Fetch - run: cargo fetch - shell: bash - - - name: Find Environments - run: cargo run --release --target ${{ matrix.target }} -- find -v -l - shell: bash - - - name: Run Tests - # Run integration tests in a single thread, - # We end up creating conda envs and running multiple tests in parallel - # that creat conda envs simultaneously causes issues (sometimes the conda envs do not seem to get created) - # Similar issues were identified in vscode-jupyter tests as well (something to do with conda lock files or the like) - run: cargo test --frozen --features ${{ matrix.feature }} -- --nocapture --test-threads=1 - env: - RUST_BACKTRACE: 1 - RUST_LOG: trace - shell: bash - - container-tests: - # These tests are required as its not easy/possible to use the previous jobs. - # E.g. we need to test against the jupyter container, as we found some issues specific to that env. - name: Tests in Containers - container: - image: ${{ matrix.image }} - options: --user=root - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - include: - - feature: ci-jupyter-container - os: ubuntu-latest - # For Tests again the container used in https://github.com/github/codespaces-jupyter - image: mcr.microsoft.com/devcontainers/universal:2.11.1 - target: x86_64-unknown-linux-musl - - feature: ci-homebrew-container - os: ubuntu-latest - # For Homebrew in Ubuntu - image: homebrew/brew - target: x86_64-unknown-linux-musl - steps: - - name: Checkout - uses: actions/checkout@v4 - - # Homebrew - - name: Homebrew Python - if: startsWith( matrix.image, 'homebrew') - run: | - # homebrew/brew:4.4.6 broke running `brew install` as root. - # As a workaround, running `brew update` and ignoring errors coming from it fixes `brew install`. - brew update || true - brew install python@3.12 python@3.11 - shell: bash - - # Rust - - name: Rust Tool Chain setup - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - targets: ${{ matrix.target }} - - - name: Cargo Fetch - run: cargo fetch - shell: bash - - - name: Find Environments - run: cargo run --release --target ${{ matrix.target }} -- find -v -l - shell: bash - - - name: Run Tests - run: cargo test --frozen --features ${{ matrix.feature }} -- --nocapture - shell: bash - - builds: - name: Builds - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - include: - - os: windows-latest - target: x86_64-pc-windows-msvc - - os: windows-latest - target: aarch64-pc-windows-msvc - - 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 - # target: aarch64-unknown-linux-musl - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Rust Tool Chain setup - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - targets: ${{ matrix.target }} - - - name: Cargo Fetch - run: cargo fetch - shell: bash - - - name: Run Tests - # 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 - run: cargo build --release --target ${{ matrix.target }} - shell: bash - - - name: Upload Artifact - uses: actions/upload-artifact@v4 - with: - name: pet-${{ matrix.target }} - path: target/${{ matrix.target }}/release/pet* + # isolated-tests: + # # Some of these tests are very specific and need to be run in isolation. + # # E.g. we need to ensure we have a poetry project setup correctly (without .venv created using `pip -m venv .venv`). + # # We can try to use the previous `tests` job, but that gets very complicated. + # name: Env Tests + # runs-on: ${{ matrix.os }} + # strategy: + # fail-fast: false + # matrix: + # include: + # - feature: ci-poetry-global # Poetry tests with envs stored in standard location + # os: ubuntu-latest + # target: x86_64-unknown-linux-musl + # - feature: ci-poetry-project # Poetry tests, with poetry envs in project + # os: ubuntu-latest + # target: x86_64-unknown-linux-musl + # - feature: ci-poetry-custom # Poetry tests with envs stored in a custom location + # os: ubuntu-latest + # target: x86_64-unknown-linux-musl + # - feature: ci-poetry-global # Poetry tests with envs stored in standard location + # os: windows-latest + # target: x86_64-pc-windows-msvc + # - feature: ci-poetry-project # Poetry tests, with poetry envs in project + # os: windows-latest + # target: x86_64-pc-windows-msvc + # - feature: ci-poetry-custom # Poetry tests with envs stored in a custom location + # os: windows-latest + # target: x86_64-pc-windows-msvc + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + + # # region Setup Poetry + # - name: Set Python 3.x to PATH + # if: startsWith( matrix.feature, 'ci-poetry') + # uses: actions/setup-python@v5 + # with: + # python-version: "3.12" + + # - name: Set Python 3.12 to PATH + # if: startsWith( matrix.feature, 'ci-poetry') + # id: setupPython312 + # uses: actions/setup-python@v5 + # with: + # python-version: "3.12" + + # - name: Set Python 3.11 to PATH + # if: startsWith( matrix.feature, 'ci-poetry') + # id: setupPython311 + # uses: actions/setup-python@v5 + # with: + # python-version: "3.11" + + # - name: Python 3.12 Path + # if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'windows') + # run: echo "PYTHON_3_12_PATH=${{ steps.setupPython312.outputs.python-path }}" >> $GITHUB_ENV + # shell: bash + + # - name: Python 3.12 Path + # if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'windows') + # run: echo $PYTHON_3_12_PATH + # shell: bash + + # - name: Python 3.11 Path + # if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'windows') + # run: echo "PYTHON_3_11_PATH=${{ steps.setupPython311.outputs.python-path }}" >> $GITHUB_ENV + # shell: bash + + # - name: Install Poetry (envs globally) + # if: startsWith( matrix.feature, 'ci-poetry-global') + # uses: snok/install-poetry@93ada01c735cc8a383ce0ce2ae205a21c415379b + # with: + # virtualenvs-create: true + # virtualenvs-in-project: false + # installer-parallel: true + + # - name: Install Poetry (env locally) + # if: startsWith( matrix.feature, 'ci-poetry-project') + # uses: snok/install-poetry@93ada01c735cc8a383ce0ce2ae205a21c415379b + # with: + # virtualenvs-create: true + # virtualenvs-in-project: true + # installer-parallel: true + + # - name: Install Poetry (env locally) + # if: startsWith( matrix.feature, 'ci-poetry-custom') + # uses: snok/install-poetry@93ada01c735cc8a383ce0ce2ae205a21c415379b + # with: + # virtualenvs-create: true + # virtualenvs-in-project: false + # virtualenvs-path: ~/my-custom-path + # installer-parallel: true + + # - name: Poetry exe + # if: startsWith( matrix.feature, 'ci-poetry') + # run: which poetry + # shell: bash + + # - name: Poetry config + # if: startsWith( matrix.feature, 'ci-poetry') + # run: poetry config --list + # shell: bash + + # - name: Poetry setup + # if: startsWith( matrix.feature, 'ci-poetry') + # # We want to have 2 envs for this poetry project 3.12 and 3.11. + # run: poetry init --name=pet-test --python=^3.11 -q -n + # shell: bash + + # - name: Poetry virtual env setup 3.12 + # if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'ubuntu') + # run: poetry env use 3.12 + # shell: bash + + # - name: Poetry virtual env setup 3.12 + # if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'windows') + # run: poetry env use $PYTHON_3_12_PATH + # shell: bash + + # - name: Poetry virtual env setup 3.11 + # if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'ubuntu') + # run: poetry env use 3.11 + # shell: bash + + # - name: Poetry virtual env setup 3.11 + # if: startsWith( matrix.feature, 'ci-poetry') && startsWith( matrix.os, 'windows') + # run: poetry env use $PYTHON_3_11_PATH + # shell: bash + + # - name: Poetry list envs + # if: startsWith( matrix.feature, 'ci-poetry') + # run: poetry env list + # shell: bash + + # - name: Poetry pyproject.toml + # if: startsWith( matrix.feature, 'ci-poetry') + # run: cat pyproject.toml + # shell: bash + + # # # Dump env vars + # # - name: Env + # # run: set + # # shell: bash + + # # endregion + + # # Rust + # - name: Rust Tool Chain setup + # uses: dtolnay/rust-toolchain@stable + # with: + # toolchain: stable + # targets: ${{ matrix.target }} + + # - name: Cargo Fetch + # run: cargo fetch + # shell: bash + + # - name: Find Environments + # run: cargo run --release --target ${{ matrix.target }} -- find -v -l + # shell: bash + + # - name: Run Tests + # # Run integration tests in a single thread, + # # We end up creating conda envs and running multiple tests in parallel + # # that creat conda envs simultaneously causes issues (sometimes the conda envs do not seem to get created) + # # Similar issues were identified in vscode-jupyter tests as well (something to do with conda lock files or the like) + # run: cargo test --frozen --features ${{ matrix.feature }} -- --nocapture --test-threads=1 + # env: + # RUST_BACKTRACE: 1 + # RUST_LOG: trace + # shell: bash + + # container-tests: + # # These tests are required as its not easy/possible to use the previous jobs. + # # E.g. we need to test against the jupyter container, as we found some issues specific to that env. + # name: Tests in Containers + # container: + # image: ${{ matrix.image }} + # options: --user=root + # runs-on: ${{ matrix.os }} + # strategy: + # fail-fast: false + # matrix: + # include: + # - feature: ci-jupyter-container + # os: ubuntu-latest + # # For Tests again the container used in https://github.com/github/codespaces-jupyter + # image: mcr.microsoft.com/devcontainers/universal:2.11.1 + # target: x86_64-unknown-linux-musl + # - feature: ci-homebrew-container + # os: ubuntu-latest + # # For Homebrew in Ubuntu + # image: homebrew/brew + # target: x86_64-unknown-linux-musl + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + + # # Homebrew + # - name: Homebrew Python + # if: startsWith( matrix.image, 'homebrew') + # run: | + # # homebrew/brew:4.4.6 broke running `brew install` as root. + # # As a workaround, running `brew update` and ignoring errors coming from it fixes `brew install`. + # brew update || true + # brew install python@3.12 python@3.11 + # shell: bash + + # # Rust + # - name: Rust Tool Chain setup + # uses: dtolnay/rust-toolchain@stable + # with: + # toolchain: stable + # targets: ${{ matrix.target }} + + # - name: Cargo Fetch + # run: cargo fetch + # shell: bash + + # - name: Find Environments + # run: cargo run --release --target ${{ matrix.target }} -- find -v -l + # shell: bash + + # - name: Run Tests + # run: cargo test --frozen --features ${{ matrix.feature }} -- --nocapture + # shell: bash + + # builds: + # name: Builds + # runs-on: ${{ matrix.os }} + # strategy: + # fail-fast: false + # matrix: + # include: + # - os: windows-latest + # target: x86_64-pc-windows-msvc + # - os: windows-latest + # target: aarch64-pc-windows-msvc + # - 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 + # # target: aarch64-unknown-linux-musl + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + + # - name: Rust Tool Chain setup + # uses: dtolnay/rust-toolchain@stable + # with: + # toolchain: stable + # targets: ${{ matrix.target }} + + # - name: Cargo Fetch + # run: cargo fetch + # shell: bash + + # - name: Run Tests + # # 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 + # run: cargo build --release --target ${{ matrix.target }} + # shell: bash + + # - name: Upload Artifact + # uses: actions/upload-artifact@v4 + # with: + # name: pet-${{ matrix.target }} + # path: target/${{ matrix.target }}/release/pet* diff --git a/crates/pet-conda/src/environments.rs b/crates/pet-conda/src/environments.rs index 399bac68..bed01b63 100644 --- a/crates/pet-conda/src/environments.rs +++ b/crates/pet-conda/src/environments.rs @@ -30,30 +30,27 @@ impl CondaEnvironment { get_conda_environment_info(path, manager) } - pub fn to_python_environment( - &self, - conda_dir: Option, - conda_manager: Option, - ) -> PythonEnvironment { + pub fn to_python_environment(&self, conda_manager: Option) -> PythonEnvironment { #[allow(unused_assignments)] let mut name: Option = None; - if is_conda_install(&self.prefix) { - name = Some("base".to_string()); - } else { - name = self - .prefix - .file_name() - .map(|name| name.to_str().unwrap_or_default().to_string()); - } - // if the conda install folder is parent of the env folder, then we can use named activation. - // E.g. conda env is = /envs/ - // Then we can use `/bin/conda activate -n ` - if let Some(conda_dir) = conda_dir { - if !self.prefix.starts_with(conda_dir) { - name = None; + + // We can name the conda envs only if we have a conda manager. + if let Some(conda_manager) = &conda_manager { + // If the conda manager for this environment is in the same folder as the conda environment, + // Then this is a root conda environment. + if conda_manager.executable.starts_with(&self.prefix) + && is_conda_install(&self.prefix) + && self.conda_dir.is_some() + { + name = Some("base".to_string()); + } else { + name = self + .prefix + .file_name() + .map(|name| name.to_str().unwrap_or_default().to_string()); } } - // This is a root env. + let builder = PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::Conda)) .executable(self.executable.clone()) .version(self.version.clone()) @@ -75,11 +72,10 @@ pub fn get_conda_environment_info( // Not a conda environment (neither root nor a separate env). return None; } - // If we know the conda install folder, then we can use it. - let mut conda_install_folder = manager - .clone() - .and_then(|m| m.conda_dir) - .or_else(|| get_conda_installation_used_to_create_conda_env(env_path)); + // Even if we have the conda manager, always fid the conda manager based on the env. + // & then use the given conda manager as a fallback. + let mut conda_install_folder = get_conda_installation_used_to_create_conda_env(env_path) + .or_else(|| manager.clone().and_then(|m| m.conda_dir)); if let Some(conda_dir) = &conda_install_folder { if conda_dir.exists() { diff --git a/crates/pet-conda/src/lib.rs b/crates/pet-conda/src/lib.rs index 6e035a1a..6be830aa 100644 --- a/crates/pet-conda/src/lib.rs +++ b/crates/pet-conda/src/lib.rs @@ -174,8 +174,7 @@ impl CondaLocator for Conda { if environments.contains_key(&conda_env.prefix) { continue; } - let env = conda_env - .to_python_environment(Some(conda_dir.clone()), Some(manager.to_manager())); + let env = conda_env.to_python_environment(Some(manager.to_manager())); environments.insert(conda_env.prefix.clone(), env.clone()); reporter.report_manager(&manager.to_manager()); reporter.report_environment(&env); @@ -248,10 +247,7 @@ impl Locator for Conda { if let Some(env) = get_conda_environment_info(path, &None) { if let Some(conda_dir) = &env.conda_dir { if let Some(manager) = self.get_manager(conda_dir) { - let env = env.to_python_environment( - Some(conda_dir.clone()), - Some(manager.to_manager()), - ); + let env = env.to_python_environment(Some(manager.to_manager())); environments.insert(path.clone(), env.clone()); return Some(env); } else { @@ -259,7 +255,7 @@ impl Locator for Conda { // This might seem incorrect, however the tool is about discovering environments. // The client can activate this env either using another conda manager or using the activation scripts error!("Unable to find Conda Manager for env (even though we have a conda_dir): {:?}", env); - let env = env.to_python_environment(Some(conda_dir.clone()), None); + let env = env.to_python_environment(None); environments.insert(path.clone(), env.clone()); return Some(env); } @@ -268,7 +264,7 @@ impl Locator for Conda { // This might seem incorrect, however the tool is about discovering environments. // The client can activate this env either using another conda manager or using the activation scripts error!("Unable to find Conda Manager for env: {:?}", env); - let env = env.to_python_environment(None, None); + let env = env.to_python_environment(None); environments.insert(path.clone(), env.clone()); return Some(env); } @@ -301,7 +297,7 @@ impl Locator for Conda { // The client can activate this env either using another conda manager or using the activation scripts error!("Unable to find Conda Manager for the Conda env: {:?}", env); let prefix = env.prefix.clone(); - let env = env.to_python_environment(None, None); + let env = env.to_python_environment(None); let mut environments = self.environments.lock().unwrap(); environments.insert(prefix, env.clone()); reporter.report_environment(&env); @@ -340,7 +336,6 @@ impl Locator for Conda { // 5. Report this env. if let Some(manager) = manager { let env = env.to_python_environment( - manager.conda_dir.clone(), Some(manager.to_manager()), ); let mut environments = self.environments.lock().unwrap(); @@ -352,7 +347,7 @@ impl Locator for Conda { // This might seem incorrect, however the tool is about discovering environments. // The client can activate this env either using another conda manager or using the activation scripts error!("Unable to find Conda Manager for Conda env (even though we have a conda_dir {:?}): Env Details = {:?}", conda_dir, env); - let env = env.to_python_environment(Some(conda_dir.clone()), None); + let env = env.to_python_environment(None); let mut environments = self.environments.lock().unwrap(); environments.insert(prefix.clone(), env.clone()); reporter.report_environment(&env); diff --git a/crates/pet-conda/tests/lib_test.rs b/crates/pet-conda/tests/lib_test.rs index 7efa4ff1..a85305f0 100644 --- a/crates/pet-conda/tests/lib_test.rs +++ b/crates/pet-conda/tests/lib_test.rs @@ -32,7 +32,7 @@ fn find_conda_env_without_manager() { assert_eq!(env.executable, path.join("bin").join("python").into()); assert_eq!(env.version, "3.12.2".to_string().into()); assert_eq!(env.manager, None); - assert_eq!(env.name, "env_python_3".to_string().into()); + assert_eq!(env.name, None); } #[cfg(unix)] @@ -90,5 +90,5 @@ fn find_conda_env_without_manager_but_detect_manager_from_history() { env.manager.clone().unwrap().version, "23.1.0".to_string().into() ); - assert_eq!(env.name, None); + assert_eq!(env.name, "env_python_3".to_string().into()); } diff --git a/crates/pet/tests/ci_test.rs b/crates/pet/tests/ci_test.rs index 4891e14d..33baad9e 100644 --- a/crates/pet/tests/ci_test.rs +++ b/crates/pet/tests/ci_test.rs @@ -92,7 +92,7 @@ fn verify_validity_of_discovered_envs() { ); let environments = reporter.environments.lock().unwrap().clone(); - let mut threads = vec![]; + // let mut threads = vec![]; for environment in environments { if environment.executable.is_none() { continue; @@ -101,32 +101,32 @@ fn verify_validity_of_discovered_envs() { // For each enviornment verify the accuracy of sys.prefix and sys.version // by spawning the Python executable let e = environment.clone(); - threads.push(thread::spawn(move || { - verify_validity_of_interpreter_info(e); - })); + // threads.push(thread::spawn(move || { + verify_validity_of_interpreter_info(e); + // })); let e = environment.clone(); - threads.push(thread::spawn(move || { - for exe in &e.clone().symlinks.unwrap_or_default() { - // Verification 2: - // For each enviornment, given the executable verify we can get the exact same information - // Using the `locator.try_from` method (without having to find all environments). - // I.e. we should be able to get the same information using only the executable. - // - // Verification 3: - // Similarly for each environment use one of the known symlinks and verify we can get the same information. - verify_we_can_get_same_env_info_using_from_with_exe(exe, environment.clone()); - // Verification 4 & 5: - // Similarly for each environment use resolve method and verify we get the exact same information. - verify_we_can_get_same_env_info_using_resolve_with_exe(exe, environment.clone()); - // Verification 6: - // Given the exe, verify we can use the `find` method in JSON RPC to get the details, without spawning Python. - verify_we_can_get_same_env_info_using_find_with_exe(exe, environment.clone()); - } - })); - } - for thread in threads { - thread.join().unwrap(); + // threads.push(thread::spawn(move || { + for exe in &e.clone().symlinks.unwrap_or_default() { + // Verification 2: + // For each enviornment, given the executable verify we can get the exact same information + // Using the `locator.try_from` method (without having to find all environments). + // I.e. we should be able to get the same information using only the executable. + // + // Verification 3: + // Similarly for each environment use one of the known symlinks and verify we can get the same information. + verify_we_can_get_same_env_info_using_from_with_exe(exe, environment.clone()); + // Verification 4 & 5: + // Similarly for each environment use resolve method and verify we get the exact same information. + verify_we_can_get_same_env_info_using_resolve_with_exe(exe, environment.clone()); + // Verification 6: + // Given the exe, verify we can use the `find` method in JSON RPC to get the details, without spawning Python. + verify_we_can_get_same_env_info_using_find_with_exe(exe, environment.clone()); + } + // })); } + // for thread in threads { + // thread.join().unwrap(); + // } } #[cfg(unix)] @@ -719,10 +719,11 @@ fn get_python_run_command(env: &PythonEnvironment) -> Vec { if env.executable.is_none() { panic!("Conda environment without executable"); } - let conda_exe = match env.manager.clone() { - Some(manager) => manager.executable.to_str().unwrap_or_default().to_string(), - None => get_conda_exe().to_string(), - }; + let mut conda_exe = get_conda_exe().to_string(); + + if let Some(manager) = &env.manager { + conda_exe = manager.executable.to_str().unwrap_or_default().to_string(); + } if let Some(name) = env.name.clone() { return vec![ conda_exe, @@ -767,6 +768,7 @@ fn get_python_interpreter_info(cli: &Vec) -> InterpreterInfo { .output() .expect(format!("Failed to execute command {cli:?}").as_str()); let output = String::from_utf8(output.stdout).unwrap(); + trace!("Execute Python {:?} Output: {output:?}", cli); let output = output .split_once("503bebe7-c838-4cea-a1bc-0f2963bcb657") .unwrap()