File size: 4,307 Bytes
0cc98ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
set -euo pipefail

export TRANSFORMERS_NO_AUDIO=1 # That usually makes transformers.audio_utils skip the soxr import path entirely.

# Load environment variables from .env file.
if [ -f .env ]; then
  echo "πŸ’‘ Loaded .env file."
  source .env # this loads the .env file and exports its variables into the environment
else
  echo "🚨 Error: .env file not found!"
  exit 1
fi


# Choose a port (default 5678) or pass DEBUG_PORT=xxxx
# Parse KEY=VALUE args
for arg in "$@"; do
  case $arg in
    PORT=*)
      DEBUG_PORT="${arg#PORT=}"
      shift
      ;;
  esac
done
PORT="${DEBUG_PORT:-5678}"



# Use the container venv (this image already has /venv and PATH set)
# IMPORTANT: do NOT activate ./ .venv here, because that points to your old netscratch venv.
# # Activate venv (./.venv symlinks to /netscratch/.../KBExtract)
# # source ./.venv/bin/activate
if [ -x /venv/bin/python ]; then
  export VIRTUAL_ENV=/venv
  export PATH="/venv/bin:${PATH}"
else
  echo "🚨 Error: /venv/bin/python not found. Are you running inside the kbdebugger.sqsh container?" >&2
  exit 1
fi


echo "🐍 $(python --version) @ $(which python)"


NUMPY_PIN="${NUMPY_PIN:-1.26.4}"
python -m pip install --force-reinstall "numpy==${NUMPY_PIN}" >/dev/null || true
# python -m pip install --force-reinstall numpy==1.26.4

# # ------------------ Portable hnswlib install (wheelhouse) ------------------
# # Goal: avoid SIGILL when SLURM places you on a different CPU node.
# # One-time: build a portable wheel into ./.wheelhouse (see scripts/build_portable_wheels.sh).
# # Every run: reinstall from wheelhouse quickly and deterministically.

# WHEELHOUSE="${WHEELHOUSE:-/netscratch/abuali/wheelhouse}"
# NUMPY_PIN="${NUMPY_PIN:-1.26.4}"

# install_hnswlib_from_wheelhouse() {
#   if [ -d "$WHEELHOUSE" ] && ls -1 "$WHEELHOUSE"/hnswlib-*.whl >/dev/null 2>&1; then
#     echo "πŸ“¦ Installing hnswlib from wheelhouse: $WHEELHOUSE (no deps)"
#     python -m pip install --no-index --no-deps --find-links="$WHEELHOUSE" --force-reinstall hnswlib >/dev/null
#     python -m pip install --force-reinstall "numpy==${NUMPY_PIN}" >/dev/null || true
#     python -c "import hnswlib, numpy as np; print('βœ… hnswlib:', hnswlib.__file__); print('βœ… numpy:', np.__version__)"
#   else
#     echo "⚠️ Wheelhouse missing/empty at: $WHEELHOUSE"
#     echo "   Build once with: python -m pip wheel --no-build-isolation --no-binary=:all: --no-deps -w $WHEELHOUSE hnswlib"
#   fi
# }

# install_hnswlib_from_wheelhouse
# # --------------------------------------------------------------------------


# print which venv got activated (great for debugging)
python -c "import sys; print('sys.executable:', sys.executable)"

echo "πŸͺ²πŸž Debugger will listen on 0.0.0.0:${PORT}"

# Make src/ visible as a top-level package root
export PYTHONPATH="${PYTHONPATH:-}:$(pwd)/src"

# -------- portable port check (no 'ss' dependency) ----------
if ! python - "$PORT" <<'PY'
import socket, sys
port = int(sys.argv[1])
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
    s.bind(("0.0.0.0", port))
    # free immediately; we just wanted the test
    s.close()
    sys.exit(0)
except OSError:
    sys.exit(1)
PY
then
  echo "⚠️ Port ${PORT} appears to be in use."
  # Best-effort diagnostics if tools are present
  if command -v lsof >/dev/null 2>&1; then
    echo "πŸ”Ž lsof on :${PORT}:"
    lsof -i TCP:${PORT} || true
  elif command -v fuser >/dev/null 2>&1; then
    echo "πŸ”Ž fuser on :${PORT}:"
    fuser -v -n tcp ${PORT} || true
  else
    echo "ℹ️ Install lsof/fuser for more details, or pick another port."
  fi
  echo "πŸ‘‰ Use a free port: DEBUG_PORT=5690 $0"
  exit 1
fi
# -----------------------------------------------------------

# # If the port is busy, show owner and exit nicely
# if ss -ltnp | grep -q ":${PORT} "; then
#   echo "⚠️ Port ${PORT} is already in use:"
#   ss -ltnp | grep ":${PORT} " || true
#   echo "πŸ‘‰ Set DEBUG_PORT to a free port, e.g.: DEBUG_PORT=5690 $0"
#   exit 1
# fi

# Start debugpy and wait for VS Code to attach
# Tip: 0.0.0.0 makes it reachable from the login node for tunneling
# exec python -m debugpy --listen 0.0.0.0:$PORT --wait-for-client -m kbdebugger.main "$@"
exec python -m debugpy --listen 0.0.0.0:$PORT --wait-for-client -m kbdebugger.main "$@"