|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
| 4 | +# 1. Setup paths and environment |
4 | 5 | ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
5 | 6 | cd "${ROOT_DIR}" |
6 | 7 |
|
| 8 | +# Determine which Python interpreter to use |
7 | 9 | HOST_PYTHON="${PYTHON_BIN:-}" |
8 | 10 | if [[ -z "${HOST_PYTHON}" ]]; then |
9 | | - if command -v python3 >/dev/null 2>&1; then |
10 | | - HOST_PYTHON="python3" |
11 | | - elif command -v python >/dev/null 2>&1; then |
12 | | - HOST_PYTHON="python" |
13 | | - else |
14 | | - echo "No python interpreter found. Install python3 and retry." |
15 | | - exit 1 |
16 | | - fi |
| 11 | + if command -v python3 >/dev/null 2>&1; then |
| 12 | + HOST_PYTHON="python3" |
| 13 | + elif command -v python >/dev/null 2>&1; then |
| 14 | + HOST_PYTHON="python" |
| 15 | + else |
| 16 | + echo "Error: No python interpreter found. Install python3 and retry." |
| 17 | + exit 1 |
| 18 | + fi |
17 | 19 | fi |
18 | 20 |
|
| 21 | +# Create build virtual environment |
19 | 22 | VENV_DIR="${ROOT_DIR}/.wasm-build-venv" |
20 | 23 | if [[ ! -d "${VENV_DIR}" ]]; then |
21 | | - echo "Creating build virtual environment at ${VENV_DIR}..." |
22 | | - "${HOST_PYTHON}" -m venv "${VENV_DIR}" |
| 24 | + echo "Creating build virtual environment at ${VENV_DIR}..." |
| 25 | + "${HOST_PYTHON}" -m venv "${VENV_DIR}" |
23 | 26 | fi |
24 | 27 |
|
25 | 28 | PYTHON_BIN="${VENV_DIR}/bin/python" |
26 | 29 |
|
27 | | -echo "Building local simdec wheel..." |
| 30 | +# Install build dependencies and build the wheel |
| 31 | +echo "Installing build tools and generating local wheel..." |
28 | 32 | "${PYTHON_BIN}" -m pip install --upgrade pip build panel matplotlib seaborn scipy SALib |
| 33 | + |
| 34 | +# Clean old builds to avoid picking up the wrong wheel |
| 35 | +rm -rf dist/*.whl |
29 | 36 | "${PYTHON_BIN}" -m build --wheel . |
30 | 37 |
|
31 | | -SIMDEC_WHEEL="$(ls dist/simdec-*.whl | head -n 1)" |
32 | | -export PYTHONPATH="${ROOT_DIR}/src:${PYTHONPATH:-}" |
| 38 | +# Identify the generated wheel file |
| 39 | +# This prevents the "unbound variable" error by checking if the file exists |
| 40 | +SIMDEC_WHEEL_PATH=$(ls dist/*.whl | head -n 1 || echo "") |
| 41 | + |
| 42 | +if [[ -z "${SIMDEC_WHEEL_PATH}" ]]; then |
| 43 | + echo "Error: No wheel file found in dist/. Build failed." |
| 44 | + exit 1 |
| 45 | +fi |
33 | 46 |
|
| 47 | +WHEEL_FILENAME=$(basename "${SIMDEC_WHEEL_PATH}") |
| 48 | + |
| 49 | +# Prepare output directory |
| 50 | +OUT_DIR="dist/pyodide" |
| 51 | +mkdir -p "${OUT_DIR}/_static" |
| 52 | + |
| 53 | +# IMPORTANT: Copy the wheel into the output directory so it's accessible via HTTP |
| 54 | +cp "${SIMDEC_WHEEL_PATH}" "${OUT_DIR}/" |
| 55 | + |
| 56 | +# Convert Panel apps to Pyodide worker |
34 | 57 | echo "Converting Panel apps to Pyodide worker output..." |
| 58 | +export PYTHONPATH="${ROOT_DIR}/src:${PYTHONPATH:-}" |
| 59 | + |
| 60 | +# Use the full path for the requirements so the converter can find the file |
35 | 61 | "${PYTHON_BIN}" -m panel convert panel/simdec_app.py panel/sampling.py \ |
36 | | - --to pyodide-worker \ |
37 | | - --out dist/pyodide \ |
38 | | - --requirements "${SIMDEC_WHEEL}" numpy pandas matplotlib seaborn scipy SALib \ |
39 | | - --resources panel/data/stress.csv |
| 62 | + --to pyodide-worker \ |
| 63 | + --out "${OUT_DIR}" \ |
| 64 | + --requirements "${SIMDEC_WHEEL_PATH}" numpy pandas matplotlib seaborn scipy SALib \ |
| 65 | + --resources panel/data/stress.csv |
40 | 66 |
|
| 67 | +# Copy custom index page and static assets |
41 | 68 | echo "Copying custom index page and static assets..." |
42 | | -# 1. Create the _static folder in the output directory |
43 | | -mkdir -p dist/pyodide/_static |
44 | 69 |
|
45 | | -# 2. Copy all your images and thumbnails from docs/_static (if they exist) |
| 70 | +# Copy images/thumbnails from docs/_static if they exist |
46 | 71 | if [ -d "docs/_static" ]; then |
47 | | - cp -r docs/_static/* dist/pyodide/_static/ |
| 72 | + cp -r docs/_static/* "${OUT_DIR}/_static/" |
48 | 73 | fi |
49 | 74 |
|
50 | | -# 3. Copy your beautiful custom HTML file to act as the homepage OVERWRITING anything else |
51 | | -cp panel/index.html dist/pyodide/index.html |
| 75 | +# Overwrite default index.html with your custom homepage |
| 76 | +if [ -f "panel/index.html" ]; then |
| 77 | + cp panel/index.html "${OUT_DIR}/index.html" |
| 78 | +else |
| 79 | + echo "Warning: panel/index.html not found. Using default Panel index." |
| 80 | +fi |
52 | 81 |
|
53 | | -echo "WASM site generated at dist/pyodide" |
| 82 | +echo "---" |
| 83 | +echo "WASM site successfully generated at ${OUT_DIR}" |
0 commit comments