Skip to content

Commit

Permalink
strip SVG in ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
sosiristseng committed Oct 21, 2024
1 parent d41abe1 commit 77f55e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
key: ${{ steps.cache-julia.outputs.cache-primary-key }}
- name: Run notebooks
if: ${{ steps.cache-nb.outputs.cache-hit != 'true' }}
run: julia --project=@. --color=yes -p ${{ env.LITERATE_PROC }} run.jl
run: julia --project=@. --color=yes -p ${{ env.LITERATE_PROC }} ci.jl
- name: Copy back built notebooks
run: cp --verbose -rf ${{ env.NBCACHE }}/docs/* docs/
- name: Build website
Expand Down
14 changes: 9 additions & 5 deletions run.jl → ci.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function main(;

(; ipynbs, litnbs) = list_notebooks(basedir, cachedir)

if length(litnbs) > 0
if !isempty(litnbs)
# Execute literate notebooks in worker process(es)
ts_lit = pmap(litnbs; on_error=ex -> NaN) do nb
@elapsed run_literate(nb, cachedir; rmsvg)
Expand All @@ -120,7 +120,7 @@ function main(;
ts_lit = []
end

if length(ipynbs) > 0
if !isempty(ipynbs)
# Install IJulia kernel
IJulia.installkernel("Julia", "--project=@.", "--heap-size-hint=4G")

Expand All @@ -129,11 +129,15 @@ function main(;
kernelname = "--ExecutePreprocessor.kernel_name=julia-1.$(VERSION.minor)"
execute = ifelse(get(ENV, "ALLOWERRORS", " ") == "true", "--execute --allow-errors", "--execute")
timeout = "--ExecutePreprocessor.timeout=" * get(ENV, "TIMEOUT", "-1")
cmds = [`jupyter nbconvert --to notebook $(execute) $(timeout) $(kernelname) --output $(joinpath(abspath(pwd()), cachedir, nb)) $(nb)` for nb in ipynbs]

# Run the nbconvert commands in parallel
ts_ipynb = asyncmap(cmds; ntasks) do cmd
@elapsed run(cmd)
ts_ipynb = asyncmap(ipynbs; ntasks) do nb
@elapsed begin
nbout = joinpath(abspath(pwd()), cachedir, nb)
cmd = `jupyter nbconvert --to notebook $(execute) $(timeout) $(kernelname) --output $(nbout) $(nb)`
run(cmd)
rmsvg && strip_svg(nbout)
end
end
else
ts_ipynb = []
Expand Down

0 comments on commit 77f55e5

Please sign in to comment.