@@ -163,6 +163,49 @@ venv::deactivate() {
163163}
164164
165165
166+ venv::delete () {
167+ if venv::_check_if_help_requested " $1 " ; then
168+ echo " venv delete [-y]"
169+ echo
170+ echo " Delete the virtual environment located in the current folder."
171+ echo " If the environment is currently active, it will be deactivated first."
172+ echo
173+ echo " Examples:"
174+ echo " $ venv delete"
175+ echo " Are you sure you want to delete the virtual environment in .venv? [y/N] y"
176+ echo " $ Virtual environment deleted!"
177+ return " ${_success} "
178+ fi
179+
180+ if [ ! -d .venv ]; then
181+ venv::color_echo " ${_yellow} " " No virtual environment found, nothing to delete."
182+ return " ${_success} "
183+ fi
184+
185+ # If -y is not supplied as input argument, prompt the user for confirmation
186+ if [ " $1 " != " -y" ]; then
187+ read -r -p " Are you sure you want to delete the virtual environment in .venv? [y/N] " response
188+
189+ local accept_pattern=" ^([yY][eE][sS]|[yY])$"
190+ if [[ ! " ${response} " =~ $accept_pattern ]]; then
191+ venv::color_echo " ${_yellow} " " Aborting."
192+ return " ${_success} "
193+ fi
194+ fi
195+
196+ venv::color_echo " ${_yellow} " " Deleting virtual environment in .venv ..."
197+ if [ ! -z " ${VIRTUAL_ENV} " ]; then
198+ venv::deactivate
199+ fi
200+
201+ if ! rm -rf .venv; then
202+ # If the virtual environment could not be deleted
203+ return " ${_fail} "
204+ fi
205+ venv::color_echo " ${_green} " " Virtual environment deleted!"
206+ }
207+
208+
166209venv::install () {
167210 if venv::_check_if_help_requested " $1 " ; then
168211 echo " venv install [<requirements file>] [--skip-lock|-s] [<install args>]"
@@ -358,6 +401,7 @@ venv::help() {
358401 echo
359402 echo " create Create a new virtual environment in the current folder"
360403 echo " activate Activate the virtual environment in the current folder"
404+ echo " delete Delete the virtual environment in the current folder"
361405 echo " install Install requirements from a requirements file in the current environment"
362406 echo " lock Lock installed requirements in a '.lock'-file"
363407 echo " clear Remove all installed packages in the current environment"
@@ -385,6 +429,7 @@ venv::main() {
385429
386430 create \
387431 | activate \
432+ | delete \
388433 | install \
389434 | lock \
390435 | clear \
0 commit comments