sindresorhus / pure

Pretty, minimal and fast ZSH prompt
MIT License
13.22k stars 977 forks source link

Unable to remove Conda virtual environment name from Pure prompt #545

Open mattingram0 opened 4 years ago

mattingram0 commented 4 years ago

General information

It seems that the Pure prompt does not respect the changeps1: False setting in my ~/.condarc. When not using the Pure prompt the virtual environment name is hidden as expected.

System report (output of prompt_pure_system_report):

I have:

Problem description

I wish to hide the current Conda environment from the second line of the Pure prompt. Adding changeps1: False to my ~/.condarc has no effect when using Pure.

Reproduction steps

  1. Not using Pure: My ~/.zshrc with Pure deactivated:
export ZSH="/Users/matt/.oh-my-zsh"
#ZSH_THEME=""
#autoload -U promptinit; promptinit
#prompt pure

__conda_setup="$('/Users/matt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/matt/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/matt/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/matt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup

Showing the configuration is set to False, and activating Conda:

matt@Matt MacBook\n ~ % conda config --show-sources
==> /Users/matt/.condarc <==
auto_activate_base: False
changeps1: False
env_prompt:
ssl_verify: True
channels:
  - defaults
  - ostrokach
  - rwest
  - vgauthier

matt@Matt MacBook\n ~ % conda activate
matt@Matt MacBook\n ~ % conda info

     active environment : base
    active env location : /Users/matt/anaconda3
            shell level : 1
       user config file : /Users/matt/.condarc
 populated config files : /Users/matt/.condarc
          conda version : 4.8.3
    conda-build version : 3.17.8
         python version : 3.7.3.final.0
       virtual packages : __osx=10.15.2
       base environment : /Users/matt/anaconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://conda.anaconda.org/ostrokach/osx-64
                          https://conda.anaconda.org/ostrokach/noarch
                          https://conda.anaconda.org/rwest/osx-64
                          https://conda.anaconda.org/rwest/noarch
                          https://conda.anaconda.org/vgauthier/osx-64
                          https://conda.anaconda.org/vgauthier/noarch
          package cache : /Users/matt/anaconda3/pkgs
                          /Users/matt/.conda/pkgs
       envs directories : /Users/matt/anaconda3/envs
                          /Users/matt/.conda/envs
               platform : osx-64
             user-agent : conda/4.8.3 requests/2.23.0 CPython/3.7.3 Darwin/19.2.0 OSX/10.15.2
                UID:GID : 501:20
             netrc file : /Users/matt/.netrc
           offline mode : False
  1. Using Pure: My ~/.zshrc with Pure activated:
    
    export ZSH="/Users/matt/.oh-my-zsh"
    ZSH_THEME=""
    autoload -U promptinit; promptinit
    prompt pure

conda_setup="$('/Users/matt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "/Users/matt/anaconda3/etc/profile.d/conda.sh" ]; then . "/Users/matt/anaconda3/etc/profile.d/conda.sh" else export PATH="/Users/matt/anaconda3/bin:$PATH" fi fi unset conda_setup

Showing the configuration is set to False, and activating Conda:

