[ty] distinguish base conda from child conda by Gankra · Pull Request #19990 · astral-sh/ruff (original) (raw)

@Gankra

Gankra

@Gankra Gankra added the ty

Multi-file analysis & type inference

label

Aug 19, 2025

zanieb

MichaReiser

@Gankra Gankra deleted the gankra/conda-venv branch

August 20, 2025 13:07

dcreager added a commit that referenced this pull request

Aug 21, 2025

@dcreager

Gankra added a commit that referenced this pull request

Oct 3, 2025

@Danielkonge @Gankra

Summary

#19990 didn't completely fix the base vs. child conda environment distinction, since it detected slightly different behavior than what I usually see in conda. E.g., I see something like the following:

(didn't yet activate conda, but base is active)
➜ printenv | grep CONDA
CONDA_PYTHON_EXE=/opt/anaconda3/bin/python
CONDA_PREFIX=/opt/anaconda3
CONDA_DEFAULT_ENV=base
CONDA_EXE=/opt/anaconda3/bin/conda
CONDA_SHLVL=1
CONDA_PROMPT_MODIFIER=(base)

(activating conda)
➜ conda activate test

(test is an active conda environment)
❯ printenv | grep CONDA
CONDA_PREFIX=/opt/anaconda3/envs/test
CONDA_PYTHON_EXE=/opt/anaconda3/bin/python
CONDA_SHLVL=2
CONDA_PREFIX_1=/opt/anaconda3
CONDA_DEFAULT_ENV=test
CONDA_PROMPT_MODIFIER=(test)
CONDA_EXE=/opt/anaconda3/bin/conda

But the current behavior looks for CONDA_DEFAULT_ENV = basename(CONDA_PREFIX) for the base environment instead of the child environment, where we actually see this equality.

This pull request fixes that and updates the tests correspondingly.

Test Plan

I updated the existing tests with the new behavior. Let me know if you want more tests. Note: It shouldn't be necessary to test for the case where we have conda/envs/base, since one should not be able to create such an environment (one with the name of CONDA_DEFAULT_ENV).


Co-authored-by: Aria Desires aria.desires@gmail.com

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})