feat(python): add utilities to manage simple virtual environments (#9776)

Closes #9776
This commit is contained in:
Marijan Smetko
2021-04-01 23:35:00 +02:00
committed by Marc Cornellà
parent 3e2676f7dc
commit 02eb548d5a
2 changed files with 42 additions and 0 deletions

View File

@@ -51,3 +51,36 @@ alias ipython="python -c 'import IPython; IPython.terminal.ipapp.launch_new_inst
# Share local directory as a HTTP server
alias pyserver="python -m http.server"
## venv utilities
# Activate a the python virtual environment specified.
# If none specified, use 'venv'.
function vrun() {
local name="${1:-venv}"
local venvpath="${name:P}"
if [[ ! -d "$venvpath" ]]; then
echo >&2 "Error: no such venv in current directory: $name"
return 1
fi
if [[ ! -f "${venvpath}/bin/activate" ]]; then
echo >&2 "Error: '${name}' is not a proper virtual environment"
return 1
fi
. "${venvpath}/bin/activate" || return $?
echo "Activated virtual environment ${name}"
}
# Create a new virtual environment, with default name 'venv'.
function mkv() {
local name="${1:-venv}"
local venvpath="${name:P}"
python3 -m venv "${name}" || return
echo >&2 "Created venv in '${venvpath}'"
vrun "${name}"
}