```shell
~
❯ conda config --show-sources
==> /Users/matt/.condarc <==
auto_activate_base: False
changeps1: False
env_prompt:
ssl_verify: True
channels:
  - defaults
  - ostrokach
  - rwest
  - vgauthier

~
❯ conda activate

~
base ❯ conda info

     active environment : base
    active env location : /Users/matt/anaconda3
            shell level : 1
       user config file : /Users/matt/.condarc
 populated config files : /Users/matt/.condarc
          conda version : 4.8.3
    conda-build version : 3.17.8
         python version : 3.7.3.final.0
       virtual packages : __osx=10.15.2
       base environment : /Users/matt/anaconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://conda.anaconda.org/ostrokach/osx-64
                          https://conda.anaconda.org/ostrokach/noarch
                          https://conda.anaconda.org/rwest/osx-64
                          https://conda.anaconda.org/rwest/noarch
                          https://conda.anaconda.org/vgauthier/osx-64
                          https://conda.anaconda.org/vgauthier/noarch
          package cache : /Users/matt/anaconda3/pkgs
                          /Users/matt/.conda/pkgs
       envs directories : /Users/matt/anaconda3/envs
                          /Users/matt/.conda/envs
               platform : osx-64
             user-agent : conda/4.8.3 requests/2.23.0 CPython/3.7.3 Darwin/19.2.0 OSX/10.15.2
                UID:GID : 501:20
             netrc file : /Users/matt/.netrc
           offline mode : False

Thanks in advance for any help anyone is able to give. I believe it may have something to do with export VIRTUAL_ENV_DISABLE_PROMPT=12.

mijndert commented 4 years ago

I'm running with export VIRTUAL_ENV_DISABLE_PROMPT= and don't have these issues. YMMV.

mafredri commented 4 years ago

@mattingram0 this is actually working as intended. Since Pure is Conda-aware, the user should set conda config --set changeps1 False so that Conda does not interfere with the prompt set by Pure.

If you wish to disable virtualenv display, you can do so by setting export VIRTUAL_ENV_DISABLE_PROMPT=1. The reason Pure sets it to 12 (only when unset) is to detect when the user has manually requested not to show virtualenvs in the prompt. The value 12 is there to disable regular virtualenvs from interfering with the Pure prompt.

You can see https://github.com/sindresorhus/pure/pull/440 for the original discussion regarding this.

mattingram0 commented 4 years ago

I'm running with export VIRTUAL_ENV_DISABLE_PROMPT= and don't have these issues. YMMV.

Thanks for the suggestion, but unfortunately this didn't work.

@mattingram0 this is actually working as intended. Since Pure is Conda-aware, the user should set conda config --set changeps1 False so that Conda does not interfere with the prompt set by Pure.

If you wish to disable virtualenv display, you can do so by setting export VIRTUAL_ENV_DISABLE_PROMPT=1. The reason Pure sets it to 12 (only when unset) is to detect when the user has manually requested not to show virtualenvs in the prompt. The value 12 is there to disable regular virtualenvs from interfering with the Pure prompt.

You can see #440 for the original discussion regarding this.

Hi mafredi, thanks for the suggestion also and the link to that discussion. Apologies for raising this as an 'issue' in the first place if this is the intended behaviour. Unfortunately setting export VIRTUAL_ENV_DISABLE_PROMPT=1 before activating conda does not have the desired effect of removing the (base) from the prompt.

mafredri commented 4 years ago

@mattingram0 you're right, I misremembered this. We don't have a way to turn off Conda env display at the moment and there are multiple issues with that:

  1. We don't want to parse user configuration files in Pure - if it's not part of the environment, we don't know about it
  2. Conda provides no other facility than conda config --set changeps1 False to prevent it from modifying the prompt, and this is needed to keep Pure pristine
  3. We don't want to repurpose VIRTUAL_ENV_DISABLE_PROMPT for Conda because that variable already belongs to regular virtualenv and asking users to enable something that will break another thing is not cool
  4. If at all possible, we'd like to avoid introducing a Conda-specific option for Pure

This is what I can recall from the last time I researched Conda, anyway. Open to new ideas for solving this though because forcing the virtualenv display is definitely not ideal.

mattingram0 commented 4 years ago

@mattingram0 you're right, I misremembered this. We don't have a way to turn off Conda env display at the moment and there are multiple issues with that:

  1. We don't want to parse user configuration files in Pure - if it's not part of the environment, we don't know about it
  2. Conda provides no other facility than conda config --set changeps1 False to prevent it from modifying the prompt, and this is needed to keep Pure pristine
  3. We don't want to repurpose VIRTUAL_ENV_DISABLE_PROMPT for Conda because that variable already belongs to regular virtualenv and asking users to enable something that will break another thing is not cool
  4. If at all possible, we'd like to avoid introducing a Conda-specific option for Pure

This is what I can recall from the last time I researched Conda, anyway. Open to new ideas for solving this though because forcing the virtualenv display is definitely not ideal.

Hi again @mafredi, I've done a bit more digging and I think I might have come up with a solution to this. It seems that the CONDA_PROMPT_MODIFIER env var is not set if changeps1 = false appears in .condarc, and is set to (base) (for example) if changeps1 = true. So could this be used by Pure to detect if the prompt should be modified or not?

mafredri commented 4 years ago

@mattingram0 it would be an ok approach, but for that to work we would need an alternative way to tell Conda not to modify the prompt when Pure manages it. Last time I dug through the source of Conda, I could not find anything like that.

This is where we're at:

  1. Pure never wants Conda to modify the prompt, Pure will do the heavy lifting
  2. Conda only has an on/off toggle for modifying the prompt (changeps1)

For 1) we currently rely on 2). We're telling Conda, don't touch PS1, but tell us your environment and we'll display it. If we were to rely on 2) for deciding wether or not to display the environment, we would have no way to achieve 1).

adigitoleo commented 4 years ago

Hi,

I just stumbled across Pure while setting up a new machine with zsh, and then I wanted to check if it worked with conda (maybe a heads-up in the REDME?) so somehow I stumbled into this issue and here we are...

I remember having the same trouble with the conda prompt modification before, when I wanted to make a custom prompt. As @mafredri said, the CONDA_PROMPT_MODIFIER is not reliable for people who want to customize rather than just remove the conda env hint.

However, this answer on SO led me to the env_prompt setting in .condarc which controls the formatting of the prompt modifier. I just remembered about it while reading this, and maybe it could be used somehow?

@mattingram0 As a naive and hackish workaround, you could try setting env_prompt to an empty string, instead of using changeps1. I will install pure and conda and try it out myself tomorrow.

johnpyp commented 4 years ago

I stumbled across this issue today, and after trying all of the mentioned possible fixes and following stackoverflow threads to no avail, I found a maybe-solution that probably breaks things that I'm unaware of, but it's working for me at the moment.

In the pure code it just checks if the CONDA_DEFAULT_ENV variable is set, and if so display it. So I just did export CONDA_DEFAULT_ENV="" and it seems to have worked. This probably breaks stuff in conda, but I didn't notice anything so far, at least not any issues that affect my acute usage of conda.