Skip to content

Commit 8d0e1e6

Browse files
committed
Fix virtualenv detection with spaces in WORKON_HOME
Fixes issue #194 Change-Id: I9021fbecd15f0626b948c810a3fb2dcf8e800802 Signed-off-by: Doug Hellmann <[email protected]>
1 parent 3b1b3a2 commit 8d0e1e6

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

docs/source/history.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Release History
55
dev
66
===
77

8-
- Ensure that all $() style commands that produce paths are
8+
- Ensure that all ``$()`` style commands that produce paths are
99
quoted. Addresses :bbissue:`164`.
1010
- Add :ref:`command-wipeenv` command for removing all packages
1111
installed in the virtualenv.
@@ -17,6 +17,8 @@ dev
1717
:ref:`command-mkvirtualenv`. Resolves :bbissue:`190`.
1818
- Add :ref:`command-allvirtualenv` command to run a command across all
1919
virtualenvs. Suggested by Dave Coutts in :bbissue:`186`.
20+
- Fix :ref:`command-lsvirtualenv` when there are spaces in
21+
``WORKON_HOME``. Resolves :bbissue:`194`.
2022

2123
4.0
2224
===

tests/test_lsvirtualenv.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- mode: shell-script -*-
2+
3+
test_dir=$(cd $(dirname $0) && pwd)
4+
source "$test_dir/setup.sh"
5+
6+
oneTimeSetUp() {
7+
rm -rf "$WORKON_HOME"
8+
mkdir -p "$WORKON_HOME"
9+
source "$test_dir/../virtualenvwrapper.sh"
10+
}
11+
12+
oneTimeTearDown() {
13+
rm -rf "$WORKON_HOME"
14+
}
15+
16+
setUp () {
17+
echo
18+
rm -f "$test_dir/catch_output"
19+
}
20+
21+
test_no_workon_home () {
22+
old_home="$WORKON_HOME"
23+
export WORKON_HOME="$WORKON_HOME/not_there"
24+
lsvirtualenv >"$old_home/output" 2>&1
25+
output=$(cat "$old_home/output")
26+
assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
27+
WORKON_HOME="$old_home"
28+
}
29+
30+
test_space_in_workon_home () {
31+
old_home="$WORKON_HOME"
32+
export WORKON_HOME="$WORKON_HOME/with space"
33+
mkdir "$WORKON_HOME"
34+
(cd "$WORKON_HOME"; virtualenv testenv) 2>&1
35+
lsvirtualenv -b >"$old_home/output"
36+
output=$(cat "$old_home/output")
37+
assertTrue "Did not see expected message in \"$output\"" "echo $output | grep 'testenv'"
38+
WORKON_HOME="$old_home"
39+
}
40+
41+
42+
. "$test_dir/shunit2"

virtualenvwrapper.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,7 @@ function virtualenvwrapper_show_workon_options {
534534
# 4. Format the output to show one name on a line.
535535
# 5. Eliminate any lines with * on them because that means there
536536
# were no envs.
537-
(echo $WORKON_HOME/*/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate) 2>/dev/null \
538-
| command \sed "s|$WORKON_HOME/||g" \
537+
(cd "$WORKON_HOME" && echo */$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate) 2>/dev/null \
539538
| command \sed "s|/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate||g" \
540539
| command \fmt -w 1 \
541540
| (unset GREP_OPTIONS; command \egrep -v '^\*$') 2>/dev/null

0 commit comments

Comments
 (0)