@@ -9,7 +9,7 @@ _yellow="\033[01;33m"
99_red=" \033[31m"
1010
1111# Version number has to follow pattern "^v\d+\.\d+\.\d+.*$"
12- _version=" v1.4.1 "
12+ _version=" v1.5.0 "
1313
1414# Valid VCS URL environment variable pattern
1515# https://peps.python.org/pep-0610/#specification
@@ -163,15 +163,60 @@ 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]"
176+ echo " y"
177+ echo " $ Virtual environment deleted!"
178+ return " ${_success} "
179+ fi
180+
181+ if [ ! -d .venv ]; then
182+ venv::color_echo " ${_yellow} " " No virtual environment found, nothing to delete."
183+ return " ${_success} "
184+ fi
185+
186+ # If -y is not supplied as input argument, prompt the user for confirmation
187+ if [ " $1 " != " -y" ]; then
188+ echo " Are you sure you want to delete the virtual environment in .venv? [y/N]"
189+ read -r response
190+
191+ local accept_pattern=" ^([yY][eE][sS]|[yY])$"
192+ if [[ ! " ${response} " =~ $accept_pattern ]]; then
193+ venv::color_echo " ${_yellow} " " Aborting."
194+ return " ${_success} "
195+ fi
196+ fi
197+
198+ venv::color_echo " ${_yellow} " " Deleting virtual environment in .venv ..."
199+ if [ ! -z " ${VIRTUAL_ENV} " ]; then
200+ venv::deactivate
201+ fi
202+
203+ if ! rm -rf .venv; then
204+ # If the virtual environment could not be deleted
205+ return " ${_fail} "
206+ fi
207+ venv::color_echo " ${_green} " " Virtual environment deleted!"
208+ }
209+
210+
166211venv::install () {
167212 if venv::_check_if_help_requested " $1 " ; then
168- echo " venv install [<requirements file>] [--skip-lock] [<install args>]"
213+ echo " venv install [<requirements file>] [--skip-lock|-s ] [<install args>]"
169214 echo
170215 echo " Clear the environment, then install requirements from <requirements file>,"
171216 echo " like 'requirements.txt' or 'requirements.lock'."
172217 echo " Installed packages are then locked into the corresponding .lock-file,"
173218 echo " e.g. 'venv install requirements.txt' will lock packages into 'requirements.lock'."
174- echo " This step is skipped if '--skip-lock' is specified, or when installing"
219+ echo " This step is skipped if '--skip-lock' or '-s' is specified, or when installing"
175220 echo " directly from a .lock-file."
176221 echo
177222 echo " The <requirements file> must be in the form '*requirements.[txt|lock]'."
@@ -185,12 +230,12 @@ venv::install() {
185230 echo
186231 echo " $ venv install dev-requirements.txt"
187232 echo
188- echo " $ venv install requirements.txt --skip-lock --no-cache"
233+ echo " $ venv install requirements.txt --skip-lock|-s --no-cache"
189234 return " ${_success} "
190235 fi
191236
192237 local requirements_file
193- if [ -z " $1 " ] || [ " $1 " = " --skip-lock" ]; then
238+ if [ -z " $1 " ] || [ " $1 " = " --skip-lock" ] || [ " $1 " = " -s " ] ; then
194239 # If no filename was passed
195240 requirements_file=" requirements.txt"
196241
@@ -206,7 +251,7 @@ venv::install() {
206251 fi
207252
208253 local skip_lock=false
209- if [ " $1 " = " --skip-lock" ]; then
254+ if [ " $1 " = " --skip-lock" ] || [ " $1 " = " -s " ] ; then
210255 skip_lock=true
211256 shift
212257 fi
@@ -358,6 +403,7 @@ venv::help() {
358403 echo
359404 echo " create Create a new virtual environment in the current folder"
360405 echo " activate Activate the virtual environment in the current folder"
406+ echo " delete Delete the virtual environment in the current folder"
361407 echo " install Install requirements from a requirements file in the current environment"
362408 echo " lock Lock installed requirements in a '.lock'-file"
363409 echo " clear Remove all installed packages in the current environment"
@@ -385,6 +431,7 @@ venv::main() {
385431
386432 create \
387433 | activate \
434+ | delete \
388435 | install \
389436 | lock \
390437 | clear \
0 commit comments