From b3ac0e30ec5115035008bf715542f3d11059c9cb Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 7 Mar 2024 08:44:19 -0800 Subject: [PATCH] Add Conda tests to `system-install.yml` (#2281) Closes https://github.com/astral-sh/uv/issues/2280. --- .github/workflows/system-install.yml | 41 ++++++++++++++++++++++++++++ crates/uv-virtualenv/src/bare.rs | 26 ++++++++++++++---- scripts/check_system_python.py | 10 ++++++- 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/.github/workflows/system-install.yml b/.github/workflows/system-install.yml index 73b95b962..8698a57b6 100644 --- a/.github/workflows/system-install.yml +++ b/.github/workflows/system-install.yml @@ -231,3 +231,44 @@ jobs: - name: "Validate global Python install" run: python3.9 scripts/check_system_python.py --uv ./target/debug/uv + + install-conda: + name: Install on Conda (${{ matrix.python-version }}, ${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: ["ubuntu-latest", "macos-latest", "windows-latest"] + python-version: ["3.8", "3.11"] + steps: + - uses: actions/checkout@v4 + + - uses: conda-incubator/setup-miniconda@v3 + with: + miniconda-version: "latest" + activate-environment: uv + python-version: ${{ matrix.python-version }} + + - name: Conda info + shell: bash -el {0} + run: conda info + + - name: Conda list + shell: pwsh + run: conda list + + - name: "Install Rust toolchain" + run: rustup show + + - uses: Swatinem/rust-cache@v2 + + - name: "Build" + run: cargo build + + - name: "Print Python path" + shell: bash -el {0} + run: echo $(which python) + + - name: "Validate global Python install" + shell: bash -el {0} + run: python ./scripts/check_system_python.py --uv ./target/debug/uv diff --git a/crates/uv-virtualenv/src/bare.rs b/crates/uv-virtualenv/src/bare.rs index 506ce4050..65e591861 100644 --- a/crates/uv-virtualenv/src/bare.rs +++ b/crates/uv-virtualenv/src/bare.rs @@ -179,18 +179,32 @@ pub fn create_bare_venv( match fs_err::copy(shim, scripts.join(python_exe)) { Ok(_) => {} Err(err) if err.kind() == io::ErrorKind::NotFound => { + let launcher = match python_exe { + "python.exe" => "venvwlauncher.exe", + "pythonw.exe" => "venvwlauncher.exe", + _ => unreachable!(), + }; + // If `python.exe` doesn't exist, try the `venvlaucher.exe` shim. let shim = interpreter .stdlib() .join("venv") .join("scripts") .join("nt") - .join(match python_exe { - "python.exe" => "venvwlauncher.exe", - "pythonw.exe" => "venvwlauncher.exe", - _ => unreachable!(), - }); - fs_err::copy(shim, scripts.join(python_exe))?; + .join(launcher); + + // If the `venvwlauncher.exe` shim doesn't exist, then on Conda at least, we + // can look for it next to the Python executable itself. + match fs_err::copy(shim, scripts.join(python_exe)) { + Ok(_) => {} + Err(err) if err.kind() == io::ErrorKind::NotFound => { + let shim = base_python.with_file_name(launcher); + fs_err::copy(shim, scripts.join(python_exe))?; + } + Err(err) => { + return Err(err.into()); + } + } } Err(err) => { return Err(err.into()); diff --git a/scripts/check_system_python.py b/scripts/check_system_python.py index 261f0f646..a4ba8bf6b 100755 --- a/scripts/check_system_python.py +++ b/scripts/check_system_python.py @@ -92,10 +92,18 @@ if __name__ == "__main__": ) logging.info("Installing into virtual environment...") + + # Disable the `CONDA_PREFIX` and `VIRTUAL_ENV` environment variables, so that + # we only rely on virtual environment discovery via the `.venv` directory. + # Our "system Python" here might itself be a Conda environment! + env = os.environ.copy() + env["CONDA_PREFIX"] = "" + env["VIRTUAL_ENV"] = "" subprocess.run( - [uv, "pip", "install", "pylint"], + [uv, "pip", "install", "pylint", "--verbose"], cwd=temp_dir, check=True, + env=env, ) # Ensure that the package (`pylint`) isn't installed globally.