Commits

Doug Hellmann committed 8a9a11c

add -i option to mkvirtualenv

  • Participants
  • Parent commits 41e0661

Comments (0)

Files changed (4)

docs/en/command_ref.rst

 
 Syntax::
 
-    mkvirtualenv [-r requirements_file] [virtualenv options] ENVNAME
+    mkvirtualenv [-i package] [-r requirements_file] [virtualenv options] ENVNAME
 
-All command line options except ``-r`` and ``-h`` are passed directly
-to ``virtualenv``.  The new environment is automatically activated
-after being initialized.
+All command line options except ``-i``, ``-r``, and ``-h`` are passed
+directly to ``virtualenv``.  The new environment is automatically
+activated after being initialized.
 
 ::
 
     mynewenv
     (mynewenv)$ 
 
+The ``-i`` option can be used to install one or more packages (by
+repeating the option) after the environment is created.
+
 The ``-r`` option can be used to specify a text file listing packages
 to be installed. The argument value is passed to ``pip -r`` to be
 installed.

docs/en/history.rst

 
   - Incorporated patch to add ``-d`` option to
     :ref:`command-add2virtualenv`, contributed by :bbuser:`miracle2k`.
+  - Add ``-i`` option to :ref:`command-mkvirtualenv`.
 
 2.9
 

tests/test_mkvirtualenv_install.sh

+#!/bin/sh
+
+#set -x
+
+test_dir=$(cd $(dirname $0) && pwd)
+
+export WORKON_HOME="$(echo ${TMPDIR:-/tmp}/WORKON_HOME | sed 's|//|/|g')"
+
+oneTimeSetUp() {
+    rm -rf "$WORKON_HOME"
+    mkdir -p "$WORKON_HOME"
+    source "$test_dir/../virtualenvwrapper.sh"
+}
+
+oneTimeTearDown() {
+    rm -rf "$WORKON_HOME"
+    rm -f "$test_dir/requirements.txt"
+}
+
+setUp () {
+    echo
+    rm -f "$test_dir/catch_output"
+}
+
+test_single_package () {
+    mkvirtualenv -i commandlineapp "env4" >/dev/null 2>&1
+    installed=$(pip freeze)
+    assertTrue "CommandLineApp not found in $installed" "echo $installed | grep CommandLineApp"
+}
+
+test_multiple_packages () {
+    mkvirtualenv -i commandlineapp -i csvcat "env4" >/dev/null 2>&1
+    installed=$(pip freeze)
+    assertTrue "CommandLineApp not found in $installed" "echo $installed | grep CommandLineApp"
+    assertTrue "csvcat not found in $installed" "echo $installed | grep csvcat"
+}
+
+. "$test_dir/shunit2"

virtualenvwrapper.sh

 
 # Help text for mkvirtualenv
 function mkvirtualenv_help {
-    echo "Usage: mkvirtualenv [-r requirements_file] [virtualenv options] env_name"
+    echo "Usage: mkvirtualenv [-i package] [-r requirements_file] [virtualenv options] env_name"
+    echo
+    echo " -i package"
+    echo
+    echo "    Install a package after the environment is created."
+    echo "    This option may be repeated."
     echo
     echo " -r requirements_file"
     echo
     typeset a
     typeset envname
     typeset requirements
+    typeset packages
 
     in_args=( "$@" )
 
             -h)
                 mkvirtualenv_help;
                 return;;
+            -i)
+                i=$(( $i + 1 ));
+                packages="$packages ${in_args[$i]}";;
             -r)
                 i=$(( $i + 1 ));
                 requirements="${in_args[$i]}";;
         pip install -r "$requirements"
     fi
 
+    for a in $packages
+    do
+        pip install $a
+    done
+
     virtualenvwrapper_run_hook "post_mkvirtualenv"
 }