Skip to content

Commit bc881b5

Browse files
feat(binder): enhance postBuild script for improved dependency management and kernel configuration
1 parent 2f22ca4 commit bc881b5

3 files changed

Lines changed: 230 additions & 361 deletions

File tree

binder/postBuild

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,58 @@
11
#!/bin/bash
22
set -euxo pipefail
33

4-
# First, instantiate and precompile your binder environment as usual
5-
julia --project=binder -e 'using Pkg; Pkg.instantiate(); Pkg.precompile()'
6-
7-
# Now, find the julia kernel.json and force it to use our project
8-
# This is the magic that makes the Pluto plugin work correctly
9-
KERNEL_PATH=$(jupyter kernelspec list | grep julia | awk '{print $2}')
10-
cat <<EOF > temp_kernel.json
11-
{
12-
"argv": [
13-
"julia",
14-
"-i",
15-
"--color=yes",
16-
"--project=/home/jovyan/binder",
17-
"{connection_file}"
18-
],
19-
"display_name": "Julia (LineCableModels)",
20-
"language": "julia"
21-
}
22-
EOF
23-
mv temp_kernel.json "${KERNEL_PATH}/kernel.json"
24-
25-
echo "Successfully configured Jupyter kernel to use the binder environment."
4+
# Pre-seed Julia's default environment for this Julia version (e.g. @v1.11)
5+
# and install everything listed in binder/Project.toml (plus your local package).
6+
7+
julia -e '
8+
using Pkg, TOML
9+
10+
# 1) Activate default env for the running Julia version
11+
# (@v#.# expands to ~/.julia/environments/v<major>.<minor>)
12+
Pkg.activate("@v#.#")
13+
14+
# 2) Always dev the local repo (your unregistered package) into the default env
15+
# so `using LineCableModels` works from anywhere.
16+
if isfile("Project.toml")
17+
try
18+
Pkg.develop(path=".")
19+
catch e
20+
@warn "Pkg.develop(path=\".\") failed; check repo root" exception=(e, catch_backtrace())
21+
end
22+
end
23+
24+
# 3) Read declared deps from binder/Project.toml (fallback to root Project.toml)
25+
projfile = isfile("binder/Project.toml") ? "binder/Project.toml" :
26+
(isfile("Project.toml") ? "Project.toml" : nothing)
27+
28+
deps = Dict{String,Any}()
29+
if projfile !== nothing
30+
proj = TOML.parsefile(projfile)
31+
deps = get(proj, "deps", deps)
32+
end
33+
34+
# 4) Add each dependency by name if it is not the local package we just devved.
35+
for name in sort(collect(keys(deps)))
36+
if name == "LineCableModels"
37+
continue
38+
end
39+
try
40+
Pkg.add(name)
41+
catch e
42+
# If this dep exists as a subdir, try dev it; else warn.
43+
if isdir(name)
44+
@info "Pkg.add($name) failed, trying Pkg.develop(path=\"$name\")"
45+
try
46+
Pkg.develop(path=name)
47+
catch e2
48+
@warn "Could not add or dev dependency $name" exception=(e2, catch_backtrace())
49+
end
50+
else
51+
@warn "Could not add dependency $name (not found as a subdir)."
52+
end
53+
end
54+
end
55+
56+
# 5) Precompile the default env so Pluto loads fast
57+
Pkg.precompile()
58+
'

binder/start

100755100644
File mode changed.

0 commit comments

Comments
 (0)