5c8c2c54325a4a32190654c58fcf1b07d309bd4e

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

Message

Merge pull request #113 from MichaelAquilina/next

1.15.0

Diff

This diff is truncated to protect this page.

  1diff --git a/CHANGELOG.rst b/CHANGELOG.rst
  2index ab5b3e0a4180046321cbb856f26749ca7251c511..bb748a33f658c6ca47da06ecfe9074492c19f458 100644
  3--- a/CHANGELOG.rst
  4+++ b/CHANGELOG.rst
  5@@ -1,6 +1,10 @@
  6 Changelog
  7 =========
  8 
  9+1.15.0
 10+------
 11+* Add AUTOSWITCH_FILE configuration option
 12+
 13 1.14.0
 14 ------
 15 * Prevent pipenv from showing its courtesy because we activated its virtualenv
 16diff --git a/README.rst b/README.rst
 17index d43c0b8c2db5b514db6b29e23a291004e7f95cf2..e458ad990acf218a6084fcda6474147d405c8848 100644
 18--- a/README.rst
 19+++ b/README.rst
 20@@ -273,6 +273,18 @@ by setting the value of ``AUTOSWITCH_DEFAULT_PYTHON``. For example:
 21 You may still override this default as usual by passing the --python parameter to
 22 the mkvenv command.
 23 
 24+**Autoswitch file name**
 25+
 26+By default, the `.venv` file is searched for in each directory in order to tell if
 27+a virtualenv should be automatically activated.
 28+
 29+If this needs to be changed (e.g. it conflicts with something else) then it may be
 30+changed by setting the value of ``AUTOSWITCH_FILE``. For example:
 31+
 32+::
 33+
 34+    export AUTOSWITCH_FILE=".autoswitch"
 35+
 36 **Default requirements file**
 37 
 38 You may specify a default requirements file to use when creating a virtualenv by
 39diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 40index 6bdb8ea776e99fcedde524190051e20eca6b6ec7..d91669ac9eb57b64ad974eea2a29b1bf18fb3136 100644
 41--- a/autoswitch_virtualenv.plugin.zsh
 42+++ b/autoswitch_virtualenv.plugin.zsh
 43@@ -1,4 +1,5 @@
 44-export AUTOSWITCH_VERSION='1.14.0'
 45+export AUTOSWITCH_VERSION="1.15.0"
 46+export AUTOSWITCH_FILE=".venv"
 47 
 48 RED="\e[31m"
 49 GREEN="\e[32m"
 50@@ -6,6 +7,7 @@ PURPLE="\e[35m"
 51 BOLD="\e[1m"
 52 NORMAL="\e[0m"
 53 
 54+
 55 function _virtual_env_dir() {
 56     local venv_name="$1"
 57     local VIRTUAL_ENV_DIR="${AUTOSWITCH_VIRTUAL_ENV_DIR:-$HOME/.virtualenvs}"
 58@@ -95,16 +97,16 @@ function _maybeworkon() {
 59 }
 60 
 61 
 62-# Gives the path to the nearest parent .venv file or nothing if it gets to root
 63+# Gives the path to the nearest parent $AUTOSWITCH_FILE or nothing if it gets to root
 64 function _check_venv_path()
 65 {
 66     local check_dir="$1"
 67 
 68-    if [[ -f "${check_dir}/.venv" ]]; then
 69-        printf "${check_dir}/.venv"
 70+    if [[ -f "${check_dir}/$AUTOSWITCH_FILE" ]]; then
 71+        printf "${check_dir}/$AUTOSWITCH_FILE"
 72         return
 73     else
 74-        # Abort search at file system root or HOME directory (latter is a perfomance optimisation).
 75+        # Abort search at file system root or HOME directory (latter is a performance optimisation).
 76         if [[ "$check_dir" = "/" || "$check_dir" = "$HOME" ]]; then
 77             return
 78         fi
 79@@ -113,13 +115,13 @@ function _check_venv_path()
 80 }
 81 
 82 
 83-# Automatically switch virtualenv when .venv file detected
 84+# Automatically switch virtualenv when $AUTOSWITCH_FILE file detected
 85 function check_venv()
 86 {
 87     local file_owner
 88     local file_permissions
 89 
 90-    # Get the .venv file, scanning parent directories
 91+    # Get the $AUTOSWITCH_FILE, scanning parent directories
 92     local venv_path=$(_check_venv_path "$PWD")
 93 
 94     if [[ -n "$venv_path" ]]; then
 95@@ -135,11 +137,11 @@ function check_venv()
 96 
 97         if [[ "$file_owner" != "$(id -u)" ]]; then
 98             printf "AUTOSWITCH WARNING: Virtualenv will not be activated\n\n"
 99-            printf "Reason: Found a .venv file but it is not owned by the current user\n"
100+            printf "Reason: Found a $AUTOSWITCH_FILE file but it is not owned by the current user\n"
101             printf "Change ownership of ${PURPLE}$venv_path${NORMAL} to ${PURPLE}'$USER'${NORMAL} to fix this\n"
102         elif ! [[ "$file_permissions" =~ ^[64][04][04]$ ]]; then
103             printf "AUTOSWITCH WARNING: Virtualenv will not be activated\n\n"
104-            printf "Reason: Found a .venv file with weak permission settings ($file_permissions).\n"
105+            printf "Reason: Found a $AUTOSWITCH_FILE file with weak permission settings ($file_permissions).\n"
106             printf "Run the following command to fix this: ${PURPLE}\"chmod 600 $venv_path\"${NORMAL}\n"
107         else
108             local switch_to="$(<"$venv_path")"
109@@ -186,8 +188,8 @@ function _default_venv()
110 # remove virtual environment for current directory
111 function rmvenv()
112 {
113-    if [[ -f ".venv" ]]; then
114-        local venv_name="$(<.venv)"
115+    if [[ -f "$AUTOSWITCH_FILE" ]]; then
116+        local venv_name="$(<$AUTOSWITCH_FILE)"
117 
118         # detect if we need to switch virtualenv first
119         if [[ -n "$VIRTUAL_ENV" ]]; then
120@@ -203,9 +205,9 @@ function rmvenv()
121         # https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s04.html
122         # https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/
123         /bin/rm -rf "$(_virtual_env_dir "$venv_name")"
124-        /bin/rm ".venv"
125+        /bin/rm "$AUTOSWITCH_FILE"
126     else
127-        printf "No .venv file in the current directory!\n"
128+        printf "No $AUTOSWITCH_FILE file in the current directory!\n"
129     fi
130 }
131 
132@@ -223,8 +225,8 @@ function mkvenv()
133         return
134     fi
135 
136-    if [[ -f ".venv" ]]; then
137-        printf ".venv file already exists. If this is a mistake use the rmvenv command\n"
138+    if [[ -f "$AUTOSWITCH_FILE" ]]; then
139+        printf "$AUTOSWITCH_FILE file already exists. If this is a mistake use the rmvenv command\n"
140     else
141         local venv_name="$(basename $PWD)"
142