mirror of
https://github.com/saymrwulf/QuantumLearning.git
synced 2026-05-18 21:30:13 +00:00
56 lines
1.6 KiB
Bash
Executable file
56 lines
1.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
PORT="${1:-8888}"
|
|
|
|
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
|
|
cat <<'EOF'
|
|
Usage: ./scripts/start_jupyter.sh [port]
|
|
|
|
Starts repo-local JupyterLab from .venv with project-local config, runtime,
|
|
kernel registration, and notebook defaults.
|
|
EOF
|
|
exit 0
|
|
fi
|
|
|
|
if ! [[ "$PORT" =~ ^[0-9]+$ ]]; then
|
|
echo "Port must be an integer, got: $PORT" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -x "$ROOT_DIR/.venv/bin/python" ]]; then
|
|
echo "Missing repo-local .venv at $ROOT_DIR/.venv" >&2
|
|
echo "Create it first with: python3.12 -m venv .venv" >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p \
|
|
"$ROOT_DIR/.cache/matplotlib" \
|
|
"$ROOT_DIR/.ipython" \
|
|
"$ROOT_DIR/.jupyter_config" \
|
|
"$ROOT_DIR/.jupyter_data" \
|
|
"$ROOT_DIR/.jupyter_runtime"
|
|
|
|
# Keep JupyterLab away from the broken Homebrew node installation on this machine.
|
|
export PATH="$ROOT_DIR/.venv/bin:/usr/bin:/bin:/usr/sbin:/sbin"
|
|
export JUPYTER_CONFIG_DIR="$ROOT_DIR/.jupyter_config"
|
|
export JUPYTER_DATA_DIR="$ROOT_DIR/.jupyter_data"
|
|
export JUPYTER_RUNTIME_DIR="$ROOT_DIR/.jupyter_runtime"
|
|
export IPYTHONDIR="$ROOT_DIR/.ipython"
|
|
export MPLCONFIGDIR="$ROOT_DIR/.cache/matplotlib"
|
|
|
|
KERNEL_DIR="$ROOT_DIR/.venv/share/jupyter/kernels/quantum-learning"
|
|
if [[ ! -f "$KERNEL_DIR/kernel.json" ]]; then
|
|
"$ROOT_DIR/.venv/bin/python" -m ipykernel install \
|
|
--sys-prefix \
|
|
--name quantum-learning \
|
|
--display-name "QuantumLearning (.venv)" \
|
|
--env IPYTHONDIR "$IPYTHONDIR" \
|
|
--env MPLCONFIGDIR "$MPLCONFIGDIR"
|
|
fi
|
|
|
|
exec "$ROOT_DIR/.venv/bin/jupyter" lab \
|
|
--no-browser \
|
|
--ip=127.0.0.1 \
|
|
--port="$PORT"
|