97840c120eb2e7f8a7f8e3a816b398675a28b64d

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

Message

Merge pull request #101 from MichaelAquilina/next

Fix pipenv project detection bug

Diff

  1diff --git a/.circleci/config.yml b/.circleci/config.yml
  2index 7d13d52db003cff431d7358b43a27e1556131270..ac4c449b6b7fb3bff9728682ecac270e440cf1cb 100644
  3--- a/.circleci/config.yml
  4+++ b/.circleci/config.yml
  5@@ -70,6 +70,11 @@ jobs:
  6         - image: "zshusers/zsh:5.6.2"
  7       <<: *test
  8 
  9+  test-zsh-5.7:
 10+      docker:
 11+        - image: "zshusers/zsh:5.7.1"
 12+      <<: *test
 13+
 14 workflows:
 15   version: 2
 16   test:
 17@@ -81,3 +86,4 @@ workflows:
 18       - test-zsh-5.4
 19       - test-zsh-5.5
 20       - test-zsh-5.6
 21+      - test-zsh-5.7
 22diff --git a/CHANGELOG.rst b/CHANGELOG.rst
 23index e21475d5bb693a9a318be891cd431c6f44547115..fec42e74a47fca49d231677bdb3f76310ecc735f 100644
 24--- a/CHANGELOG.rst
 25+++ b/CHANGELOG.rst
 26@@ -1,6 +1,11 @@
 27 Changelog
 28 =========
 29 
 30+1.11.1
 31+------
 32+* Fix bug with pipenv detection where extra messages would be incorrectly displayed
 33+* Add zsh 5.7 to the CI testing process
 34+
 35 1.11.0
 36 ------
 37 * Correct project detection behaviour when working with pipenv
 38diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 39index 7961f0ed32dc07aa02ab910d7fd62264a082cfdd..7616b3e8298cdd87542ec3a6e09eaa783fcb783a 100644
 40--- a/autoswitch_virtualenv.plugin.zsh
 41+++ b/autoswitch_virtualenv.plugin.zsh
 42@@ -1,4 +1,4 @@
 43-export AUTOSWITCH_VERSION='1.11.0'
 44+export AUTOSWITCH_VERSION='1.11.1'
 45 
 46 RED="\e[31m"
 47 GREEN="\e[32m"
 48@@ -85,7 +85,6 @@ function _check_venv_path()
 49 # Automatically switch virtualenv when .venv file detected
 50 function check_venv()
 51 {
 52-    local SWITCH_TO=""
 53     local file_owner
 54     local file_permissions
 55 
 56@@ -111,27 +110,29 @@ function check_venv()
 57             printf "Reason: Found a .venv file with weak permission settings ($file_permissions).\n"
 58             printf "Run the following command to fix this: ${PURPLE}\"chmod 600 $venv_path\"${NORMAL}\n"
 59         else
 60-            SWITCH_TO="$(<"$venv_path")"
 61+            local switch_to="$(<"$venv_path")"
 62+            _maybeworkon "$(_virtual_env_dir "$switch_to")" "virtualenv"
 63+            return
 64         fi
 65     fi
 66 
 67-    if [[ -n "$SWITCH_TO" ]]; then
 68-        _maybeworkon "$(_virtual_env_dir "$SWITCH_TO")" "virtualenv"
 69-
 70     # check if Pipfile exists rather than invoking pipenv as it is slow
 71-    elif [[ -a "Pipfile" ]] && type "pipenv" > /dev/null; then
 72-        venv_path="$(PIPENV_IGNORE_VIRTUALENVS=1 pipenv --venv)"
 73-        _maybeworkon "$venv_path" "pipenv"
 74-    else
 75-        if [[ -f "$PWD/Pipfile" ]]; then
 76-            printf "Python project detected. "
 77-            printf "Run ${PURPLE}pipenv install${NORMAL} to setup autoswitching\n"
 78-        elif [[ -f "$PWD/requirements.txt" || -f "$PWD/setup.py" ]]; then
 79-            printf "Python project detected. "
 80-            printf "Run ${PURPLE}mkvenv${NORMAL} to setup autoswitching\n"
 81+    if [[ -a "Pipfile" ]] && type "pipenv" > /dev/null; then
 82+        if venv_path="$(PIPENV_IGNORE_VIRTUALENVS=1 pipenv --venv 2>/dev/null)"; then
 83+            _maybeworkon "$venv_path" "pipenv"
 84+            return
 85         fi
 86-        _default_venv
 87     fi
 88+
 89+    # If we still haven't got anywhere, fallback to defaults
 90+    if [[ -f "$PWD/Pipfile" ]]; then
 91+        printf "Python project detected. "
 92+        printf "Run ${PURPLE}pipenv install${NORMAL} to setup autoswitching\n"
 93+    elif [[ -f "$PWD/requirements.txt" || -f "$PWD/setup.py" ]]; then
 94+        printf "Python project detected. "
 95+        printf "Run ${PURPLE}mkvenv${NORMAL} to setup autoswitching\n"
 96+    fi
 97+    _default_venv
 98 }
 99 
100 # Switch to the default virtual environment