Skip to content

Commit d4c90f9

Browse files
authored
build_wasm.sh update
Updated the build_wasm.sh script to work with netlify
1 parent 8718ee6 commit d4c90f9

File tree

1 file changed

+54
-24
lines changed

1 file changed

+54
-24
lines changed

scripts/build_wasm.sh

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,83 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
# 1. Setup paths and environment
45
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
56
cd "${ROOT_DIR}"
67

8+
# Determine which Python interpreter to use
79
HOST_PYTHON="${PYTHON_BIN:-}"
810
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
1719
fi
1820

21+
# Create build virtual environment
1922
VENV_DIR="${ROOT_DIR}/.wasm-build-venv"
2023
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}"
2326
fi
2427

2528
PYTHON_BIN="${VENV_DIR}/bin/python"
2629

27-
echo "Building local simdec wheel..."
30+
# Install build dependencies and build the wheel
31+
echo "Installing build tools and generating local wheel..."
2832
"${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
2936
"${PYTHON_BIN}" -m build --wheel .
3037

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
3346

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
3457
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
3561
"${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
4066

67+
# Copy custom index page and static assets
4168
echo "Copying custom index page and static assets..."
42-
# 1. Create the _static folder in the output directory
43-
mkdir -p dist/pyodide/_static
4469

45-
# 2. Copy all your images and thumbnails from docs/_static (if they exist)
70+
# Copy images/thumbnails from docs/_static if they exist
4671
if [ -d "docs/_static" ]; then
47-
cp -r docs/_static/* dist/pyodide/_static/
72+
cp -r docs/_static/* "${OUT_DIR}/_static/"
4873
fi
4974

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
5281

53-
echo "WASM site generated at dist/pyodide"
82+
echo "---"
83+
echo "WASM site successfully generated at ${OUT_DIR}"

0 commit comments

Comments
 (0)