File tree Expand file tree Collapse file tree 4 files changed +85
-0
lines changed
Expand file tree Collapse file tree 4 files changed +85
-0
lines changed Original file line number Diff line number Diff line change @@ -547,3 +547,18 @@ Syntax::
547547
548548 cdproject
549549
550+ ===========================
551+ Managing Installed Packages
552+ ===========================
553+
554+ .. _command-wipeenv :
555+
556+ wipeenv
557+ -------
558+
559+ Remove all of the installed third-party packages in the current
560+ virtualenv.
561+
562+ Syntax::
563+
564+ wipeenv
Original file line number Diff line number Diff line change 77
88- Ensure that all $() style commands that produce paths are
99 quoted. Addresses :bbissue: `164 `.
10+ - Add :ref: `command-wipeenv ` command for removing all packages
11+ installed in the virtualenv.
1012
11134.0
1214===
Original file line number Diff line number Diff line change 1+ # -*- mode: shell-script -*-
2+
3+ test_dir=$( cd $( dirname $0 ) && pwd)
4+ source " $test_dir /setup.sh"
5+
6+ setUp () {
7+ rm -rf " $WORKON_HOME "
8+ mkdir -p " $WORKON_HOME "
9+ source " $test_dir /../virtualenvwrapper.sh"
10+ rm -f " $test_dir /catch_output"
11+ echo
12+ }
13+
14+ tearDown () {
15+ if type deactivate > /dev/null 2>&1
16+ then
17+ deactivate
18+ fi
19+ rm -rf " $WORKON_HOME "
20+ }
21+
22+ test_wipeenv () {
23+ mkvirtualenv " wipetest" > /dev/null 2>&1
24+ (cd tests/testpackage && python setup.py install) > /dev/null 2>&1
25+ before=" $( pip freeze) "
26+ assertTrue " testpackage not installed" " pip freeze | grep testpackage"
27+ wipeenv > /dev/null 2>&1
28+ after=" $( pip freeze) "
29+ assertFalse " testpackage still installed" " pip freeze | grep testpackage"
30+ }
31+
32+ test_empty_env () {
33+ mkvirtualenv " wipetest" > /dev/null 2>&1
34+ before=" $( pip freeze) "
35+ assertFalse " testpackage still installed" " pip freeze | grep testpackage"
36+ wipeenv > /dev/null 2>&1
37+ after=" $( pip freeze) "
38+ assertFalse " testpackage still installed" " pip freeze | grep testpackage"
39+ }
40+
41+ test_not_active_env () {
42+ mkvirtualenv " wipetest" > /dev/null 2>&1
43+ deactivate
44+ assertFalse " wipenv did not report an error" " wipeenv >/dev/null 2>&1"
45+ }
46+
47+ . " $test_dir /shunit2"
48+
Original file line number Diff line number Diff line change @@ -1131,6 +1131,26 @@ fi
11311131EOF
11321132}
11331133
1134+ #
1135+ # Remove all installed packages from the env
1136+ #
1137+ function wipeenv {
1138+ virtualenvwrapper_verify_workon_home || return 1
1139+ virtualenvwrapper_verify_active_environment || return 1
1140+
1141+ typeset req_file=" $( virtualenvwrapper_tempfile " requirements.txt" ) "
1142+ pip freeze | egrep -v ' (distribute|wsgiref)' > " $req_file "
1143+ if [ -n " $( cat " $req_file " ) " ]
1144+ then
1145+ echo " Uninstalling packages:"
1146+ cat " $req_file "
1147+ echo
1148+ pip uninstall -y $( cat " $req_file " | sed ' s/>/=/g' | cut -f1 -d=)
1149+ else
1150+ echo " Nothing to remove."
1151+ fi
1152+ rm -f " $req_file "
1153+ }
11341154
11351155#
11361156# Invoke the initialization functions
You can’t perform that action at this time.
0 commit comments