From 503a51564e0d34c3929b162457ac8a6493e9a4a8 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Sat, 25 Jan 2014 19:14:58 +0900 Subject: [PATCH] Display error if `pyenv activate` was invoked as a command --- bin/pyenv-activate | 26 ++++++++++++++++++++++++++ bin/pyenv-deactivate | 21 +++++++++++++++++++++ test/activate.bats | 6 ++++++ test/deactivate.bats | 6 ++++++ 4 files changed, 59 insertions(+) create mode 100755 bin/pyenv-activate create mode 100755 bin/pyenv-deactivate diff --git a/bin/pyenv-activate b/bin/pyenv-activate new file mode 100755 index 0000000..aaa8d7d --- /dev/null +++ b/bin/pyenv-activate @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# +# Summary: Activate virtual environment +# +# Usage: pyenv activate +# pyenv activate --unset +# +# Activate a Python virtualenv environment in current shell. +# This acts almost as same as `pyenv shell`, but this invokes the `activate` +# script in your shell. +# +# should be a string matching a Python version known to pyenv. + +set -e +[ -n "$PYENV_DEBUG" ] && set -x + +{ printf "\x1B[31;1m" + echo + echo "Failed to activate virtualenv." + echo + echo "Perhaps pyenv-virtualenv has not been loaded into your shell properly." + echo "Please restart current shell and try again." + echo + printf "\x1B[0m" +} 1>&2 +exit 1 diff --git a/bin/pyenv-deactivate b/bin/pyenv-deactivate new file mode 100755 index 0000000..7d9e1d7 --- /dev/null +++ b/bin/pyenv-deactivate @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# +# Summary: Deactivate virtual environment +# +# Usage: pyenv deactivate +# +# Deactivate a Python virtual environment. + +set -e +[ -n "$PYENV_DEBUG" ] && set -x + +{ printf "\x1B[31;1m" + echo + echo "Failed to deactivate virtualenv." + echo + echo "Perhaps pyenv-virtualenv has not been loaded into your shell properly." + echo "Please restart current shell and try again." + echo + printf "\x1B[0m" +} 1>&2 +exit 1 diff --git a/test/activate.bats b/test/activate.bats index ecbdeb6..0dd5c42 100644 --- a/test/activate.bats +++ b/test/activate.bats @@ -85,3 +85,9 @@ EOS pyenv-virtualenv: cannot activate multiple versions at once: venv venv27 EOS } + +@test "should fail if activate is invoked as a command" { + run pyenv-activate + + assert_failure +} diff --git a/test/deactivate.bats b/test/deactivate.bats index cc0f186..16c8fdb 100644 --- a/test/deactivate.bats +++ b/test/deactivate.bats @@ -25,3 +25,9 @@ functions -q deactivate; and deactivate pyenv shell --unset EOS } + +@test "should fail if deactivate is invoked as a command" { + run pyenv-deactivate + + assert_failure +}