mirror of
https://git.decapod.one/brethil/dotfiles
synced 2024-11-21 11:01:31 +01:00
zsh: python: cleanup mkvenv
This commit is contained in:
parent
1537ddcc64
commit
a20bffdf67
|
@ -8,28 +8,35 @@ mkvenv(){
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "force=$force_create"
|
|
||||||
return
|
|
||||||
shift $(($OPTIND-1))
|
shift $(($OPTIND-1))
|
||||||
if [[ -n $1 ]]; then
|
if [[ -n $1 ]]; then
|
||||||
venv_name=$1
|
venv_name=$1
|
||||||
shift
|
shift
|
||||||
|
else
|
||||||
|
venv_name=.venv
|
||||||
fi
|
fi
|
||||||
# any other arguments are passed on to the `venv` module as flags/arguments
|
# any other arguments are passed on to the `venv` module as flags/arguments
|
||||||
echo ${venv_name}
|
|
||||||
|
|
||||||
if [[ -e ${venv_name} ]]; then
|
if [[ -e ${venv_name} ]]; then
|
||||||
if [[ -n ${force_create} ]]; then
|
if [[ -n ${force_create} ]]; then
|
||||||
if [[ -n $VIRTUAL_ENV ]]; then # deactivate venv if enabled
|
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
|
fi
|
||||||
rm -rf ${venv_name} && info "Deleted existing virtualenv"
|
rm -rf ${venv_name} && warning "Deleted existing virtualenv."
|
||||||
else
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
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
|
if [[ -z ${source_venv} ]]; then
|
||||||
echo -n " done. Enable? [Y/n] "
|
echo -n " done. Enable? [Y/n] "
|
||||||
read source_venv
|
read source_venv
|
||||||
|
@ -38,7 +45,8 @@ mkvenv(){
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $source_venv != "n" ]]; then
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user