diff --git a/docs/make.jl b/docs/make.jl index d8f083cb3..8ecdb7252 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -17,44 +17,32 @@ const BLACKLIST = ["deep-kernel-learning", "support-vector-machine"] ispath(EXAMPLES_OUT) && rm(EXAMPLES_OUT; recursive=true) mkpath(EXAMPLES_OUT) -# preprocessor for Literate example scripts: -# - add Documenter @setup snippet that activates each example's own project environment -function preprocess(content) - sub = SubstitutionString(""" - \\0 - # - #md # - #md # ```@setup @__NAME__ - #md # using Pkg: Pkg - #md # Pkg.activate("$(EXAMPLES_SRC)/@__NAME__") - #md # Pkg.instantiate() - #md # ``` - # - """) - return replace(content, r"^# # [^\n]*"m => sub; count=1) -end - +cmd = Base.julia_cmd() +docs_env = @__DIR__ for example in readdir(EXAMPLES_SRC) example ∈ BLACKLIST && continue exampledir = joinpath(EXAMPLES_SRC, example) isdir(exampledir) || continue - Pkg.activate(exampledir) do - Pkg.develop(; path=PACKAGE_DIR) + filepath = joinpath(exampledir, "script.jl") + @show load_path = "$(exampledir):$(docs_env)" + code = """ + import Pkg Pkg.instantiate() - filepath = joinpath(exampledir, "script.jl") - Literate.markdown( - filepath, EXAMPLES_OUT; name=example, documenter=true, preprocess=preprocess - ) - Literate.notebook( - filepath, - EXAMPLES_OUT; - name=example, - documenter=true, - preprocess=preprocess, - execute=false, - ) + using Literate + Literate.markdown("$(filepath)", "$(EXAMPLES_OUT)"; name="$(example)", documenter=true, execute=true) + Literate.notebook("$(filepath)", "$(EXAMPLES_OUT)"; name="$(example)", documenter=true, execute=true) + """ + withenv("JULIA_LOAD_PATH" => load_path) do + run(`$(cmd) --project=$(exampledir) -e $(code)`) end end +# Pkg.activate(exampledir) do +# Pkg.develop(; path=PACKAGE_DIR) +# Pkg.instantiate() +# filepath = joinpath(exampledir, "script.jl") +# Literate.markdown( +# filepath, EXAMPLES_OUT; name=example, documenter=true, preprocess=preprocess +# ) DocMeta.setdocmeta!( KernelFunctions,