@@ -63,6 +63,7 @@ function virtualenvwrapper_verify_active_environment () {
63
63
return 0
64
64
}
65
65
66
+ # Run a hook script in the current shell
66
67
function virtualenvwrapper_source_hook () {
67
68
scriptname="$1"
68
69
if [ -f "$scriptname" ]
@@ -71,6 +72,7 @@ function virtualenvwrapper_source_hook () {
71
72
fi
72
73
}
73
74
75
+ # Run a hook script in its own shell
74
76
function virtualenvwrapper_run_hook () {
75
77
scriptname="$1"
76
78
shift
@@ -219,6 +221,16 @@ elif [ -n "$ZSH_VERSION" ] ; then
219
221
compctl -g "`virtualenvwrapper_show_workon_options`" workon rmvirtualenv
220
222
fi
221
223
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
+
222
234
# Path management for packages outside of the virtual env.
223
235
# Based on a contribution from James Bennett and Jannis Leidel.
224
236
#
230
242
# "virtualenv_path_extensions.pth" inside the virtualenv's
231
243
# site-packages directory; if this file does not exist, it will be
232
244
# created first.
233
- #
234
245
function add2virtualenv () {
235
246
236
247
virtualenvwrapper_verify_active_environment || return 1
237
248
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`"
240
250
241
251
if [ ! -d "${site_packages}" ]
242
252
then
@@ -271,44 +281,26 @@ function add2virtualenv () {
271
281
return 0
272
282
}
273
283
274
- #
275
- # cdsitepackages
276
- #
277
284
# Does a ``cd`` to the site-packages directory of the currently-active
278
285
# virtualenv.
279
- #
280
-
281
286
function cdsitepackages () {
282
287
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"
286
290
}
287
291
288
- #
289
- # cdvirtualenv
290
- #
291
292
# Does a ``cd`` to the root of the currently-active virtualenv.
292
- #
293
-
294
293
function cdvirtualenv () {
295
294
virtualenvwrapper_verify_active_environment || return 1
296
295
cd $VIRTUAL_ENV/$1
297
296
}
298
297
299
- #
300
- # lssitepackages
301
- #
302
298
# Shows the content of the site-packages directory of the currently-active
303
299
# virtualenv
304
- #
305
-
306
300
function lssitepackages () {
307
301
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
312
304
313
305
path_file="$site_packages/virtualenv_path_extensions.pth"
314
306
if [ -f "$path_file" ]
0 commit comments