summaryrefslogtreecommitdiff
path: root/plugins/python/python.plugin.zsh
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/python/python.plugin.zsh')
-rw-r--r--plugins/python/python.plugin.zsh33
1 files changed, 33 insertions, 0 deletions
diff --git a/plugins/python/python.plugin.zsh b/plugins/python/python.plugin.zsh
index 896fae3ca..6c7fc6cbb 100644
--- a/plugins/python/python.plugin.zsh
+++ b/plugins/python/python.plugin.zsh
@@ -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}"
+}