summary refs log tree commit diff
path: root/pkgs/development/interpreters/python/hooks/venv-shell-hook.sh
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/interpreters/python/hooks/venv-shell-hook.sh')
-rw-r--r--pkgs/development/interpreters/python/hooks/venv-shell-hook.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/pkgs/development/interpreters/python/hooks/venv-shell-hook.sh b/pkgs/development/interpreters/python/hooks/venv-shell-hook.sh
new file mode 100644
index 00000000000..3185b1f9fae
--- /dev/null
+++ b/pkgs/development/interpreters/python/hooks/venv-shell-hook.sh
@@ -0,0 +1,26 @@
+venvShellHook() {
+    echo "Executing venvHook"
+    runHook preShellHook
+
+    if [ -d "${venvDir}" ]; then
+      echo "Skipping venv creation, '${venvDir}' already exists"
+    else
+      echo "Creating new venv environment in path: '${venvDir}'"
+      @pythonInterpreter@ -m venv "${venvDir}"
+    fi
+
+    source "${venvDir}/bin/activate"
+
+    runHook postShellHook
+    echo "Finished executing venvShellHook"
+}
+
+if [ -z "${dontUseVenvShellHook:-}" ] && [ -z "${shellHook-}" ]; then
+    echo "Using venvShellHook"
+    if [ -z "${venvDir-}" ]; then
+        echo "Error: \`venvDir\` should be set when using \`venvShellHook\`."
+        exit 1
+    else
+        shellHook=venvShellHook
+    fi
+fi