Skip to content

Commit aad3987

Browse files
committed
add get_env_details hook
1 parent 27afc9c commit aad3987

File tree

7 files changed

+67
-2
lines changed

7 files changed

+67
-2
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2010-08-16 Doug Hellmann <[email protected]>
2+
3+
* virtualenvwrapper/user_scripts.py (get_env_details): New hook to
4+
optionally give more detail than the name of an environment when
5+
the user requests a list.
6+
7+
* virtualenvwrapper.sh: Update workon to use the get_env_details
8+
hook to print more details, if the user provides scripts to give
9+
them.
10+
111
2010-06-03 Doug Hellmann <[email protected]>
212

313
* virtualenvwrapper.sh: Escape the call to "which" so we don't use

docs/en/history.rst

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

5+
2.3
6+
7+
- Added ``get_env_details`` hook.
8+
59
2.2.2
610

711
- Integrate Fred Palmer's patch to escape more shell commands to

docs/en/plugins.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,17 @@ before or after the event. The suffix ``_source`` is added for
298298
extensions that return shell code instead of taking action directly
299299
(see :ref:`plugins-user-env`).
300300

301+
.. _plugins-get_env_details:
302+
303+
get_env_details
304+
===============
305+
306+
The ``virtualenvwrapper.get_env_details`` hooks are run when
307+
``workon`` is run with no arguments and a list of the virtual
308+
environments is printed. The hook is run once for each environment,
309+
after the name is printed, and can be used to show additional
310+
information about that environment.
311+
301312
.. _plugins-initialize:
302313

303314
initialize

docs/en/scripts.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ The end-user customization scripts are either *sourced* (allowing them
88
to modify your shell environment) or *run* as an external program at
99
the appropriate trigger time.
1010

11+
.. _scripts-get_env_details:
12+
13+
get_env_details
14+
===============
15+
16+
:Global/Local: both
17+
:Argument(s): env name
18+
:Sourced/Run: run
19+
20+
``$WORKON_HOME/get_env_details`` is run when ``workon`` is run with no
21+
arguments and a list of the virtual environments is printed. The hook
22+
is run once for each environment, after the name is printed, and can
23+
print additional information about that environment.
24+
1125
.. _scripts-initialize:
1226

1327
initialize

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
PROJECT = 'virtualenvwrapper'
4-
VERSION = '2.2.2'
4+
VERSION = '2.3'
55

66
# Bootstrap installation of Distribute
77
import distribute_setup
@@ -194,6 +194,10 @@ def find_package_data(
194194
'virtualenvwrapper.post_deactivate_source': [
195195
'user_scripts = virtualenvwrapper.user_scripts:post_deactivate_source',
196196
],
197+
198+
'virtualenvwrapper.get_env_details': [
199+
'user_scripts = virtualenvwrapper.user_scripts:get_env_details',
200+
],
197201
},
198202

199203
zip_safe=False,

virtualenvwrapper.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ virtualenvwrapper_show_workon_options () {
236236
# into the output list.
237237
# echo seems a little faster than find, even with -depth 3.
238238
(cd "$WORKON_HOME"; for f in */bin/activate; do echo $f; done) 2>/dev/null | \sed 's|^\./||' | \sed 's|/bin/activate||' | \sort | (unset GREP_OPTIONS; \egrep -v '^\*$')
239+
239240
# (cd "$WORKON_HOME"; find -L . -depth 3 -path '*/bin/activate') | sed 's|^\./||' | sed 's|/bin/activate||' | sort
240241
}
241242

@@ -247,7 +248,12 @@ workon () {
247248
typeset env_name="$1"
248249
if [ "$env_name" = "" ]
249250
then
250-
virtualenvwrapper_show_workon_options
251+
for env_name in $(virtualenvwrapper_show_workon_options)
252+
do
253+
echo -n "$env_name"
254+
virtualenvwrapper_run_hook "get_env_details" "$env_name"
255+
echo
256+
done
251257
return 1
252258
fi
253259

virtualenvwrapper/user_scripts.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def run_global(script_name, *args):
7373
"This hook is run before every virtualenv is activated."),
7474
("postactivate",
7575
"This hook is run after every virtualenv is activated."),
76+
77+
# get_env_details
78+
("get_env_details",
79+
"This hook is run when the list of virtualenvs is printed so each name can include details."),
7680
]
7781

7882

@@ -88,6 +92,10 @@ def run_global(script_name, *args):
8892
"This hook is run before this virtualenv is activated."),
8993
("postactivate",
9094
"This hook is run after this virtualenv is activated."),
95+
96+
# get_env_details
97+
("get_env_details",
98+
"This hook is run when the list of virtualenvs is printed so each name can include details."),
9199
]
92100

93101

@@ -218,3 +226,11 @@ def post_deactivate_source(args):
218226
[ -f "$WORKON_HOME/postdeactivate" ] && source "$WORKON_HOME/postdeactivate"
219227
unset VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV
220228
""" % { 'env_name':args[0] }
229+
230+
231+
def get_env_details(args):
232+
log.debug('get_env_details')
233+
run_global('get_env_details', *args)
234+
script_path = os.path.expandvars(os.path.join('$WORKON_HOME', args[0], 'bin', 'get_env_details'))
235+
run_script(script_path, *args)
236+
return

0 commit comments

Comments
 (0)