Skip to content

Commit 6f6b11c

Browse files
committed
add -n and -l options to hook loader
1 parent b987b03 commit 6f6b11c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

docs/source/history.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Dev
1919
- Fix a problem with ``virtualenvwrapper_show_workon_options`` that
2020
caused it to show ``*`` as the name of a virtualenv when no
2121
environments had yet been created.
22+
- Change the hook loader so it can be told to run only a set of
23+
named hooks.
24+
- Add support for listing the available hooks, to be used in help
25+
output of commands like virtualenvwrapper.project's mkproject.
2226

2327
2.0.2
2428

virtualenvwrapper/hook_loader.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""Load hooks for virtualenvwrapper.
77
"""
88

9+
import inspect
910
import logging
1011
import optparse
1112
import os
@@ -24,6 +25,12 @@ def main():
2425
dest='sourcing',
2526
default=False,
2627
)
28+
parser.add_option('-l', '--list',
29+
help='Print a list of the plugins available for the given hook',
30+
action='store_true',
31+
default=False,
32+
dest='listing',
33+
)
2734
parser.add_option('-v', '--verbose',
2835
help='Show more information on the console',
2936
action='store_const',
@@ -37,6 +44,12 @@ def main():
3744
const=0,
3845
dest='verbose_level',
3946
)
47+
parser.add_option('-n', '--name',
48+
help='Only run the hook from the named plugin',
49+
action='append',
50+
dest='names',
51+
default=[],
52+
)
4053
parser.disable_interspersed_args() # stop when we hit an option without an '-'
4154
options, args = parser.parse_args()
4255

@@ -66,7 +79,12 @@ def main():
6679
hook += '_source'
6780

6881
for ep in pkg_resources.iter_entry_points('virtualenvwrapper.%s' % hook):
82+
if options.names and ep.name not in options.names:
83+
continue
6984
plugin = ep.load()
85+
if options.listing:
86+
print ' {0:10} -- {1}'.format(ep.name, inspect.getdoc(plugin) or '')
87+
continue
7088
if options.sourcing:
7189
# Show the shell commands so they can
7290
# be run in the calling shell.

0 commit comments

Comments
 (0)