| set -euo pipefail | |
| REPO_DIR="${REPO_DIR:-/nfs/ywang29/GmNet/journal_exp}" | |
| VENV_DIR="${VENV_DIR:-/tmp/gmnet_venv}" | |
| PYTHON_BASE="${PYTHON_BASE:-python3}" | |
| INSTALL_DEV="${INSTALL_DEV:-0}" | |
| UPGRADE_PACKAGING_TOOLS="${UPGRADE_PACKAGING_TOOLS:-0}" | |
| if [[ "${VENV_DIR}" != /tmp && "${VENV_DIR}" != /tmp/* ]]; then | |
| echo "VENV_DIR must be under /tmp so setup cannot modify the global environment" >&2 | |
| exit 2 | |
| fi | |
| if [[ ! -f "${REPO_DIR}/pyproject.toml" ]]; then | |
| echo "GmNet journal repository not found at ${REPO_DIR}" >&2 | |
| exit 1 | |
| fi | |
| if ! command -v "${PYTHON_BASE}" >/dev/null 2>&1; then | |
| echo "Python executable not found: ${PYTHON_BASE}" >&2 | |
| exit 1 | |
| fi | |
| if [[ ! -x "${VENV_DIR}/bin/python" ]]; then | |
| "${PYTHON_BASE}" -m venv --system-site-packages "${VENV_DIR}" | |
| fi | |
| PYTHON="${VENV_DIR}/bin/python" | |
| export PIP_DISABLE_PIP_VERSION_CHECK=1 | |
| if [[ "${UPGRADE_PACKAGING_TOOLS}" == 1 ]]; then | |
| "${PYTHON}" -m pip install --upgrade pip setuptools wheel | |
| fi | |
| "${PYTHON}" -m pip install -r "${REPO_DIR}/requirements-runtime.txt" | |
| if [[ "${INSTALL_DEV}" == 1 ]]; then | |
| "${PYTHON}" -m pip install -r "${REPO_DIR}/requirements-dev.txt" | |
| fi | |
| "${PYTHON}" -m pip install --no-build-isolation --editable "${REPO_DIR}" | |
| "${PYTHON}" "${REPO_DIR}/scripts/check_env.py" --strict-versions | |
| echo "Isolated GmNet environment is ready: ${VENV_DIR}" | |
| echo "Use ${PYTHON} or export VENV_DIR=${VENV_DIR} when running scripts." | |