From 46a71f3584096c017a5960851887bae12c2857b5 Mon Sep 17 00:00:00 2001 From: Calum MacRae Date: Mon, 29 Apr 2024 08:46:05 +0100 Subject: [PATCH] fix: ensure Python 3.11 >= requirement is met for create-venv.sh as reported in NillionNetwork/discussions#32 --- packages/nillion/create-venv.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/nillion/create-venv.sh b/packages/nillion/create-venv.sh index 350f1c2..07ce3f8 100644 --- a/packages/nillion/create-venv.sh +++ b/packages/nillion/create-venv.sh @@ -1,5 +1,17 @@ #!/usr/bin/env bash +PYTHON_MAJOR_MINOR_VERSION="" + +function check_python_version() { + required_version="3.11" + current_version=$(python3 --version | cut -d ' ' -f2) + PYTHON_MAJOR_MINOR_VERSION=$(echo $current_version | cut -d '.' -f1,2) + if ! printf '%s\n' "$required_version" "$current_version" | sort -V | head -n 1 | grep -qx "$required_version"; then + echo "This script requires Python ${required_version} or higher. You are running Python $current_version." + exit 1 + fi +} + function create_venv () { if [[ ! -z "${VIRTUAL_ENV:-}" ]]; then echo "Virtualenv is already active! Run 'deactivate' to deactivate the virtualenv." @@ -7,16 +19,17 @@ function create_venv () { fi echo "Creating virtualenv" - python3.11 -m pip install install --user virtualenv==20.24.6 + python3 -m pip install --user virtualenv==20.24.6 NILLION_VENV=".venv" mkdir -p "$NILLION_VENV" - python3.11 -m virtualenv -p python3.11 "$NILLION_VENV" + python3 -m virtualenv -p python3 "$NILLION_VENV" source "$NILLION_VENV/bin/activate" - python3.11 -m pip install -r requirements.txt + python3 -m pip install -r requirements.txt echo "Virtualenv: $NILLION_VENV" - echo "Check the $NILLION_VENV/lib/python3.11/site-packages folder to make sure you have py_nillion_client and nada_dsl packages" + echo "Check the $NILLION_VENV/lib/python${PYTHON_MAJOR_MINOR_VERSION}/site-packages folder to make sure you have py_nillion_client and nada_dsl packages" } +check_python_version create_venv