Skip to content

Instantly share code, notes, and snippets.

@anthonyinfinity
Created July 5, 2020 09:33
Show Gist options
  • Save anthonyinfinity/d322ea3452f490b10a371265036220e0 to your computer and use it in GitHub Desktop.
Save anthonyinfinity/d322ea3452f490b10a371265036220e0 to your computer and use it in GitHub Desktop.
Create a pyenv virtual venv in the current directory
#!/bin/sh
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
# Usage: $ sh mk-venv
if [[ -z "${1}" ]]; then
echo "Usage: $ mk-venv pythonversion"
exit 1
fi
reqs="requirements.txt"
pfile="Pipefile"
if [[ ! -z "${2}" ]]; then
mkdir ${2} &&
cd ${2}
proj="${2}"
echo ${proj}
else
proj=$(basename "$PWD")
echo ${proj}
fi
printf "\e[1;34mCreating a new virtualenv for dir: ${proj}.\e[0m";
pyenv virtualenv ${1} venv-$proj
pyenv local venv-$proj
full_path_to_pip=$(which pip)
$full_path_to_pip install --upgrade pip
if [[ -f "$reqs" ]]; then
printf "\e[1;34mFound requirements.txt. Installing.\e[0m";
$full_path_to_pip install wheel
$full_path_to_pip install -r $reqs
fi
if [[ -f "$pfile" ]]; then
printf "\e[1;34mFound ${pfile}. Converting.\e[0m";
$full_path_to_pip install pipenv
full_path_to_pipenv=$(which pipenv)
$full_path_to_pipenv run pipenv_to_requirements -f
$full_path_to_pip uninstall pipenv
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment