#!/usr/bin/env bash

MIN_VERSION=3.10

function version_gte() {
    test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
}

function usage() {
    echo "Usage: $(basename $0) <venv-name> [...]"
    echo ""
    exit 1
}

VENV_NAME="$1"
PYTHON="$(which python python3.10 python3.11 python3 2> /dev/null | tail -n 1)"
if [ -n "$PYTHON" ]; then
    PYTHON_VER="$($PYTHON --version | cut -f2 -d' ')"
    echo "System python version $PYTHON_VER at $PYTHON"
else
    PYTHON_VER=0
    echo "No system python version found"
fi

: ${1?"$(usage)"}
#  Script exits here if command-line parameters absent

if version_gte "$MIN_VERSION" "$PYTHON_VER"; then
    echo "Min python version $MIN_VERSION. TODO: pyenv"
    exit 1
else
    if [ ! -e $VENV_NAME ]; then
        $PYTHON -m venv "$VENV_NAME"
    fi
    bash --init-file <(echo "source ~/.bashrc; source ./$VENV_NAME/bin/activate")
fi
Edit Report
Pub: 21 Apr 2023 20:23 UTC
Edit: 21 Apr 2023 20:24 UTC
Views: 28