From f0a0bfed9a2325bb382ef5ea0ade6655beb5807b Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Fri, 24 Jul 2020 13:29:35 +0200 Subject: [PATCH] Update python scripts pypi-release: install required venv dependencies venv: add support for per project .venv file --- devel/pypi-release | 2 +- misc/venv | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/devel/pypi-release b/devel/pypi-release index 61d84a7..1e07b52 100755 --- a/devel/pypi-release +++ b/devel/pypi-release @@ -9,7 +9,7 @@ if [[ $? != 0 ]]; then fi cd $root -pip-venv-deps twine bump2version +pip-venv-deps twine bump2version setuptools wheel if ! exists chronic; then echo "(chronic not found. install moreutils to only see relevant output)" diff --git a/misc/venv b/misc/venv index 0109392..e834f56 100755 --- a/misc/venv +++ b/misc/venv @@ -8,7 +8,9 @@ zparseopts -D -E \ n=newvenv -new=newvenv \ t=tmsu -tmsu=tmsu \ p=pyenv -pyenv=pyenv \ - f=find -find=find + f=find -find=find \ + i=ignore -ignore-local=ignore \ + s=save -save=save if [[ $help ]]; then <<-HELP @@ -26,7 +28,12 @@ if [[ $help ]]; then -p, --pyenv Use pyenv virtualenvs -f, --find Search for virtualenvs by looking for directories ending with 'venv' - If neither -p or -f are given, the default behaviour is to use both + If neither -p or -f are given, the default behaviour is to use both + + -s, --save Store selected venv in .venv in current directory. Will be used + automatically, when called in this dir again. + -i, --ignore-local + Ignore .venv files. HELP exit fi @@ -39,7 +46,7 @@ venvsh() { if [[ -z $cdvenv ]]; then cd $ORIGDIR fi - $SHELL + exec $SHELL } pyenvsh() { @@ -47,9 +54,26 @@ pyenvsh() { eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)" pyenv activate "$1" - $SHELL + exec $SHELL } +envsh() { + local venv=$1 + if [[ $venv =~ pyenv\!* ]]; then + pyenvsh ${venv##pyenv!} + else + venvsh $venv + fi +} + +if [[ -z $ignore && -e .venv ]]; then + venv=$(<.venv) + echo "Local .venv found (-i to ignore)." + echo "Using: $venv" + envsh $venv +fi + + if [[ -n $tmsu ]]; then venv=$( for i in $(tmsu files --directory lang=python); do @@ -84,10 +108,10 @@ elif [[ ! $pyenv && $find ]]; then else venv=$(cat <(fd -I -t d 'venv$' $1) <(pyenvs) | fzf) fi + if [[ -n $venv ]]; then - if [[ $venv =~ pyenv\!* ]]; then - exec pyenvsh ${venv##pyenv!} - else - exec venvsh $venv + if [[ -n $save ]]; then + echo $venv > .venv fi + envsh $venv fi