Skip to content

Commit 2d1cf10

Browse files
committed
add cdsitepackages arg handling from William McVey
2 parents 8615cf7 + 2223c83 commit 2d1cf10

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

docsource/command_ref.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,16 @@ cdsitepackages
8484

8585
Because the exact path to the site-packages directory in the virtualenv depends on the
8686
version of Python, ``cdsitepackages`` is provided as a shortcut for ``cdvirtualenv
87-
lib/python${pyvers}/site-packages``.
87+
lib/python${pyvers}/site-packages``. An optional argument is also allowed, to specify
88+
a directory hierarchy within the ``site-packages`` directory to change into.
89+
90+
::
91+
$ workon pymotw
92+
$ echo $VIRTUAL_ENV
93+
/Users/dhellmann/.virtualenvs/pymotw
94+
$ cdsitepackages PyMOTW/bisect/
95+
$ pwd
96+
/Users/dhellmann/.virtualenvs/pymotw/lib/python2.6/site-packages/PyMOTW/bisect
8897

8998
===============
9099
Path Management

docsource/history.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Release History
33
===============
44

5+
1.25
6+
7+
- Merged in changes to cdsitepackages from William McVey. It now
8+
takes an argument and supports tab-completion for directories
9+
within site-packages.
10+
511
1.24.2
612

713
- Add user provided :ref:`tips-and-tricks` section.

pavement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# What project are we building?
2929
PROJECT = 'virtualenvwrapper'
30-
VERSION = '1.24.2'
30+
VERSION = '1.25'
3131
os.environ['VERSION'] = VERSION
3232

3333
# Read the long description to give to setup

tests/test.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ test_cdsitepackages () {
8282
popd >/dev/null
8383
}
8484

85+
test_cdsitepackages_with_arg () {
86+
pushd "$(pwd)" >/dev/null
87+
pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
88+
sitepackage_subdir="$VIRTUAL_ENV/lib/python${pyvers}/site-packages/subdir"
89+
mkdir -p "${sitepackage_subdir}"
90+
cdsitepackages subdir
91+
assertSame "$sitepackage_subdir" "$(pwd)"
92+
popd >/dev/null
93+
}
94+
8595
test_mkvirtualenv_activates () {
8696
mkvirtualenv "env2"
8797
assertTrue virtualenvwrapper_verify_active_environment

virtualenvwrapper_bashrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,13 @@ if [ -n "$BASH" ] ; then
316316
# COMPREPLY=( $(compgen -d -- "${VIRTUAL_ENV}/${cur}" | sed -e "s@${VIRTUAL_ENV}/@@" ) )
317317
COMPREPLY=( $(cdvirtualenv && compgen -d -- "${cur}" ) )
318318
}
319+
_cdsitepackages_complete ()
320+
{
321+
local cur="$2"
322+
COMPREPLY=( $(cdsitepackages && compgen -d -- "${cur}" ) )
323+
}
319324
complete -o nospace -F _cdvirtualenv_complete -S/ cdvirtualenv
325+
complete -o nospace -F _cdsitepackages_complete -S/ cdsitepackages
320326
complete -o default -o nospace -F _virtualenvs workon
321327
complete -o default -o nospace -F _virtualenvs rmvirtualenv
322328
elif [ -n "$ZSH_VERSION" ] ; then
@@ -388,7 +394,7 @@ function add2virtualenv () {
388394
function cdsitepackages () {
389395
virtualenvwrapper_verify_active_environment || return 1
390396
site_packages="`virtualenvwrapper_get_site_packages_dir`"
391-
cd "$site_packages"
397+
cd "$site_packages"/$1
392398
}
393399

394400
# Does a ``cd`` to the root of the currently-active virtualenv.

0 commit comments

Comments
 (0)