@@ -269,12 +269,70 @@ function virtualenvwrapper_verify_active_environment {
269
269
return 0
270
270
}
271
271
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
+
272
282
# Create a new environment, in the WORKON_HOME.
273
283
#
274
284
# Usage: mkvirtualenv [options] ENVNAME
275
285
# (where the options are passed directly to virtualenv)
276
286
#
277
287
function 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
+
278
336
eval " envname=\$ $# "
279
337
virtualenvwrapper_verify_workon_home || return 1
280
338
virtualenvwrapper_verify_virtualenv || return 1
@@ -294,6 +352,12 @@ function mkvirtualenv {
294
352
[ ! -d " $WORKON_HOME /$envname " ] && return 0
295
353
# Now activate the new environment
296
354
workon " $envname "
355
+
356
+ if [ ! -z " $requirements " ]
357
+ then
358
+ pip install -r " $requirements "
359
+ fi
360
+
297
361
virtualenvwrapper_run_hook " post_mkvirtualenv"
298
362
}
299
363
@@ -738,8 +802,8 @@ function mkproject {
738
802
mkvirtualenv -h;
739
803
return ;;
740
804
-t)
741
- templates= " $templates $a " ;
742
- i= $(( $i + 1 )) ;;
805
+ i= $(( $i + 1 )) ;
806
+ templates= " $templates ${in_args[$i]} " ;;
743
807
* )
744
808
if [ ${# out_args} -gt 0 ]
745
809
then
0 commit comments