Skip to content

Instantly share code, notes, and snippets.

@dreamingbinary
Last active March 5, 2020 20:17
Show Gist options
  • Save dreamingbinary/7cdd1e897b04cca9354187bf38a24817 to your computer and use it in GitHub Desktop.
Save dreamingbinary/7cdd1e897b04cca9354187bf38a24817 to your computer and use it in GitHub Desktop.
virtualenv shortcuts; useful on the CLI

Install Instructions

  1. Put contents of virtualenv.sh in your ~.bashrc or ~.bash_profile
  2. Run source ~.bashrc or source ~.bash_profle to make the new commands available.

Pre-requisite

  1. Python 3 installed
  2. pip3 install virtualenv

Usage in an Existing Project

With a requirements.txt file already available, you can run the following commands to get set up quickly.

  1. vI - Initializes the virtualenv with python3. A venv folder is created. Only do this the first time.
  2. vA - Activate the virtualenv. You'll notice (venv) prepended to your CLI prompt
    • All pip packages will be installed in a newly created venv folder.
    • This becomes your first step of the workflow if you've already initialized the environment.
  3. vR - Install from requirements file.
  4. vD - Deactivate the virtualenv. Do this when you're done. Or just close that terminal session.

Refer to image screenshot.png for example.

VIRTENT=$(which virtualenv);
if [[ $VIRTENT != '' ]]; then
REQ=requirements.txt
REQB=requirements-build.txt
REQV=requirements-vendored.txt
REQI=infra-requirements.txt
# Virtualenv helpers, because I will forget
alias venvInit="virtualenv -p $(which python3) venv"
alias venvActivate=". venv/bin/activate"
alias venvDeactivate="deactivate"
alias vRequirements="pip install -r ${REQ} -U; [ -f ${REQB} ] && pip install -r ${REQB} -U; [ -f ${REQV} ] && pip install -r ${REQV} -U; [ -f buildlib/${REQB} ] && pip install -r buildlib/${REQB} -U; [ -f buildlib/${REQV} ] && pip install -r buildlib/${REQV} -U;"
alias vI=venvInit
alias vA=venvActivate
alias vR=vRequirements
alias vD=deactivate
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment