From 97cab90b580fa6cefdd2097fea6d9da84d0558eb Mon Sep 17 00:00:00 2001 From: Louise Poole Date: Thu, 27 Mar 2025 16:55:37 +0100 Subject: [PATCH] fix: fix script dependency check and paths (#186) Allows you to run the script from outside of the testing directory. --- testing/setup_env.sh | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/testing/setup_env.sh b/testing/setup_env.sh index eed6ead..f67b948 100755 --- a/testing/setup_env.sh +++ b/testing/setup_env.sh @@ -5,23 +5,12 @@ command_exists() { command -v "$1" >/dev/null 2>&1 } -# Map of dependencies to their binaries (used to check if they are installed) -declare -A dependencies=( - ["git"]="git" - ["rust"]="rustc" - ["gcc"]="gcc" - ["openssl"]="openssl" - ["pkg-config"]="pkg-config" - ["conda"]="conda" - ["pip"]="pip" - ["libpq"]="pg_config" -) - -# Check each dependency -for dep in "${!dependencies[@]}"; do - binary=${dependencies[$dep]} - if ! command_exists "$binary"; then - echo "Error: '$dep' is not installed." +# Check each dependency is installed +local deps=("git" "rustc" "gcc" "openssl" "conda" "pip" "pg_config") +local names=("git" "rust" "gcc" "openssl" "conda" "pip" "libpq") +for i in "${!deps[@]}"; do + if ! command_exists "${deps[$i]}"; then + echo "Error: '${names[$i]}' is not installed." exit 1 fi done @@ -31,7 +20,10 @@ echo "All dependencies are installed. Proceeding with setup..." # Variables ENV_NAME="tycho-protocol-sdk-testing" PYTHON_VERSION="3.9" -REQUIREMENTS_FILE="requirements.txt" +# Get the directory where this script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +ROOT_DIR="$( cd "$SCRIPT_DIR/.." && pwd )" # Assuming the script is in a subdirectory of the root +REQUIREMENTS_FILE="$ROOT_DIR/testing/requirements.txt" # Create conda environment echo "Creating conda environment ${ENV_NAME} with Python ${PYTHON_VERSION}..." @@ -46,5 +38,6 @@ echo "Installing the requirements from ${REQUIREMENTS_FILE}..." pip install -r $REQUIREMENTS_FILE --index-url https://pypi.org/simple conda activate $ENV_NAME -echo "Setup complete." +echo "----------------------------------------" +echo "SETUP COMPLETE." echo "Run 'conda activate $ENV_NAME' to activate the environment." \ No newline at end of file