A simple bash shell script for dealing with the following typical situation:
python -m venv venv
source venv/scripts/activate
pip install -r requirements.txt
The script is executed using the command source venv.sh
-hshow help message and exit-dinstall dependencies from requirements_dev.txt-nthe name of the virtual environment directory-rrecreate the virtual environment-qthe script will generate no output
The script can be aliased with the bash command alias venv="source venv.sh"
The alias can be made permanent by adding it to your .bashrc file. To reference the script in your user directory use
alias venv="source ~/venv.sh"Now the command venv can be used in place of source venv.sh
The examples below show how to invoke the script, as well as how to do the equivalent work on the command line.
source venv.sh
python -m venv venv
source venv/scripts/activate
pip install -r requirements.txt
source venv.sh -n "testing" -d
python -m venv testing
source testing/scripts/activate
pip install -r requirements_dev.txt
source venv.sh -r -q
rm -r venv
python -m venv venv
source venv/scripts/activate
pip install -r requirements.txt
venv
python -m venv venv
source venv/scripts/activate
pip install -r requirements.txt
venv -n "testing" -d -r
rm -r testing
python -m venv testing
source testing/scripts/activate
pip install -r requirements_dev.txt
- Wherever possible the script will verify a file or directory exists before trying to use or delete it.
- Due to how shell scripts process arguments the
-qflag must come first to ensure complete silence.
This project is licensed under the MIT license. Feel free to edit and distribute this template as you like.
See LICENSE for more information.
