#!/usr/bin/env bash
set -euxo pipefail

# Build the package environment from the repository Project.toml. The IJulia
# kernel below uses --project=@. so notebooks opened under this checkout use
# this same package environment.
julia --project=. -e 'using Pkg; Pkg.instantiate(); Pkg.precompile(); using LAlatex, LaTeXStrings, Symbolics, BlockArrays'
julia --project=. scripts/binder_warmup.jl

# Expose the Python helper shim as `import lalatex` in Python notebooks opened
# from any directory inside the Binder checkout.
python -m pip install --upgrade pip setuptools wheel juliacall sympy
python -m pip install --no-build-isolation --no-deps -e .
PYTHON_JULIACALL_EXE=julia PYTHON_JULIACALL_PROJECT=. LALATEX_PROJECT=. python scripts/python_interop_smoke.py --require-installed

# Keep IJulia out of the package dependencies while still providing a Binder
# notebook kernel.
julia -e 'using Pkg; Pkg.add("IJulia"); Pkg.precompile(); using IJulia; installkernel("Julia LAlatex", "--project=@.")'
