#!/bin/bash

set -e

install_dir=$1
if [ -z "$install_dir" ]; then
  echo "usage: $0 INSTALL_DIR"
  exit 1
fi

helpers_dir="$(dirname "${BASH_SOURCE[0]}")"
cp -r \
  "$helpers_dir/lib" \
  "$helpers_dir/run.py" \
  "$helpers_dir/requirements.txt" \
  "$install_dir"

cd "$install_dir"
PYENV_VERSION=2.7.18 pyenv exec pip install -r "requirements.txt"
PYENV_VERSION=3.9.4  pyenv exec pip install -r "requirements.txt"

# Workaround of https://github.com/python-poetry/poetry/issues/3010
# By default poetry config file is stored under ~/.config/pypoetry
# and is not bound to any specific Python version
PYENV_VERSION=3.9.4 pyenv exec poetry config experimental.new-installer false
