Blame view

scripts/create_venv.sh 1.52 KB
484adbfe   tangwang   adapt ubuntu; con...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  #!/bin/bash
  #
  # Create and initialize Python venv for saas-search.
  #
  # Usage:
  #   ./scripts/create_venv.sh
  #
  set -euo pipefail
  
  PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
  cd "${PROJECT_ROOT}"
  
  VENV_DIR="${PROJECT_ROOT}/.venv"
  
  PYTHON_BIN="${PYTHON_BIN:-python3.10}"
  if ! command -v "${PYTHON_BIN}" >/dev/null 2>&1; then
    PYTHON_BIN="python3"
  fi
  
  echo "Using python: $(${PYTHON_BIN} --version)"
  
  if ! "${PYTHON_BIN}" -c "import ensurepip" >/dev/null 2>&1; then
    echo "ERROR: ensurepip is not available for ${PYTHON_BIN}." >&2
    echo "On Ubuntu/Debian, install the venv package first, e.g.:" >&2
    echo "  sudo apt-get update -y && sudo apt-get install -y python3-venv" >&2
    echo "If you are using Python 3.12 specifically, you may need:" >&2
    echo "  sudo apt-get install -y python3.12-venv" >&2
    exit 1
  fi
  
  if [[ -d "${VENV_DIR}" ]]; then
    if [[ -f "${VENV_DIR}/bin/activate" ]]; then
      echo "venv already exists at ${VENV_DIR}"
    else
      echo "Found incomplete venv at ${VENV_DIR}, recreating..."
      rm -rf "${VENV_DIR}"
      "${PYTHON_BIN}" -m venv "${VENV_DIR}"
    fi
  else
    echo "Creating venv at ${VENV_DIR} ..."
    "${PYTHON_BIN}" -m venv "${VENV_DIR}"
  fi
  
  # shellcheck disable=SC1091
  source "${VENV_DIR}/bin/activate"
  
ed948666   tangwang   tidy
47
  python -m pip install --upgrade pip wheel
484adbfe   tangwang   adapt ubuntu; con...
48
49
50
51
52
53
54
55
56
57
58
59
  python -m pip install -r requirements.txt
  
  if [[ "${INSTALL_ML:-0}" == "1" ]]; then
    echo
    echo "INSTALL_ML=1 detected. Installing optional ML dependencies..."
    python -m pip install -r requirements_ml.txt
  fi
  
  echo
  echo "Done."
  echo "Next:"
  echo "  source activate.sh"