{% extends "base_debian.j2" %}
{% set __python_version_txt__=expands_bento_path("env", "python", "version.txt") %}
{% set __environment_yml__=expands_bento_path("env", "conda", "environment.yml") %}
{% block SETUP_BENTO_ENVARS %}
{{ super() }}

RUN --mount=type=cache,mode=0777,target=/root/.cache/pip bash <<EOF
SAVED_PYTHON_VERSION=$(cat {{ __python_version_txt__ }})
PYTHON_VERSION=${SAVED_PYTHON_VERSION%.*}

echo "Installing Python $PYTHON_VERSION with conda..."
conda install -y -n base pkgs/main::python=$PYTHON_VERSION pip

if [ -f {{ __environment_yml__ }} ]; then
  # set pip_interop_enabled to improve conda-pip interoperability. Conda can use
  # pip-installed packages to satisfy dependencies.
  echo "Updating conda base environment with environment.yml"
  conda config --set pip_interop_enabled True || true
  conda env update -n base -f {{ __environment_yml__ }}
  conda clean --all
fi
EOF
{% endblock %}
