1ab79589b87f7df939fa0a7351789250f6d8e485

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

Message

Remove virtualenv requirement on load

Will now only be required with running mkvenv.
This will allow using Pipenv

Diff

  1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
  2index 7616b3e8298cdd87542ec3a6e09eaa783fcb783a..96a8d749f4605c1adde8499e6a8b28854b057bc6 100644
  3--- a/autoswitch_virtualenv.plugin.zsh
  4+++ b/autoswitch_virtualenv.plugin.zsh
  5@@ -177,6 +177,16 @@ function rmvenv()
  6 # helper function to create a virtual environment for the current directory
  7 function mkvenv()
  8 {
  9+    if ! type "virtualenv" > /dev/null; then
 10+        printf "${BOLD}${RED}"
 11+        printf "zsh-autoswitch-virtualenv requires virtualenv to be installed!\n\n"
 12+        printf "${NORMAL}"
 13+        printf "If this is already installed but you are still seeing this message, \n"
 14+        printf "then make sure the ${BOLD}virtualenv${NORMAL} command is in your PATH.\n"
 15+        printf "\n"
 16+        return
 17+    fi
 18+
 19     if [[ -f ".venv" ]]; then
 20         printf ".venv file already exists. If this is a mistake use the rmvenv command\n"
 21     else
 22@@ -257,14 +267,5 @@ function disable_autoswitch_virtualenv() {
 23 }
 24 
 25 
 26-if ! type "virtualenv" > /dev/null; then
 27-    printf "${BOLD}${RED}"
 28-    printf "zsh-autoswitch-virtualenv requires virtualenv to be installed!\n\n"
 29-    printf "${NORMAL}"
 30-    printf "If this is already installed but you are still seeing this message, \n"
 31-    printf "then make sure the ${BOLD}virtualenv${NORMAL} command is in your PATH.\n"
 32-    printf "\n"
 33-else
 34-    enable_autoswitch_virtualenv
 35-    check_venv
 36-fi
 37+enable_autoswitch_virtualenv
 38+check_venv
 39diff --git a/tests/test_help.zunit b/tests/test_help.zunit
 40index d31bc1375c0649abf1f6281725066aceea3ed925..c74cb0a70c57f14d25b734f17c0b95ea2a8ce96f 100644
 41--- a/tests/test_help.zunit
 42+++ b/tests/test_help.zunit
 43@@ -1,21 +1 @@
 44 #!/usr/bin/env zunit
 45-
 46-@test 'prints help message and disables plugin if virtualenv not setup' {
 47-    # Mock type to fail
 48-    function type() {
 49-        if [[ "$1" == "virtualenv" ]]; then
 50-            return 1
 51-        fi
 52-        return 0
 53-    }
 54-
 55-    run load ../autoswitch_virtualenv.plugin.zsh
 56-
 57-    assert $status equals 0
 58-    assert "$lines[1]" contains "zsh-autoswitch-virtualenv requires virtualenv to be installed!"
 59-    assert "$lines[2]" is_empty
 60-    assert "$lines[3]" contains "If this is already installed but you are still seeing this message,"
 61-    assert "$lines[4]" contains "then make sure the \e[1mvirtualenv\e[0m command is in your PATH.\n"
 62-    assert "$lines[5]" is_empty
 63-    assert ${#lines} equals 4
 64-}
 65diff --git a/tests/test_mkvenv.zunit b/tests/test_mkvenv.zunit
 66index 530319a2a186ea26a7b54c2bede4edadb9f4fa5d..9b08b8eedcbe20946093e1368ab53cb6cf74cf6d 100644
 67--- a/tests/test_mkvenv.zunit
 68+++ b/tests/test_mkvenv.zunit
 69@@ -1,6 +1,9 @@
 70 #!/usr/bin/env zunit
 71 
 72 @setup {
 73+    function virtualenv {
 74+        echo virtualenv $@
 75+    }
 76 
 77     export DISABLE_AUTOSWITCH_VENV="1"
 78     load "../autoswitch_virtualenv.plugin.zsh"
 79@@ -40,11 +43,6 @@
 80 }
 81 
 82 @test 'mkvenv - uses default python if set and not specified' {
 83-    # mock virtualenv function to test its inputs
 84-    function virtualenv {
 85-        echo virtualenv $@
 86-    }
 87-
 88     mkdir myproject
 89     cd myproject
 90     AUTOSWITCH_DEFAULT_PYTHON="python_foo"
 91@@ -84,3 +82,23 @@
 92     assert $status equals 0
 93     assert "$output" same_as "myproject"
 94 }
 95+
 96+@test 'prints help message and disables plugin if virtualenv not setup' {
 97+    # Mock type to fail
 98+    function type() {
 99+        if [[ "$1" == "virtualenv" ]]; then
100+            return 1
101+        fi
102+        return 0
103+    }
104+
105+    run mkvenv
106+
107+    assert $status equals 0
108+    assert "$lines[1]" contains "zsh-autoswitch-virtualenv requires virtualenv to be installed!"
109+    assert "$lines[2]" is_empty
110+    assert "$lines[3]" contains "If this is already installed but you are still seeing this message,"
111+    assert "$lines[4]" contains "then make sure the \e[1mvirtualenv\e[0m command is in your PATH.\n"
112+    assert "$lines[5]" is_empty
113+    assert ${#lines} equals 4
114+}