f980dd6176a1e8912843f9aa755efcf4fcfdc6e8

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

Message

feat: Update mkvenv to generate virtualenvs that dont shadow

Diff

  1diff --git a/.circleci/config.yml b/.circleci/config.yml
  2index 27c74f7047d21b62364ce9375f1d28b864232b5d..4938b6e26a238838f7276b796d6348b307ebd8bd 100644
  3--- a/.circleci/config.yml
  4+++ b/.circleci/config.yml
  5@@ -6,7 +6,16 @@ test: &test
  6     - checkout
  7     - run:
  8         name: Install Dependencies
  9-        command: apt-get update && apt-get install -y curl python3-pip ncurses-bin python python-virtualenv git
 10+        command: >
 11+          apt-get update &&
 12+          apt-get install -y
 13+          python3-pip
 14+          python
 15+          python-virtualenv
 16+          curl
 17+          ncurses-bin
 18+          git
 19+          pwgen
 20     - run:
 21         name: install pipenv
 22         command: pip3 install pipenv
 23diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 24index 59b8b4f4485e78304ba564a9a4f68424acb94daf..75fd264f83126c2ebce45f7187e163a5f9435470 100644
 25--- a/autoswitch_virtualenv.plugin.zsh
 26+++ b/autoswitch_virtualenv.plugin.zsh
 27@@ -315,7 +315,7 @@ function mkvenv()
 28         if [[ -f "$AUTOSWITCH_FILE" ]]; then
 29             printf "$AUTOSWITCH_FILE file already exists. If this is a mistake use the rmvenv command\n"
 30         else
 31-            local venv_name="$(basename $PWD)"
 32+            local venv_name="$(basename $PWD)-$(pwgen 8 1)"
 33 
 34             printf "Creating ${PURPLE}%s${NONE} virtualenv\n" "$venv_name"
 35 
 36diff --git a/tests/test_mkvenv.zunit b/tests/test_mkvenv.zunit
 37index ae18ab4ebb5a6d1d080f9e5133fb717ccf9b63a4..cf194a19bd403e451d98bfbbd981b9b20da7e82e 100644
 38--- a/tests/test_mkvenv.zunit
 39+++ b/tests/test_mkvenv.zunit
 40@@ -50,12 +50,11 @@
 41 
 42     assert $status equals 0
 43     assert "$TARGET/myproject/.venv" exists
 44-    # assert "$lines[1]" same_as "Creating \e[35mmyproject\e[0m virtualenv"
 45 
 46     run cat "$TARGET/myproject/.venv"
 47 
 48     assert $status equals 0
 49-    assert "$output" same_as "myproject"
 50+    assert "$output" matches "myproject-[a-zA-Z0-9]{8}"
 51 }
 52 
 53 @test 'mkvenv - (poetry project) runs correct command' {
 54@@ -92,12 +91,14 @@
 55     assert $status equals 0
 56     assert "$TARGET/myproject/.venv" exists
 57     # Assert mock output
 58-    assert "$lines[2]" same_as "virtualenv --python=python_foo $HOME/.virtualenvs/myproject"
 59+
 60+    expected="virtualenv --python=python_foo $HOME/.virtualenvs/myproject-"
 61+    assert "$lines[2]" contains "$expected"
 62 
 63     run cat "$TARGET/myproject/.venv"
 64 
 65     assert $status equals 0
 66-    assert "$output" same_as "myproject"
 67+    assert "$output" matches "myproject-[a-zA-Z0-9]{8}"
 68 }
 69 
 70 @test 'mkvenv - uses specified python if default set' {
 71@@ -115,12 +116,12 @@
 72     assert $status equals 0
 73     assert "$TARGET/myproject/.venv" exists
 74     # Assert mock output
 75-    assert "$lines[2]" same_as "virtualenv --python=python_bar $HOME/.virtualenvs/myproject"
 76+    assert "$lines[2]" contains "virtualenv --python=python_bar $HOME/.virtualenvs/myproject-"
 77 
 78     run cat "$TARGET/myproject/.venv"
 79 
 80     assert $status equals 0
 81-    assert "$output" same_as "myproject"
 82+    assert "$output" matches "myproject-[a-zA-Z0-9]{8}"
 83 }
 84 
 85 @test 'prints help message and disables plugin if virtualenv not setup' {
 86diff --git a/tests/test_rmvenv.zunit b/tests/test_rmvenv.zunit
 87index c7fde66c80f7d479c6d00ed5db0c1e0c74598efc..53a6a0285123e21b2a61151262d506d717c27fba 100644
 88--- a/tests/test_rmvenv.zunit
 89+++ b/tests/test_rmvenv.zunit
 90@@ -68,11 +68,12 @@
 91 @test 'rmvenv - removes .venv and deactivates if currently active' {
 92     test_venv="$(basename $PWD)"
 93     run mkvenv
 94+    target_venv="$(<.venv)"
 95 
 96     run rmvenv
 97 
 98     assert $state equals 0
 99-    assert "$output" same_as "Removing \e[35m$test_venv\e[0m..."
100+    assert "$output" same_as "Removing \e[35m$target_venv\e[0m..."
101     test ! -f .venv
102     test ! -d "$HOME/.virtualenvs/$test_venv"
103 }