diff --git a/tools/combine_pkg_envs.jl b/tools/combine_pkg_envs.jl index a815994f..91cd9258 100644 --- a/tools/combine_pkg_envs.jl +++ b/tools/combine_pkg_envs.jl @@ -1,8 +1,10 @@ -if !isdir("pluto-deployment-environment") || length(ARGS) != 1 +include("./common.jl") + +if length(ARGS) != 1 error(""" - Run me from the root of the repository directory, using: + Syntax: - julia tools/combine_pkg_envs.jl + julia tools/$(basename(@__FILE__)) Where is true or false to update all packages as well. """) @@ -10,34 +12,6 @@ end update = parse(Bool, ARGS[1]) -import Pkg -Pkg.activate("./pluto-deployment-environment") -Pkg.instantiate() -import Pluto -ENV["JULIA_PKG_PRECOMPILE_AUTO"] = 0 - - - -# Find all notebooks -lectures_dir = joinpath(@__DIR__, "..", "lectures") -prob_prog_dir = joinpath(@__DIR__, "..", "probprog") -minis_dir = joinpath(@__DIR__, "..", "minis") -ignore_dir = joinpath(@__DIR__, "..", "ignore_dir") - -all_notebooks = mapreduce(union, [ - lectures_dir, - prob_prog_dir, - minis_dir, - ignore_dir -]) do d - isdir(d) ? - filter(Pluto.is_pluto_notebook, readdir(d; join=true)) : - String[] -end - - - - "Extract embedded project and manifest contents from each notebook" function extract_toml_contents(notebook_path::String) content = read(notebook_path, String) diff --git a/tools/common.jl b/tools/common.jl new file mode 100644 index 00000000..10260bb2 --- /dev/null +++ b/tools/common.jl @@ -0,0 +1,41 @@ +if !isdir("pluto-deployment-environment") + error(""" + Run me from the root of the repository directory, using: + + julia tools/scriptname.jl argument1 argument2 ... + """) +end + + +begin + import TOML + manifest_version = TOML.parsefile("./pluto-deployment-environment/Manifest.toml")["julia_version"] + + @assert manifest_version == string(VERSION) "This repository uses Julia version $(manifest_version) (in pluto-deployment-environment), but this is Julia $(VERSION). Start a new Julia session with the correct version, or create a new Manifest.toml." +end + +import Pkg +Pkg.activate("./pluto-deployment-environment") +Pkg.instantiate() +import Pluto +ENV["JULIA_PKG_PRECOMPILE_AUTO"] = 0 + +flatmap(args...) = vcat(map(args...)...) + + +# Find all notebooks +lectures_dir = joinpath(@__DIR__, "..", "lectures") +prob_prog_dir = joinpath(@__DIR__, "..", "probprog") +minis_dir = joinpath(@__DIR__, "..", "minis") +ignore_dir = joinpath(@__DIR__, "..", "ignore_dir") + +all_notebooks = mapreduce(union, [ + lectures_dir, + prob_prog_dir, + minis_dir, + ignore_dir +]) do d + isdir(d) ? + filter(Pluto.is_pluto_notebook, readdir(d; join=true)) : + String[] +end diff --git a/tools/find_open_markdown_cells.jl b/tools/find_open_markdown_cells.jl new file mode 100644 index 00000000..7932d3eb --- /dev/null +++ b/tools/find_open_markdown_cells.jl @@ -0,0 +1,21 @@ +include("./common.jl") + + +for path in all_notebooks + @info "🌸 Checking $path" + notebook = Pluto.load_notebook_nobackup(path) + + + old = notebook.topology + new = notebook.topology = Pluto.updated_topology(old, notebook, notebook.cells) + + + for c in notebook.cells + c.code_folded && continue + !Pluto.is_just_text(new, c) && continue + if startswith(strip(c.code), "md") || startswith(strip(c.code), "html") + @error "Markdown cell is not folded" path c.cell_id + end + end + +end diff --git a/tools/generate_pdf.jl b/tools/generate_pdf.jl index dfe498a3..6137be3b 100644 --- a/tools/generate_pdf.jl +++ b/tools/generate_pdf.jl @@ -29,14 +29,12 @@ output_dir = mktempdir(; cleanup=false) @info "Output directory: $(output_dir)" lecture_urls = [ - "TODO You need to update this list", "https://bmlip.github.io/course/lectures/Course%20Syllabus.html", "https://bmlip.github.io/course/lectures/Machine%20Learning%20Overview.html", "https://bmlip.github.io/course/lectures/Probability%20Theory%20Review.html", "https://bmlip.github.io/course/lectures/Bayesian%20Machine%20Learning.html", "https://bmlip.github.io/course/lectures/Factor%20Graphs.html", "https://bmlip.github.io/course/lectures/Density%20Estimation.html", - "https://bmlip.github.io/course/lectures/The%20Multinomial%20Distribution.html", "https://bmlip.github.io/course/lectures/Regression.html", "https://bmlip.github.io/course/lectures/Generative%20Classification.html", "https://bmlip.github.io/course/lectures/Discriminative%20Classification.html", diff --git a/tools/update_notebook_packages.jl b/tools/update_notebook_packages.jl index 5250f070..61685b6a 100644 --- a/tools/update_notebook_packages.jl +++ b/tools/update_notebook_packages.jl @@ -1,4 +1,6 @@ -if !isdir("pluto-deployment-environment") || length(ARGS) != 2 +include("./common.jl") + +if length(ARGS) != 2 error(""" Run me from the root of the repository directory, using: @@ -9,33 +11,14 @@ if !isdir("pluto-deployment-environment") || length(ARGS) != 2 """) end -begin - import TOML - manifest_version = TOML.parsefile("./pluto-deployment-environment/Manifest.toml")["julia_version"] - - @assert manifest_version == string(VERSION) "This repository uses Julia version $(manifest_version) (in pluto-deployment-environment), but this is Julia $(VERSION). Start a new Julia session with the correct version, or create a new Manifest.toml." -end - -import Pkg -Pkg.activate("./pluto-deployment-environment") -Pkg.instantiate() - -import Pluto - -flatmap(args...) = vcat(map(args...)...) +level = getfield(Pkg, Symbol("UPLEVEL_$(ARGS[1])")) +run_notebooks = parse(Bool, ARGS[2]) getfrom(dir) = flatmap(walkdir(dir)) do (root, _dirs, files) joinpath.((root,), files) end -all_files_recursive = [getfrom("lectures")..., getfrom("probprog")..., getfrom("minis")...] - -all_notebooks = filter!(Pluto.is_pluto_notebook, all_files_recursive) - -level = getfield(Pkg, Symbol("UPLEVEL_$(ARGS[1])")) -run_notebooks = parse(Bool, ARGS[2]) - for n in all_notebooks @info "Updating" n ENV["JULIA_PKG_PRECOMPILE_AUTO"] = 0