Created
May 9, 2022 15:20
-
-
Save polyglothacker/0f58aafef3e63dce9e119b44c5f38f53 to your computer and use it in GitHub Desktop.
A shell function which creates a temporary virtual environment which self destructs upon deactivation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ideally put this inside your ~/.bashrc file | |
function temp-venv() { | |
function cleanup_venv() { | |
echo "Cleaning up ${VIRTUAL_ENV} ..." | |
rm -rf ${VIRTUAL_ENV} | |
unalias deactivate | |
deactivate | |
} | |
# Create a temporary virtualenv which terminates and | |
# cleans itself up on exit | |
# Install using uuid-runtime package | |
env_name=$(uuidgen) | |
# It is created in $HOME/.temp | |
mkdir -p ~/.temp && cd ~/.temp | |
python3.7 -m venv ${env_name} | |
echo "Temporary virtualenv ${env_name} created" | |
source ${env_name}/bin/activate | |
alias 'deactivate'='cleanup_venv' | |
pip install --upgrade pip && pip install wheel | |
# Do your stuff... | |
# ... | |
cd - | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment