Created
May 19, 2024 17:16
-
-
Save hexmode/01c664dc51bbb5dd7bbbe10f2e0c3279 to your computer and use it in GitHub Desktop.
Test venv with different pythons in the path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
VENV_DIR=envdir | |
setup() { | |
local asdf=$1 | |
local env=$2 | |
local python=$3 | |
local first=$4 | |
if [ -n "$env" ]; then | |
export VIRTUALENV_PYTHON=$env | |
fi | |
if [ -z "$env" ]; then | |
unset VIRTUALENV_PYTHON | |
fi | |
rm -rf "$VENV_DIR" | |
virtualenv ${python:+--python=$python} ${first:+--try-first-with=$first} "$VENV_DIR" > /dev/null 2>&1 | |
. "$VENV_DIR/bin/activate" | |
active=$(python --version | sed 's/^Python //') | |
deactivate | |
disactive=$(python --version | sed 's/^Python //') | |
first=$(echo $first | sed s,$HOME,~,g) | |
python=$(echo $python | sed s,$HOME,~,g) | |
line="$asdf\t$VIRTUALENV_PYTHON\t$python\t$first\t$active\t$disactive" | |
echo -e -n "$line\r" >&2 | |
echo -e "$line" | |
} | |
( | |
version=("" "3.8.19" "3.9.19" "3.10.14" "3.11.9" "3.12.3") | |
version=("" "3.9.19" "3.11.9" ) | |
short=() | |
for ver in "${version[@]}"; do | |
short+=( "${ver%.*}" ) | |
PATH="$PATH:$HOME/.asdf/installs/python/$ver/bin" | |
done | |
echo -e "asdf\tENV\t--python\t--try-first-with\tActivated\tDeactivated" | |
for asdf in "${version[@]}"; do | |
echo "python ${asdf:-system}" > .tool-versions | |
for env in "${short[@]}"; do | |
for pyver in "${short[@]}"; do | |
fullpyver="$pyver" | |
test -z "$fullpyver" || fullpyver="$(echo $HOME/.asdf/installs/python/$pyver*/bin/python$pyver)" | |
for first in "${short[@]}"; do | |
test -z "$first" || first="$(echo $HOME/.asdf/installs/python/$first*/bin/python$first)" | |
setup "$asdf" "$env" "$pyver" "$first" | |
test -z "$pyver" || setup "$asdf" "$env" "python$pyver" "$first" | |
test -z "$fullpyver" || setup "$asdf" "$env" "$fullpyver" "$first" | |
done | |
done | |
done | |
done | |
) | column -t -s $'\t' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output.txt is the output of this.