Skip to content

Commit 285851c

Browse files
committed
print the list of core hooks if no hook name is given in list mode
1 parent f00418b commit 285851c

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

docs/en/history.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ dev
1313
- Fix the test script and runner so the user's ``$WORKON_HOME`` is
1414
not erased if they do not have some test shells installed.
1515
(big thanks to :bbuser:`agriffis`).
16+
- If the hook loader is told to list plugins but is not given a hook
17+
name, it prints the list of core hooks.
1618

1719
3.2
1820

virtualenvwrapper.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ function mkproject {
897897

898898
cd "$PROJECT_HOME"
899899

900-
virtualenvwrapper_run_hook project.pre_mkproject $envname
900+
virtualenvwrapper_run_hook "project.pre_mkproject" $envname
901901

902902
echo "Creating $PROJECT_HOME/$envname"
903903
mkdir -p "$PROJECT_HOME/$envname"
@@ -912,10 +912,10 @@ function mkproject {
912912
# For some reason zsh insists on prefixing the template
913913
# names with a space, so strip them out before passing
914914
# the value to the hook loader.
915-
virtualenvwrapper_run_hook --name $(echo $t | sed 's/^ //') project.template $envname
915+
virtualenvwrapper_run_hook --name $(echo $t | sed 's/^ //') "project.template" $envname
916916
done
917917

918-
virtualenvwrapper_run_hook project.post_mkproject
918+
virtualenvwrapper_run_hook "project.post_mkproject"
919919
}
920920

921921
# Change directory to the active project

virtualenvwrapper/hook_loader.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import inspect
9+
import itertools
910
import logging
1011
import logging.handlers
1112
import optparse
@@ -98,7 +99,11 @@ def main():
9899

99100
# Determine which hook we're running
100101
if not args:
101-
parser.error('Please specify the hook to run')
102+
if options.listing:
103+
list_hooks()
104+
return 0
105+
else:
106+
parser.error('Please specify the hook to run')
102107
hook = args[0]
103108

104109
if options.sourcing and options.script_filename:
@@ -126,6 +131,7 @@ def main():
126131

127132
return 0
128133

134+
129135
def run_hooks(hook, options, args, output=None):
130136
if output is None:
131137
output = sys.stdout
@@ -135,7 +141,7 @@ def run_hooks(hook, options, args, output=None):
135141
continue
136142
plugin = ep.load()
137143
if options.listing:
138-
sys.stdout.write(' %-10s -- %s\n' % (ep.name, inspect.getdoc(plugin) or ''))
144+
output.write(' %-10s -- %s\n' % (ep.name, inspect.getdoc(plugin) or ''))
139145
continue
140146
if options.sourcing:
141147
# Show the shell commands so they can
@@ -149,5 +155,29 @@ def run_hooks(hook, options, args, output=None):
149155
# Just run the plugin ourselves
150156
plugin(args[1:])
151157

158+
159+
def list_hooks(output=None):
160+
if output is None:
161+
output = sys.stdout
162+
for hook in itertools.chain(
163+
('_'.join(h)
164+
for h in itertools.product(['pre', 'post'],
165+
['mkvirtualenv',
166+
'rmvirtualenv',
167+
'activate',
168+
'deactivate',
169+
'cpvirtualenv',
170+
])
171+
),
172+
['initialize',
173+
'get_env_details',
174+
'project.pre_mkproject',
175+
'project.post_mkproject',
176+
'project.template',
177+
]
178+
):
179+
output.write(hook + '\n')
180+
181+
152182
if __name__ == '__main__':
153183
main()

0 commit comments

Comments
 (0)