@@ -63,6 +63,7 @@ function virtualenvwrapper_verify_active_environment () {
6363 return 0
6464}
6565
66+ # Run a hook script in the current shell
6667function virtualenvwrapper_source_hook () {
6768 scriptname="$1"
6869 if [ -f "$scriptname" ]
@@ -71,6 +72,7 @@ function virtualenvwrapper_source_hook () {
7172 fi
7273}
7374
75+ # Run a hook script in its own shell
7476function virtualenvwrapper_run_hook () {
7577 scriptname="$1"
7678 shift
@@ -219,6 +221,16 @@ elif [ -n "$ZSH_VERSION" ] ; then
219221 compctl -g "`virtualenvwrapper_show_workon_options`" workon rmvirtualenv
220222fi
221223
224+ # Prints the Python version string for the current interpreter.
225+ function virtualenvwrapper_get_python_version () {
226+ python -c 'import sys; print ".".join(str(p) for p in sys.version_info[:2])'
227+ }
228+
229+ # Prints the path to the site-packages directory for the current environment.
230+ function virtualenvwrapper_get_site_packages_dir () {
231+ echo "$VIRTUAL_ENV/lib/python`virtualenvwrapper_get_python_version`/site-packages"
232+ }
233+
222234# Path management for packages outside of the virtual env.
223235# Based on a contribution from James Bennett and Jannis Leidel.
224236#
230242# "virtualenv_path_extensions.pth" inside the virtualenv's
231243# site-packages directory; if this file does not exist, it will be
232244# created first.
233- #
234245function add2virtualenv () {
235246
236247 virtualenvwrapper_verify_active_environment || return 1
237248
238- pyvers="`python -c 'import sys; print sys.version[:3]'`"
239- site_packages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
249+ site_packages="`virtualenvwrapper_get_site_packages_dir`"
240250
241251 if [ ! -d "${site_packages}" ]
242252 then
@@ -271,44 +281,26 @@ function add2virtualenv () {
271281 return 0
272282}
273283
274- #
275- # cdsitepackages
276- #
277284# Does a ``cd`` to the site-packages directory of the currently-active
278285# virtualenv.
279- #
280-
281286function cdsitepackages () {
282287 virtualenvwrapper_verify_active_environment || return 1
283- pyvers="`python -c 'import sys; print sys.version[:3]'`"
284- site_packages="lib/python${pyvers}/site-packages"
285- cdvirtualenv $site_packages
288+ site_packages="`virtualenvwrapper_get_site_packages_dir`"
289+ cd "$site_packages"
286290}
287291
288- #
289- # cdvirtualenv
290- #
291292# Does a ``cd`` to the root of the currently-active virtualenv.
292- #
293-
294293function cdvirtualenv () {
295294 virtualenvwrapper_verify_active_environment || return 1
296295 cd $VIRTUAL_ENV/$1
297296}
298297
299- #
300- # lssitepackages
301- #
302298# Shows the content of the site-packages directory of the currently-active
303299# virtualenv
304- #
305-
306300function lssitepackages () {
307301 virtualenvwrapper_verify_active_environment || return 1
308- pyvers="`python -c 'import sys; print sys.version[:3]'`"
309- site_packages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
310- echo "$site_packages"
311- ls -l $site_packages
302+ site_packages="`virtualenvwrapper_get_site_packages_dir`"
303+ ls $@ $site_packages
312304
313305 path_file="$site_packages/virtualenv_path_extensions.pth"
314306 if [ -f "$path_file" ]
0 commit comments