d59c697db6750a9b0cecec22d9abf8277d44f16e

Author
Michael Aquilina <michaelaquilina@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

Merge pull request #33 from MichaelAquilina/0.3.0

Release 0.3.0

Diff

  1diff --git a/CHANGELOG.rst b/CHANGELOG.rst
  2index 90145377bb8914f8aafbea2876ac0b30311fc109..c885807e4363617a9c345f13d94a6d498607a024 100644
  3--- a/CHANGELOG.rst
  4+++ b/CHANGELOG.rst
  5@@ -1,6 +1,12 @@
  6 Changelog
  7 =========
  8 
  9+0.3.0
 10+-----
 11+* Disable plugin and print help message if virtualenvwrapper not setup correctly
 12+* Fix bug in rmvenv when no virtualenv was activated
 13+* Fix flaky tests
 14+
 15 0.2.1
 16 -----
 17 * Add tests for mkvenv and check_venv
 18diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 19index a80a43c61a7a9572ba0d77dab088716112e94c05..faafa873ceccc70b1e1754b904f59857f0347a32 100644
 20--- a/autoswitch_virtualenv.plugin.zsh
 21+++ b/autoswitch_virtualenv.plugin.zsh
 22@@ -1,3 +1,14 @@
 23+if ! type workon > /dev/null; then
 24+    export DISABLE_AUTOSWITCH_VENV="1"
 25+    printf "\e[1m\e[31m"
 26+    printf "zsh-autoswitch-virtualenv requires virtualenvwrapper to be installed!\n\n"
 27+    printf "If this is already installed but you are still seeing this message, add the "
 28+    printf "following to your ~/.zshrc:\n"
 29+    printf "\e[39m"
 30+    printf "source =virtualenvwrapper.sh\n"
 31+    printf "\e[0m"
 32+fi
 33+
 34 function _maybeworkon() {
 35   if [[ -z "$VIRTUAL_ENV" || "$1" != "$(basename $VIRTUAL_ENV)" ]]; then
 36      if [ -z "$AUTOSWITCH_SILENT" ]; then
 37@@ -88,11 +99,17 @@ function _default_venv()
 38 function rmvenv()
 39 {
 40   if [[ -f ".venv" ]]; then
 41+
 42     venv_name="$(<.venv)"
 43-    current_venv="$(basename $VIRTUAL_ENV)"
 44-    if [[ "$current_venv" = "$venv_name" ]]; then
 45-      _default_venv
 46+
 47+    # detect if we need to switch virtualenv first
 48+    if [[ -n "$VIRTUAL_ENV" ]]; then
 49+        current_venv="$(basename $VIRTUAL_ENV)"
 50+        if [[ "$current_venv" = "$venv_name" ]]; then
 51+            _default_venv
 52+        fi
 53     fi
 54+
 55     rmvirtualenv "$venv_name"
 56     rm ".venv"
 57   else
 58diff --git a/tests/test_check_venv.zunit b/tests/test_check_venv.zunit
 59index 38694b5b0e4c20df47b59377b76d58e71cd49b79..d50458c5e3a62d6933c5c8bf95404763b1081b63 100644
 60--- a/tests/test_check_venv.zunit
 61+++ b/tests/test_check_venv.zunit
 62@@ -69,10 +69,11 @@
 63 
 64 @test 'check_venv - deactivate if no .venv available' {
 65     PWD="$TARGET"
 66-    MYOLDPWD="$(dirname $TARGET)"
 67+    MYOLDPWD="$(dirname TARGET)"
 68+    VIRTUAL_ENV="foo"
 69     unset AUTOSWITCH_DEFAULTENV
 70     function deactivate {
 71-        echo deactivating
 72+        echo "deactivating"
 73     }
 74 
 75     run check_venv
 76diff --git a/tests/test_check_venv_path.zunit b/tests/test_check_venv_path.zunit
 77index c844f40caa06de10a203ab1ff7c053bc0be6cf17..0d0ca34b172143e4308cb6681da9b0cfcfb21ca7 100644
 78--- a/tests/test_check_venv_path.zunit
 79+++ b/tests/test_check_venv_path.zunit
 80@@ -2,6 +2,7 @@
 81 
 82 
 83 @setup {
 84+    source =virtualenvwrapper.sh
 85     export DISABLE_AUTOSWITCH_VENV="1"
 86     load "../autoswitch_virtualenv.plugin.zsh"
 87     TARGET="$(mktemp -d)"
 88diff --git a/tests/test_help.zunit b/tests/test_help.zunit
 89new file mode 100644
 90index 0000000000000000000000000000000000000000..b50c2435f18a8cc2c12a33ad4628fe6361abdfbd
 91--- /dev/null
 92+++ b/tests/test_help.zunit
 93@@ -0,0 +1,11 @@
 94+#!/usr/bin/env zunit
 95+
 96+@test 'prints help message and disables plugin if virtualenvwrapper not setup' {
 97+    run load ../autoswitch_virtualenv.plugin.zsh
 98+
 99+    assert $status equals 0
100+    assert "$lines[1]" contains "zsh-autoswitch-virtualenv requires virtualenvwrapper to be installed!"
101+    assert "$lines[2]" is_empty
102+    assert "$lines[3]" contains "If this is already installed but you are still seeing this message, add the following to your ~/.zshrc"
103+    assert "$lines[4]" contains "source =virtualenvwrapper.sh"
104+}