Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

venv section displays incorrect value when Pipenv's PIPENV_PYTHON environment variable is set #752

Closed
jayBana opened this issue Nov 14, 2019 · 0 comments

Comments

@jayBana
Copy link

jayBana commented Nov 14, 2019

I am using Pipenv in conjunction with Pyenv and in order for Pipenv to respect Pyenv's global and local Python versions, I set the $PIPENV_PYTHON environment variable to the following value $PYENV_ROOT/shims/python as per this section of the Pipenv documentation.

When the $PIPENV_PYTHON env variable is set followed by creating and activating a virtual environment, the value from the $PIPENV_PYTHON env variable is appended to the end of the "usual" $VIRTUAL_ENV value and stored in the $VIRTUAL_ENV env variable as its new value.

As an example:

  • usually in "normal" circumstances the $VIRTUAL_ENV would have the following value: /Users/user_name/.local/share/virtualenvs/test_environment-PVGY9Ddq
  • however, when the $PIPENV_PYTHON env variable is set, then the $VIRTUAL_ENV becomes /Users/user_name/.local/share/virtualenvs/test_environment-PVGY9Ddq-/Users/user_name/.pyenv/shims/python

This is not captured in the logic currently implemented in the venv.zsh and the venv name is shown as python as a result of venv="$VIRTUAL_ENV:t" on line 37

I am currently working around this by changing the spaceship_venv() to the following

# Show current virtual environment (Python).
spaceship_venv() {
  [[ $SPACESHIP_VENV_SHOW == false ]] && return

  # Check if the current directory running via Virtualenv
  [ -n "$VIRTUAL_ENV" ] || return

  local 'venv'

  if [[ "${SPACESHIP_VENV_GENERIC_NAMES[(i)$VIRTUAL_ENV:t]}" -le \
        "${#SPACESHIP_VENV_GENERIC_NAMES}" ]]
  then
    venv="$VIRTUAL_ENV:h:t"
  else
    if [ ! -v PIPENV_PYTHON ]; then
      venv="$VIRTUAL_ENV:t"
    else
      venv=$(echo "$VIRTUAL_ENV" | sed -e "s|.*virtualenvs\/\(.*\)-$PIPENV_PYTHON.*|\1|")
    fi
  fi

However, I don't think that this captures all the edgecases

@spaceship-prompt spaceship-prompt locked and limited conversation to collaborators Jun 11, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Development

No branches or pull requests

2 participants