Skip to content

Commit 8a9a11c

Browse files
committed
add -i option to mkvirtualenv
1 parent 41e0661 commit 8a9a11c

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

docs/en/command_ref.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ Create a new environment, in the WORKON_HOME.
2222

2323
Syntax::
2424

25-
mkvirtualenv [-r requirements_file] [virtualenv options] ENVNAME
25+
mkvirtualenv [-i package] [-r requirements_file] [virtualenv options] ENVNAME
2626

27-
All command line options except ``-r`` and ``-h`` are passed directly
28-
to ``virtualenv``. The new environment is automatically activated
29-
after being initialized.
27+
All command line options except ``-i``, ``-r``, and ``-h`` are passed
28+
directly to ``virtualenv``. The new environment is automatically
29+
activated after being initialized.
3030

3131
::
3232

@@ -41,6 +41,9 @@ after being initialized.
4141
mynewenv
4242
(mynewenv)$
4343

44+
The ``-i`` option can be used to install one or more packages (by
45+
repeating the option) after the environment is created.
46+
4447
The ``-r`` option can be used to specify a text file listing packages
4548
to be installed. The argument value is passed to ``pip -r`` to be
4649
installed.

docs/en/history.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dev
66

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

1011
2.9
1112

tests/test_mkvirtualenv_install.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
#set -x
4+
5+
test_dir=$(cd $(dirname $0) && pwd)
6+
7+
export WORKON_HOME="$(echo ${TMPDIR:-/tmp}/WORKON_HOME | sed 's|//|/|g')"
8+
9+
oneTimeSetUp() {
10+
rm -rf "$WORKON_HOME"
11+
mkdir -p "$WORKON_HOME"
12+
source "$test_dir/../virtualenvwrapper.sh"
13+
}
14+
15+
oneTimeTearDown() {
16+
rm -rf "$WORKON_HOME"
17+
rm -f "$test_dir/requirements.txt"
18+
}
19+
20+
setUp () {
21+
echo
22+
rm -f "$test_dir/catch_output"
23+
}
24+
25+
test_single_package () {
26+
mkvirtualenv -i commandlineapp "env4" >/dev/null 2>&1
27+
installed=$(pip freeze)
28+
assertTrue "CommandLineApp not found in $installed" "echo $installed | grep CommandLineApp"
29+
}
30+
31+
test_multiple_packages () {
32+
mkvirtualenv -i commandlineapp -i csvcat "env4" >/dev/null 2>&1
33+
installed=$(pip freeze)
34+
assertTrue "CommandLineApp not found in $installed" "echo $installed | grep CommandLineApp"
35+
assertTrue "csvcat not found in $installed" "echo $installed | grep csvcat"
36+
}
37+
38+
. "$test_dir/shunit2"

virtualenvwrapper.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ function virtualenvwrapper_verify_active_environment {
271271

272272
# Help text for mkvirtualenv
273273
function mkvirtualenv_help {
274-
echo "Usage: mkvirtualenv [-r requirements_file] [virtualenv options] env_name"
274+
echo "Usage: mkvirtualenv [-i package] [-r requirements_file] [virtualenv options] env_name"
275+
echo
276+
echo " -i package"
277+
echo
278+
echo " Install a package after the environment is created."
279+
echo " This option may be repeated."
275280
echo
276281
echo " -r requirements_file"
277282
echo
@@ -296,6 +301,7 @@ function mkvirtualenv {
296301
typeset a
297302
typeset envname
298303
typeset requirements
304+
typeset packages
299305

300306
in_args=( "$@" )
301307

@@ -315,6 +321,9 @@ function mkvirtualenv {
315321
-h)
316322
mkvirtualenv_help;
317323
return;;
324+
-i)
325+
i=$(( $i + 1 ));
326+
packages="$packages ${in_args[$i]}";;
318327
-r)
319328
i=$(( $i + 1 ));
320329
requirements="${in_args[$i]}";;
@@ -356,6 +365,11 @@ function mkvirtualenv {
356365
pip install -r "$requirements"
357366
fi
358367

368+
for a in $packages
369+
do
370+
pip install $a
371+
done
372+
359373
virtualenvwrapper_run_hook "post_mkvirtualenv"
360374
}
361375

0 commit comments

Comments
 (0)