diff --git a/share/brewkit/python-venv.sh b/share/brewkit/python-venv.sh index 6dbf4fae..c5e0921d 100755 --- a/share/brewkit/python-venv.sh +++ b/share/brewkit/python-venv.sh @@ -1,12 +1,11 @@ -#!/bin/sh +#!/usr/bin/env -S tea sh #--- # dependencies: -# gnu.org/coreutils: '*' +# git-scm.org: ^2 +# # ^^ required to set version tag used by setup tools #--- -#TODO no need to make a sub-dir, just make what we got the v-env - set -ex CMD_NAME=$(basename "$1") @@ -15,29 +14,30 @@ VERSION="$(basename "$PREFIX")" PYTHON_VERSION=$(python --version | cut -d' ' -f2) PYTHON_VERSION_MAJ=$(echo "$PYTHON_VERSION" | cut -d. -f1) -python -m venv "$PREFIX" - -cd "$PREFIX"/bin +export VIRTUAL_ENV="$PREFIX"/venv -./pip install "$CMD_NAME==$VERSION" +python -m venv "$VIRTUAL_ENV" -for x in *; do - if test "$x" != "$CMD_NAME" -a "$x" != python; then - rm "$x" - fi -done +# setup tools requires a git version typically +cd "$SRCROOT" +git init +git commit -mnil --allow-empty +git tag -a "$VERSION" -m "Version $VERSION" -mkdir ../libexec -mv "$CMD_NAME" ../libexec/"$CMD_NAME" +cd "$VIRTUAL_ENV" +bin/pip install "$SRCROOT" --verbose # python virtual-envs are not relocatable # our only working choice is to rewrite these files and symlinks every time # because we promise that tea is relocatable *at any time* -cat < "$CMD_NAME" +mkdir -p ../bin + +#FIXME requiring sed is a bit lame +cat < ../bin/"$CMD_NAME" #!/bin/sh -export VIRTUAL_ENV="\$(cd "\$(dirname "\$0")"/.. && pwd)" +export VIRTUAL_ENV="\$(cd "\$(dirname "\$0")"/.. && pwd)/venv" cat < \$VIRTUAL_ENV/pyvenv.cfg home = \$TEA_PREFIX/python.org/v$PYTHON_VERSION_MAJ/bin @@ -45,12 +45,15 @@ include-system-site-packages = false executable = \$TEA_PREFIX/python.org/v$PYTHON_VERSION_MAJ/bin/python EOSH -sed -i.bak "1s|.*|#!\$VIRTUAL_ENV/bin/python|" "\$VIRTUAL_ENV"/libexec/$CMD_NAME +find "\$VIRTUAL_ENV"/bin -depth 1 -type f | xargs \ + sed -i.bak "1s|.*|#!\$VIRTUAL_ENV/bin/python|" + +rm "\$VIRTUAL_ENV"/bin/*.bak ln -sf "\$TEA_PREFIX"/python.org/v$PYTHON_VERSION_MAJ/bin/python "\$VIRTUAL_ENV"/bin/python -exec "\$VIRTUAL_ENV"/libexec/$CMD_NAME "\$@" +exec "\$VIRTUAL_ENV"/bin/$CMD_NAME "\$@" EOF -chmod +x "$CMD_NAME" +chmod +x ../bin/"$CMD_NAME"