aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Pasquet <dev@etenil.net>2016-12-23 00:03:34 +0000
committerGuillaume Pasquet <dev@etenil.net>2016-12-23 00:03:34 +0000
commite33cb3f849dc32e5c0f083ac5f1394dc792b32a1 (patch)
tree1c4eacf06d730fe74cefc14751162a35da97f3fd
Initial commit.
-rw-r--r--README.md32
-rwxr-xr-xvenvworkon.sh30
2 files changed, 62 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..3ddcf66
--- /dev/null
+++ b/README.md
@@ -0,0 +1,32 @@
+VENV WORKON
+===========
+
+A very simple wrapper around python3's venv. This little script
+allows creating and using venvs well tucked away from your project
+code.
+
+## Install
+Put the `venvworkon.sh` script somewhere and source it in your
+`~/.profile` or `~/.bashrc` file.
+
+## Usage
+The script only supports one usage mode:
+
+ $ workon [environment]
+
+If *environment* is not provided, then the list of existing venvs
+will be printed instead.
+
+## Where venvs are created
+When `workon` is called, venvs are created or loaded from the
+`$HOME/.venvs` folder.
+
+## Post-load script
+If the file `$HOME/.venvs/<venv>/postload.sh` exists, it is
+automatically sourced after the venv is loaded. This is useful
+to export environment variable such as `DJANGO_SETTINGS_MODULE`.
+
+## Why bother using this
+`virtualenvwrapper` is certainly much more feature-packed and
+useful than this. But this wrapper is handy for development and
+uses the light-weight `pyvenv` rather than virtualenv. Up to you.
diff --git a/venvworkon.sh b/venvworkon.sh
new file mode 100755
index 0000000..1da01bd
--- /dev/null
+++ b/venvworkon.sh
@@ -0,0 +1,30 @@
+workon() {
+ envroot="$HOME/.venv"
+
+ if [ ! -e "$envroot" ]
+ then
+ mkdir -p "$envroot"
+ fi
+
+ if [ "$#" -lt "1" ]
+ then
+ ls "$envroot"
+ return
+ fi
+
+ envname=$1
+
+ envdir="$envroot/$envname"
+
+ if [ ! -e "$envdir" ]
+ then
+ pyvenv "$envdir"
+ fi
+
+ source "$envdir/bin/activate"
+
+ if [ -e "$envdir/postload.sh" ]
+ then
+ source "$envdir/postload.sh"
+ fi
+}