Skip to content

Commit 865dc41

Browse files
committed
Merge upstream changes
2 parents 896cfeb + 3ca7ba1 commit 865dc41

File tree

3 files changed

+59
-16
lines changed

3 files changed

+59
-16
lines changed

docs/en/history.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ dev
1010
- Worked on some brittle tests.
1111
- Received updates to Japanese translation of the documentation from
1212
:bbuser:`t2y`.
13+
- Fix the test script and runner so the user's ``$WORKON_HOME`` is
14+
not erased if they do not have some test shells installed.
15+
(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.
18+
- Merge several fixes for path and variable handling for MSYS users
19+
from :bbuser:`bwanamarko`. Includes a fix for :bbissue:`138`.
20+
- Change :ref:`command-mkvirtualenv` so it catches both ``-h`` and
21+
``--help``.
22+
- Fix some issues with the way temporary files are used for hook
23+
scripts. (contributed by :bbuser:`agriffis`)
1324

1425
3.2
1526

virtualenvwrapper.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function virtualenvwrapper_verify_workon_home {
118118
then
119119
echo "NOTE: Virtual environments directory $WORKON_HOME does not exist. Creating..." 1>&2
120120
fi
121-
mkdir -p $WORKON_HOME
121+
mkdir -p "$WORKON_HOME"
122122
RC=$?
123123
fi
124124
return $RC
@@ -300,7 +300,7 @@ function mkvirtualenv_help {
300300
echo;
301301
echo 'virtualenv help:';
302302
echo;
303-
virtualenv -h;
303+
virtualenv $@;
304304
}
305305

306306
# Create a new environment, in the WORKON_HOME.
@@ -336,8 +336,8 @@ function mkvirtualenv {
336336
-a)
337337
i=$(( $i + 1 ));
338338
project="${in_args[$i]}";;
339-
-h)
340-
mkvirtualenv_help;
339+
-h|--help)
340+
mkvirtualenv_help $a;
341341
return;;
342342
-i)
343343
i=$(( $i + 1 ));
@@ -611,7 +611,7 @@ function virtualenvwrapper_get_python_version {
611611

612612
# Prints the path to the site-packages directory for the current environment.
613613
function virtualenvwrapper_get_site_packages_dir {
614-
"$VIRTUAL_ENV/bin/python" -c "import distutils; print(distutils.sysconfig.get_python_lib())"
614+
"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python" -c "import distutils; print(distutils.sysconfig.get_python_lib())"
615615
}
616616

617617
# Path management for packages outside of the virtual env.
@@ -709,7 +709,7 @@ function lssitepackages {
709709
virtualenvwrapper_verify_workon_home || return 1
710710
virtualenvwrapper_verify_active_environment || return 1
711711
typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
712-
ls $@ $site_packages
712+
ls $@ "$site_packages"
713713

714714
path_file="$site_packages/_virtualenv_path_extensions.pth"
715715
if [ -f "$path_file" ]
@@ -899,7 +899,7 @@ function mkproject {
899899

900900
cd "$PROJECT_HOME"
901901

902-
virtualenvwrapper_run_hook project.pre_mkproject $envname
902+
virtualenvwrapper_run_hook "project.pre_mkproject" $envname
903903

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

920-
virtualenvwrapper_run_hook project.post_mkproject
920+
virtualenvwrapper_run_hook "project.post_mkproject"
921921
}
922922

923923
# Change directory to the active project

virtualenvwrapper/hook_loader.py

Lines changed: 39 additions & 7 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
@@ -14,6 +15,7 @@
1415

1516
import pkg_resources
1617

18+
1719
class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler):
1820
"""Taken from http://stackoverflow.com/questions/1407474/does-python-logging-handlers-rotatingfilehandler-allow-creation-of-a-group-writa
1921
"""
@@ -23,6 +25,7 @@ def _open(self):
2325
os.umask(prevumask)
2426
return rtv
2527

28+
2629
def main():
2730
parser = optparse.OptionParser(
2831
usage='usage: %prog [options] <hook> [<arguments>]',
@@ -67,7 +70,7 @@ def main():
6770
dest='names',
6871
default=[],
6972
)
70-
parser.disable_interspersed_args() # stop when we hit an option without an '-'
73+
parser.disable_interspersed_args() # stop when we hit an option without an '-'
7174
options, args = parser.parse_args()
7275

7376
root_logger = logging.getLogger('')
@@ -85,10 +88,10 @@ def main():
8588

8689
# Send higher-level messages to the console, too
8790
console = logging.StreamHandler()
88-
console_level = [ logging.WARNING,
89-
logging.INFO,
90-
logging.DEBUG,
91-
][options.verbose_level]
91+
console_level = [logging.WARNING,
92+
logging.INFO,
93+
logging.DEBUG,
94+
][options.verbose_level]
9295
console.setLevel(console_level)
9396
formatter = logging.Formatter('%(name)s %(message)s')
9497
console.setFormatter(formatter)
@@ -98,7 +101,11 @@ def main():
98101

99102
# Determine which hook we're running
100103
if not args:
101-
parser.error('Please specify the hook to run')
104+
if options.listing:
105+
list_hooks()
106+
return 0
107+
else:
108+
parser.error('Please specify the hook to run')
102109
hook = args[0]
103110

104111
if options.sourcing and options.script_filename:
@@ -126,6 +133,7 @@ def main():
126133

127134
return 0
128135

136+
129137
def run_hooks(hook, options, args, output=None):
130138
if output is None:
131139
output = sys.stdout
@@ -135,7 +143,7 @@ def run_hooks(hook, options, args, output=None):
135143
continue
136144
plugin = ep.load()
137145
if options.listing:
138-
sys.stdout.write(' %-10s -- %s\n' % (ep.name, inspect.getdoc(plugin) or ''))
146+
output.write(' %-10s -- %s\n' % (ep.name, inspect.getdoc(plugin) or ''))
139147
continue
140148
if options.sourcing:
141149
# Show the shell commands so they can
@@ -149,5 +157,29 @@ def run_hooks(hook, options, args, output=None):
149157
# Just run the plugin ourselves
150158
plugin(args[1:])
151159

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

0 commit comments

Comments
 (0)