6 Commits

Author SHA1 Message Date
Jovier A. Jiménez
e83e7496fa remove redundant environment variable declaration 2024-09-14 16:26:24 -07:00
Jovier A. Jiménez
6c523f4ce3 add example of custom prompt string 2024-09-14 16:24:29 -07:00
Jovier A. Jiménez
119c4db68c update test setup to unset PYENV_VIRTUALENV_PROMPT 2024-09-14 16:23:01 -07:00
Jovier A. Jiménez
83fae32522 update README with example 2024-02-19 21:30:57 -08:00
Jovier A. Jiménez
96d066e44c update tests 2024-02-19 21:19:08 -08:00
Jovier A. Jiménez
9f3afd0cfb allow users to configure prompt add-on 2024-02-19 21:18:56 -08:00
5 changed files with 64 additions and 1 deletions

View File

@@ -243,6 +243,7 @@ You can set certain environment variables to control pyenv-virtualenv.
* `PIP_VERSION`, if set and `venv` is preferred * `PIP_VERSION`, if set and `venv` is preferred
over `virtualenv`, install the specified version of pip. over `virtualenv`, install the specified version of pip.
* `PYENV_VIRTUALENV_VERBOSE_ACTIVATE`, if set, shows some verbose outputs on activation and deactivation * `PYENV_VIRTUALENV_VERBOSE_ACTIVATE`, if set, shows some verbose outputs on activation and deactivation
* `PYENV_VIRTUALENV_PROMPT`, if set, allows users to customize how `pyenv-virtualenv` modifies their shell prompt. The default prompt ("(venv)") is overwritten with any user-specified text. Specify the location of the virtual environment name with the string `{venv}`. For example, the default prompt string would be `({venv})`.
## Version History ## Version History

View File

@@ -262,9 +262,14 @@ EOS
fi fi
;; ;;
* ) * )
if [ -z "${PYENV_VIRTUALENV_PROMPT}" ]; then
PYENV_VIRTUALENV_PROMPT="(${venv})"
else
PYENV_VIRTUALENV_PROMPT="${PYENV_VIRTUALENV_PROMPT/\{venv\}/${venv}}"
fi
cat <<EOS cat <<EOS
export _OLD_VIRTUAL_PS1="\${PS1:-}"; export _OLD_VIRTUAL_PS1="\${PS1:-}";
export PS1="(${venv}) \${PS1:-}"; export PS1="${PYENV_VIRTUALENV_PROMPT} \${PS1:-}";
EOS EOS
;; ;;
esac esac

View File

@@ -15,6 +15,7 @@ setup() {
unset PYENV_VIRTUALENV_DISABLE_PROMPT unset PYENV_VIRTUALENV_DISABLE_PROMPT
unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT
unset VIRTUAL_ENV_DISABLE_PROMPT unset VIRTUAL_ENV_DISABLE_PROMPT
unset PYENV_VIRTUALENV_PROMPT
unset _OLD_VIRTUAL_PS1 unset _OLD_VIRTUAL_PS1
stub pyenv-hooks "activate : echo" stub pyenv-hooks "activate : echo"
} }
@@ -44,6 +45,31 @@ EOS
unstub pyenv-sh-deactivate unstub pyenv-sh-deactivate
} }
@test "activate virtualenv from current version with custom prompt" {
export PYENV_VIRTUALENV_INIT=1
stub pyenv-version-name "echo venv"
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="bash" PYENV_VERSION="venv" PYENV_VIRTUALENV_PROMPT='venv:{venv}' run pyenv-sh-activate
assert_success
assert_output <<EOS
deactivated
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
export _OLD_VIRTUAL_PS1="\${PS1:-}";
export PS1="venv:venv \${PS1:-}";
EOS
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
}
@test "activate virtualenv from current version (quiet)" { @test "activate virtualenv from current version (quiet)" {
export PYENV_VIRTUALENV_INIT=1 export PYENV_VIRTUALENV_INIT=1

View File

@@ -16,6 +16,7 @@ setup() {
unset PYENV_VIRTUALENV_DISABLE_PROMPT unset PYENV_VIRTUALENV_DISABLE_PROMPT
unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT
unset VIRTUAL_ENV_DISABLE_PROMPT unset VIRTUAL_ENV_DISABLE_PROMPT
unset PYENV_VIRTUALENV_PROMPT
unset _OLD_VIRTUAL_PS1 unset _OLD_VIRTUAL_PS1
stub pyenv-hooks "activate : echo" stub pyenv-hooks "activate : echo"
} }
@@ -53,6 +54,35 @@ EOS
teardown_conda "anaconda-2.3.0" teardown_conda "anaconda-2.3.0"
} }
@test "activate conda root from current version with custom prompt" {
export PYENV_VIRTUALENV_INIT=1
setup_conda "anaconda-2.3.0"
stub pyenv-version-name "echo anaconda-2.3.0"
stub pyenv-virtualenv-prefix "anaconda-2.3.0 : echo \"${PYENV_ROOT}/versions/anaconda-2.3.0\""
stub pyenv-prefix "anaconda-2.3.0 : echo \"${PYENV_ROOT}/versions/anaconda-2.3.0\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="bash" PYENV_VERSION="anaconda-2.3.0" PYENV_VIRTUALENV_PROMPT='venv:{venv}' run pyenv-sh-activate
assert_success
assert_output <<EOS
deactivated
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/anaconda-2.3.0";
export VIRTUAL_ENV="${PYENV_ROOT}/versions/anaconda-2.3.0";
export CONDA_DEFAULT_ENV="root";
export _OLD_VIRTUAL_PS1="\${PS1:-}";
export PS1="venv:anaconda-2.3.0 \${PS1:-}";
export CONDA_PREFIX="${TMP}/pyenv/versions/anaconda-2.3.0";
EOS
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
teardown_conda "anaconda-2.3.0"
}
@test "activate conda root from current version (fish)" { @test "activate conda root from current version (fish)" {
export PYENV_VIRTUALENV_INIT=1 export PYENV_VIRTUALENV_INIT=1

View File

@@ -6,6 +6,7 @@ setup() {
export PYENV_ROOT="${TMP}/pyenv" export PYENV_ROOT="${TMP}/pyenv"
export HOOK_PATH="${TMP}/i has hooks" export HOOK_PATH="${TMP}/i has hooks"
mkdir -p "$HOOK_PATH" mkdir -p "$HOOK_PATH"
unset PYENV_VIRTUALENV_PROMPT
} }
@test "pyenv-virtualenv hooks" { @test "pyenv-virtualenv hooks" {