1
0
mirror of https://git.decapod.one/brethil/dotfiles synced 2024-12-22 13:01:40 +01:00

zsh: python: cleanup mkvenv

This commit is contained in:
bretello 2023-11-11 18:54:40 +01:00
parent 1537ddcc64
commit a20bffdf67
Signed by: brethil
GPG Key ID: 876AAC6290170FE7

View File

@ -8,28 +8,35 @@ mkvenv(){
esac
done
echo "force=$force_create"
return
shift $(($OPTIND-1))
if [[ -n $1 ]]; then
venv_name=$1
shift
else
venv_name=.venv
fi
# any other arguments are passed on to the `venv` module as flags/arguments
echo ${venv_name}
if [[ -e ${venv_name} ]]; then
if [[ -n ${force_create} ]]; then
if [[ -n $VIRTUAL_ENV ]]; then # deactivate venv if enabled
deactivate && info "Deactivated existing virtualenv" || red "Could not run deactivate";
deactivate && warning "Deactivated existing virtualenv" || red "Could not run deactivate";
fi
rm -rf ${venv_name} && info "Deleted existing virtualenv"
rm -rf ${venv_name} && warning "Deleted existing virtualenv."
else
echo "$(color $RED Error:) $(color $BOLD .venv) already exists. Run with -f to recreate it." >&2
error "$(color $BOLD .venv) already exists. Run with -f to recreate it." >&2
return 1
fi
fi
info "Creating virtualenv ${venv_name}... " && python -m virtualenv $@ ${venv_name}|| echo -e "Failed to create virtualenv. Is virtualenv installed? Try:\n $ pip install virtualenv"
info "Creating virtualenv ${venv_name}... "
if ! python -m virtualenv $@ ${venv_name} ; then
error "Failed to create virtualenv. Is virtualenv installed? Try:\n $ pip install virtualenv"
return 1
fi
if [[ -z ${source_venv} ]]; then
echo -n " done. Enable? [Y/n] "
read source_venv
@ -38,7 +45,8 @@ mkvenv(){
fi
if [[ $source_venv != "n" ]]; then
source ${venv_name}/bin/activate && echo -e "$(color $BOLD Enabled!) 🐍 $(color $BOLD$PURPLE $(python --version | cut -d " " -f2 )) ($(color $BOLD$GREEN $(pip --version | cut -d " " -f -2)))"
source ${venv_name}/bin/activate && \
echo -e "$(color $BOLD Enabled!) 🐍 $(color $BOLD$PURPLE $(python --version | cut -d " " -f2 )) ($(color $BOLD$GREEN $(pip --version | cut -d " " -f -2)))"
fi
}