8005bf3f9139ad04be3f417fcda28434d50bc7aa

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

Message

Merge pull request #69 from MichaelAquilina/next

1.6.0

Diff

  1diff --git a/CHANGELOG.rst b/CHANGELOG.rst
  2index e0e090fa3d8677d95b770b9fd1d4a151feb7abfa..d3aab9eb9a3ebd07797cc03f5fef7a9a6b271cc8 100644
  3--- a/CHANGELOG.rst
  4+++ b/CHANGELOG.rst
  5@@ -1,6 +1,11 @@
  6 Changelog
  7 =========
  8 
  9+1.6.0
 10+-----
 11+* Display snake emoji by default when switching virtualenvs
 12+* Minor tweaks and changes
 13+
 14 1.5.0
 15 -----
 16 * Detect python projects with `setup.py`
 17diff --git a/README.rst b/README.rst
 18index 93d2c286a08441c4c72e7c8b1d32e3ddbe7dec41..bbfcf2d1694f98be61dcd75ea6709bffc02d1282 100644
 19--- a/README.rst
 20+++ b/README.rst
 21@@ -256,8 +256,7 @@ zsh-autoswitch-virtualenv will warn you and refuse to activate a virtual
 22 envionrment automatically in the following situations:
 23 
 24 -  You are not the owner of the ``.venv`` file found in a directory.
 25--  The ``.venv`` file has weak permissions. I.e. it is readable or
 26-   writable by other users on the system.
 27+-  The ``.venv`` file has weak permissions. I.e. it is writable by other users on the system.
 28 
 29 In both cases, the warnings should explain how to fix the problem.
 30 
 31diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 32index f3ad8c510322b4124e0c00bba881694c529d0d4b..d2207d76a95da89567762b71dcb000ec9cfdd3e0 100644
 33--- a/autoswitch_virtualenv.plugin.zsh
 34+++ b/autoswitch_virtualenv.plugin.zsh
 35@@ -1,4 +1,4 @@
 36-export AUTOSWITCH_VERSION='1.5.0'
 37+export AUTOSWITCH_VERSION='1.6.0'
 38 
 39 RED="\e[31m"
 40 GREEN="\e[32m"
 41@@ -40,7 +40,11 @@ function _maybeworkon() {
 42     venv_name="$1"
 43     venv_type="$2"
 44 
 45-    DEFAULT_MESSAGE_FORMAT="Switching %venv_type: ${BOLD}${PURPLE}%venv_name${NORMAL} ${GREEN}[%py_version]${NORMAL}"
 46+    DEFAULT_MESSAGE_FORMAT="Switching %venv_type: ${BOLD}${PURPLE}%venv_name${NORMAL} ${GREEN}[๐Ÿ%py_version]${NORMAL}"
 47+    if [[ "$LANG" != *".UTF-8" ]]; then
 48+        # Remove multibyte characters if the terminal does not support utf-8
 49+        DEFAULT_MESSAGE_FORMAT="${DEFAULT_MESSAGE_FORMAT/๐Ÿ/}"
 50+    fi
 51 
 52     if [[ -z "$VIRTUAL_ENV" || "$venv_name" != "$(basename $VIRTUAL_ENV)" ]]; then
 53 
 54@@ -193,7 +197,6 @@ function mkvenv()
 55 
 56 
 57 function install_requirements() {
 58-    setopt nullglob
 59     if [[ -f "$PWD/setup.py" ]]; then
 60         printf "Found a ${PURPLE}setup.py${NORMAL} file. Install dependencies? [y/N]: "
 61         read ans
 62@@ -205,6 +208,7 @@ function install_requirements() {
 63         fi
 64     fi
 65 
 66+    setopt nullglob
 67     for requirements in *requirements.txt
 68     do
 69         printf "Found a ${PURPLE}%s${NORMAL} file. Install? [y/N]: " "$requirements"
 70diff --git a/tests/test_check_venv.zunit b/tests/test_check_venv.zunit
 71index a90d37a38438514cb1096c322cf20b073857b78d..41e188269374597d2ef6fb1b4dd2a4e89e30a7e7 100644
 72--- a/tests/test_check_venv.zunit
 73+++ b/tests/test_check_venv.zunit
 74@@ -99,7 +99,7 @@
 75     run check_venv
 76 
 77     assert $status equals 0
 78-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 79+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
 80 }
 81 
 82 @test 'check_venv - No security warning for readable by group permission' {
 83@@ -113,7 +113,7 @@
 84     run check_venv
 85 
 86     assert $status equals 0
 87-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 88+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
 89 }
 90 
 91 @test 'check_venv - No security warning for readable only by owner permission' {
 92@@ -126,7 +126,7 @@
 93     run check_venv
 94 
 95     assert $status equals 0
 96-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 97+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
 98 }
 99 
100 
101@@ -137,7 +137,7 @@
102     run check_venv
103 
104     assert $status equals 0
105-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoodefault\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
106+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoodefault\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
107 }
108 
109 
110@@ -153,7 +153,7 @@
111     run check_venv
112 
113     assert $status equals 0
114-    assert "$output" same_as "Switching pipenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
115+    assert "$output" same_as "Switching pipenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
116 }
117 
118 
119@@ -181,5 +181,5 @@
120     run check_venv
121 
122     assert $status equals 0
123-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
124+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
125 }
126diff --git a/tests/test_maybeworkon.zunit b/tests/test_maybeworkon.zunit
127index d64d291d77a0a9d83adc6477a01c45eca6862bb0..7ffcfa845cd07526859855ebe5d04c06779408ae 100644
128--- a/tests/test_maybeworkon.zunit
129+++ b/tests/test_maybeworkon.zunit
130@@ -37,7 +37,7 @@
131     run _maybeworkon foobar virtualenv
132 
133     assert $state equals 0
134-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
135+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
136 }
137 
138 @test '_maybeworkon - custom message' {
139@@ -50,13 +50,23 @@
140     assert "$output" same_as "Hello cheese - this is foobar ($PYTHON_VERSION)"
141 }
142 
143+@test '_maybeworkon - no emoji on non utf-8 LANG' {
144+    VIRTUAL_ENV=""
145+    LANG="ASCII"
146+
147+    run _maybeworkon foobar virtualenv
148+
149+    assert $state equals 0
150+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
151+}
152+
153 @test '_maybeworkon - switches virtualenv if current virtualenv is different' {
154     VIRTUAL_ENV="$HOME/.virtualenvs/default_venv"
155 
156     run _maybeworkon foobar virtualfoo
157 
158     assert $state equals 0
159-    assert "$output" contains "Switching virtualfoo: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
160+    assert "$output" contains "Switching virtualfoo: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
161 }
162 
163 @test '_maybeworkon - switches virtualenv if current virtualenv is different (silent)' {
164diff --git a/tests/test_plugin.zunit b/tests/test_plugin.zunit
165index f8580b94f0824c7f0633f958a604946d2577c127..ec88b24f20efdf7687aef82bd478b0f91ee1d9d1 100644
166--- a/tests/test_plugin.zunit
167+++ b/tests/test_plugin.zunit
168@@ -36,7 +36,7 @@
169     run load ../autoswitch_virtualenv.plugin.zsh
170 
171     assert $status equals 0
172-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
173+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
174 }
175 
176 @test 'plugin - does nothing if switching to directory without .venv' {
177@@ -62,7 +62,7 @@
178     run cd "$TEMP_DIR"
179 
180     assert $status equals 0
181-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
182+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
183 
184     mkdir "$TEMP_DIR/foo"
185 
186@@ -70,5 +70,5 @@
187     run cd "$TEMP_DIR/foo"
188 
189     assert $status equals 0
190-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
191+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
192 }