Skip to content

Commit

Permalink
Fixes not installing the python sources we dl
Browse files Browse the repository at this point in the history
Also restores putting the venv in PREFIX/venv

Doesn’t delete anything the venv creates since pipenv seems to want to run its own activate in some context or another.
  • Loading branch information
mxcl committed Feb 27, 2023
1 parent cf5df18 commit 895c9da
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions share/brewkit/python-venv.sh
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -15,42 +14,46 @@ 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 <<EOF > "$CMD_NAME"
mkdir -p ../bin

#FIXME requiring sed is a bit lame
cat <<EOF > ../bin/"$CMD_NAME"
#!/bin/sh
export VIRTUAL_ENV="\$(cd "\$(dirname "\$0")"/.. && pwd)"
export VIRTUAL_ENV="\$(cd "\$(dirname "\$0")"/.. && pwd)/venv"
cat <<EOSH > \$VIRTUAL_ENV/pyvenv.cfg
home = \$TEA_PREFIX/python.org/v$PYTHON_VERSION_MAJ/bin
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"

0 comments on commit 895c9da

Please sign in to comment.