#!/usr/bin/env bash
set -euo pipefail

cd "${ASCEND_DEPLOYER_HOME:-/workspaces/ascend-deployer}"
export PATH="$HOME/.local/bin:$PATH"

sudo mkdir -p "$HOME/.cache/pip" "$HOME/.ansible/tmp" "$HOME/.ascend_deployer"
sudo chown -R "$(id -u):$(id -g)" "$HOME/.cache/pip" "$HOME/.ansible" "$HOME/.ascend_deployer"
chmod 700 "$HOME/.ansible" "$HOME/.ansible/tmp"

if [ -f .devcontainer/requirements-dev.txt ]; then
  python3 -m pip install --user -r .devcontainer/requirements-dev.txt
elif [ -f test/requirements.txt ]; then
  python3 -m pip install --user -r test/requirements.txt
fi

python3 -m pre_commit install

echo "Ascend Deployer development container is ready."
echo "Project is available through PYTHONPATH: ${PYTHONPATH:-}"
python3 --version
python3 -m pip --version
ansible --version
python3 -m pytest --version