68
68
# path might contain stuff to expand.
69
69
# (it might be possible to do this in shell, but I don't know a
70
70
# cross-shell-safe way of doing it -wolever)
71
- if echo " $WORKON_HOME " | grep -e " [$~]" > /dev/null
71
+ if echo " $WORKON_HOME " | egrep -e " ( [$~]|//) " > /dev/null
72
72
then
73
73
# This will normalize the path by:
74
- # - Expanding variables (eg, $foo)
75
- # - Converting ~s to complete paths (eg, ~/ to /home/brian/ and ~arthur to /home/arthur)
74
+ # - Removing extra slashes (e.g., when TMPDIR ends in a slash)
75
+ # - Expanding variables (e.g., $foo)
76
+ # - Converting ~s to complete paths (e.g., ~/ to /home/brian/ and ~arthur to /home/arthur)
76
77
WORKON_HOME=$( " $VIRTUALENVWRAPPER_PYTHON " -c " import os; print os.path.expandvars(os.path.expanduser(\" $WORKON_HOME \" ))" )
77
78
export WORKON_HOME
78
79
fi
81
82
virtualenvwrapper_verify_workon_home () {
82
83
if [ ! -d " $WORKON_HOME " ]
83
84
then
84
- [ " $1 " != " -q" ] && echo " ERROR: Virtual environments directory '$WORKON_HOME ' does not exist. Create it or set WORKON_HOME to an existing directory." >&2
85
+ [ " $1 " != " -q" ] && echo " ERROR: Virtual environments directory '$WORKON_HOME ' does not exist. Create it or set WORKON_HOME to an existing directory." 1 >&2
85
86
return 1
86
87
fi
87
88
return 0
@@ -92,20 +93,20 @@ virtualenvwrapper_verify_workon_home () {
92
93
# Expects 1 argument, the suffix for the new file.
93
94
virtualenvwrapper_tempfile () {
94
95
# Note: the 'X's must come last
95
- mktemp " virtualenvwrapper-$1 -XXXXXX"
96
+ mktemp -t " virtualenvwrapper-$1 -XXXXXX"
96
97
}
97
98
98
99
# Run the hooks
99
100
virtualenvwrapper_run_hook () {
100
- hook_script=" $( virtualenvwrapper_tempfile hook) "
101
+ typeset hook_script=" $( virtualenvwrapper_tempfile ${1} - hook) "
101
102
" $VIRTUALENVWRAPPER_PYTHON " -c ' from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script " $hook_script " " $@ "
102
103
result=$?
103
104
104
105
if [ $result -eq 0 ]
105
106
then
106
107
source " $hook_script "
107
108
fi
108
- rm -f " $hook_script " & > /dev/null
109
+ rm -f " $hook_script " > /dev/null 2>&1
109
110
return $result
110
111
}
111
112
@@ -115,14 +116,14 @@ virtualenvwrapper_initialize () {
115
116
virtualenvwrapper_run_hook " initialize"
116
117
if [ $? -ne 0 ]
117
118
then
118
- echo " virtualenvwrapper.sh: Python encountered a problem. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH set properly." 1>&2
119
+ echo " virtualenvwrapper.sh: Python encountered a problem. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH is set properly." 1>&2
119
120
return 1
120
121
fi
121
122
}
122
123
123
124
# Verify that virtualenv is installed and visible
124
125
virtualenvwrapper_verify_virtualenv () {
125
- venv=$( which virtualenv | grep -v " not found" )
126
+ typeset venv=$( which virtualenv | grep -v " not found" )
126
127
if [ " $venv " = " " ]
127
128
then
128
129
echo " ERROR: virtualenvwrapper could not find virtualenv in your path" >&2
@@ -382,7 +383,7 @@ add2virtualenv () {
382
383
cdsitepackages () {
383
384
virtualenvwrapper_verify_workon_home || return 1
384
385
virtualenvwrapper_verify_active_environment || return 1
385
- site_packages=" ` virtualenvwrapper_get_site_packages_dir` "
386
+ typeset site_packages=" ` virtualenvwrapper_get_site_packages_dir` "
386
387
cd " $site_packages " /$1
387
388
}
388
389
@@ -398,7 +399,7 @@ cdvirtualenv () {
398
399
lssitepackages () {
399
400
virtualenvwrapper_verify_workon_home || return 1
400
401
virtualenvwrapper_verify_active_environment || return 1
401
- site_packages=" ` virtualenvwrapper_get_site_packages_dir` "
402
+ typeset site_packages=" ` virtualenvwrapper_get_site_packages_dir` "
402
403
ls $@ $site_packages
403
404
404
405
path_file=" $site_packages /virtualenv_path_extensions.pth"
@@ -427,12 +428,12 @@ cpvirtualenv() {
427
428
fi
428
429
if echo " $WORKON_HOME " | grep -e " /$" > /dev/null
429
430
then
430
- env_home=" $WORKON_HOME "
431
+ typset env_home=" $WORKON_HOME "
431
432
else
432
- env_home=" $WORKON_HOME /"
433
+ typeset env_home=" $WORKON_HOME /"
433
434
fi
434
- source_env=" $env_home$env_name "
435
- target_env=" $env_home$new_env "
435
+ typeset source_env=" $env_home$env_name "
436
+ typeset target_env=" $env_home$new_env "
436
437
437
438
if [ ! -e " $source_env " ]
438
439
then
@@ -442,12 +443,12 @@ cpvirtualenv() {
442
443
443
444
cp -r " $source_env " " $target_env "
444
445
for script in $( ls $target_env /bin/* )
445
- do
446
+ do
446
447
newscript=" $script -new"
447
448
sed " s|$source_env |$target_env |g" < " $script " > " $newscript "
448
449
mv " $newscript " " $script "
449
450
chmod a+x " $script "
450
- done
451
+ done
451
452
452
453
virtualenv " $target_env " --relocatable
453
454
sed " s/VIRTUAL_ENV\(.*\)$env_name /VIRTUAL_ENV\1$new_env /g" < " $source_env /bin/activate" > " $target_env /bin/activate"
0 commit comments