@@ -269,12 +269,70 @@ function virtualenvwrapper_verify_active_environment {
269269 return 0
270270}
271271
272+ # Help text for mkvirtualenv
273+ function mkvirtualenv_help {
274+ echo " Usage: mkvirtualenv [-r requirements_file] [virtualenv options] env_name"
275+ echo
276+ echo " -r requirements_file"
277+ echo
278+ echo " Provide a pip requirements file to install a base set of packages"
279+ echo " into the new environment."
280+ }
281+
272282# Create a new environment, in the WORKON_HOME.
273283#
274284# Usage: mkvirtualenv [options] ENVNAME
275285# (where the options are passed directly to virtualenv)
276286#
277287function mkvirtualenv {
288+ typeset -a in_args
289+ typeset -a out_args
290+ typeset -i i
291+ typeset tst
292+ typeset a
293+ typeset envname
294+ typeset requirements
295+
296+ in_args=( " $@ " )
297+
298+ if [ -n " $ZSH_VERSION " ]
299+ then
300+ i=1
301+ tst=" -le"
302+ else
303+ i=0
304+ tst=" -lt"
305+ fi
306+ while [ $i $tst $# ]
307+ do
308+ a=" ${in_args[$i]} "
309+ # echo "arg $i : $a"
310+ case " $a " in
311+ -h)
312+ echo ' mkvirtualenv help:' ;
313+ echo ;
314+ mkvirtualenv_help;
315+ echo ;
316+ echo ' virtualenv help:' ;
317+ echo ;
318+ virtualenv -h;
319+ return ;;
320+ -r)
321+ i=$(( $i + 1 )) ;
322+ requirements=" ${in_args[$i]} " ;;
323+ * )
324+ if [ ${# out_args} -gt 0 ]
325+ then
326+ out_args=( " ${out_args[@]-} " " $a " )
327+ else
328+ out_args=( " $a " )
329+ fi ;;
330+ esac
331+ i=$(( $i + 1 ))
332+ done
333+
334+ set -- " ${out_args[@]} "
335+
278336 eval " envname=\$ $# "
279337 virtualenvwrapper_verify_workon_home || return 1
280338 virtualenvwrapper_verify_virtualenv || return 1
@@ -294,6 +352,12 @@ function mkvirtualenv {
294352 [ ! -d " $WORKON_HOME /$envname " ] && return 0
295353 # Now activate the new environment
296354 workon " $envname "
355+
356+ if [ ! -z " $requirements " ]
357+ then
358+ pip install -r " $requirements "
359+ fi
360+
297361 virtualenvwrapper_run_hook " post_mkvirtualenv"
298362}
299363
@@ -738,8 +802,8 @@ function mkproject {
738802 mkvirtualenv -h;
739803 return ;;
740804 -t)
741- templates= " $templates $a " ;
742- i= $(( $i + 1 )) ;;
805+ i= $(( $i + 1 )) ;
806+ templates= " $templates ${in_args[$i]} " ;;
743807 * )
744808 if [ ${# out_args} -gt 0 ]
745809 then
0 commit comments