Some tools are provided here for interacting with virtual-env and tox.
venv is probably a recreation of other tools. It overlaps greatly with virtualenvwrapper (workon).
The big difference is mostly a preference. I prefer running subshells to modifying the current shell environment.
Create a new virtual env
$ venv create restview
Pip install something into it
$ venv restview pip install restview
Activate that virtual env
$ venv exec restview
(venv:restview) ~/$
Run a command in it:
$ venv exec restview your-command
or, 'e' is an alias for exec.
$ venv e restview your-command your-arg1 your-arg1
Destroy it:
$ venv delete --force restview
If you use a program from venv and do not like then length of:
venv exec venv-name command
Then you can write a wrapper with:
$ venv wrapper softlayer slcli
#!/bin/sh
exec venv exec softlayer slcli "$@"
That writes the wrapper to stdout by default. Give it -o/--output to write to a file:
$ venv wrapper --output ~/bin/slcli softlayer slcli
Or you could alias that also.
tox-venv: run a command inside a tox environment.
If you use tox, then you likely have .tox/<venv>
directories that you can
enter with tox
command. However, sometimes you want to poke around or
run a command inside there without modifying your tox.ini
file.
Assuming 'tox.ini' in the local directory, it will determine where your tox environments are correctly.
tox-venv is copied into cloud-init
's source tree at tools/tox-venv. The two versions have diverged slightly.
tox-venv could/should probably be done in python possibly importing tox.
This version is much faster than python -c "import tox"
(or even python -c pass
). The faster path is used when providing a
command (tox-venv py3 /bin/true
).
Example:
Run python in pep8 tox environment. This will use tox to create the enviroment if it does not exist.
$ tox-venv pep8 python
Run pep8 on the file my.py
:
$ tox-venv pep8 pep8 my.py
Run the default commands
for the py3 environment passing it the provided posargs
.
$ time ./tools/tox-venv py3 - tests/unittests/test_log.py
Just enter the virtualenv that provided in your 'doc' tox environment.
$ tox-venv doc /bin/bash
(tox:docs) $
List what tox environments there are. Those with a * are existing environments.
$ tox-venv --list
py26
docs*
py27*
By default, tox-venv will run the 'commands' that it reads for the environment provided.