From 92467fc610fccc0eb119d66caceae7b7fe694dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Galy-Fajou?= Date: Thu, 24 Jun 2021 17:22:58 +0200 Subject: [PATCH 01/10] Use processes to run literate examples --- docs/make.jl | 52 +++++++++++++++++++--------------------------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index d8f083cb3..4335476d7 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -17,44 +17,30 @@ 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() 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) - 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, - ) - end + filepath = joinpath(exampledir, "script.jl") + @show code = """using Literate; Literate.markdown("script.jl", "$(EXAMPLES_OUT)"; name=example, documenter=true, execute=true)""" + run(addenv(`$(cmd) -e $(code)`, Dict("JULIA_LOAD_PATH" => exampledir))) + Literate.notebook( + filepath, + EXAMPLES_OUT; + name=example, + documenter=true, + execute=false, + ) 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, From 138b35ba527dfbf983ee6163d76347a3b79f03de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Galy-Fajou?= Date: Thu, 24 Jun 2021 17:44:50 +0200 Subject: [PATCH 02/10] Working script --- docs/make.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 4335476d7..934183b4f 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -23,8 +23,11 @@ for example in readdir(EXAMPLES_SRC) exampledir = joinpath(EXAMPLES_SRC, example) isdir(exampledir) || continue filepath = joinpath(exampledir, "script.jl") - @show code = """using Literate; Literate.markdown("script.jl", "$(EXAMPLES_OUT)"; name=example, documenter=true, execute=true)""" - run(addenv(`$(cmd) -e $(code)`, Dict("JULIA_LOAD_PATH" => exampledir))) + @show code = """ + using Literate + Literate.markdown("$(filepath)", "$(EXAMPLES_OUT)"; name="$(example)", documenter=true, execute=true) + """ + run(`$(cmd) --project=$(exampledir) -e $(code)`) Literate.notebook( filepath, EXAMPLES_OUT; From 233faaf84c79005bb9b191b0d95551206b8e0470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Galy-Fajou?= Date: Thu, 24 Jun 2021 17:45:38 +0200 Subject: [PATCH 03/10] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- docs/make.jl | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 934183b4f..e4f147c3a 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -28,13 +28,7 @@ for example in readdir(EXAMPLES_SRC) Literate.markdown("$(filepath)", "$(EXAMPLES_OUT)"; name="$(example)", documenter=true, execute=true) """ run(`$(cmd) --project=$(exampledir) -e $(code)`) - Literate.notebook( - filepath, - EXAMPLES_OUT; - name=example, - documenter=true, - execute=false, - ) + Literate.notebook(filepath, EXAMPLES_OUT; name=example, documenter=true, execute=false) end # Pkg.activate(exampledir) do # Pkg.develop(; path=PACKAGE_DIR) @@ -44,7 +38,6 @@ end # filepath, EXAMPLES_OUT; name=example, documenter=true, preprocess=preprocess # ) - DocMeta.setdocmeta!( KernelFunctions, :DocTestSetup, From 0f3ef9dcbdad6eb86b1726728caebe8d694b28d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Galy-Fajou?= Date: Thu, 24 Jun 2021 17:53:37 +0200 Subject: [PATCH 04/10] Add instantiate --- docs/make.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/make.jl b/docs/make.jl index 934183b4f..be97395c3 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -24,6 +24,8 @@ for example in readdir(EXAMPLES_SRC) isdir(exampledir) || continue filepath = joinpath(exampledir, "script.jl") @show code = """ + import Pkg + Pkg.instantiate() using Literate Literate.markdown("$(filepath)", "$(EXAMPLES_OUT)"; name="$(example)", documenter=true, execute=true) """ From ea11792178d00167855592e2ce8a7f7de4762157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Galy-Fajou?= Date: Thu, 24 Jun 2021 18:03:49 +0200 Subject: [PATCH 05/10] Adding environment --- docs/make.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 3eeb992d9..95048be66 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -18,18 +18,20 @@ ispath(EXAMPLES_OUT) && rm(EXAMPLES_OUT; recursive=true) mkpath(EXAMPLES_OUT) cmd = Base.julia_cmd() +docs_env = @__DIR__ for example in readdir(EXAMPLES_SRC) example ∈ BLACKLIST && continue exampledir = joinpath(EXAMPLES_SRC, example) isdir(exampledir) || continue filepath = joinpath(exampledir, "script.jl") - @show code = """ + @show load_path = "$(exampledir):$(docs_env)" + code = """ import Pkg Pkg.instantiate() using Literate Literate.markdown("$(filepath)", "$(EXAMPLES_OUT)"; name="$(example)", documenter=true, execute=true) """ - run(`$(cmd) --project=$(exampledir) -e $(code)`) + run(addenv(`$(cmd) --project=$(exampledir) -e $(code)`, Dict("JULIA_LOAD_PATH" => load_path))) Literate.notebook(filepath, EXAMPLES_OUT; name=example, documenter=true, execute=false) end # Pkg.activate(exampledir) do From 18701b787dc93d60bcfc427f7c5155f2876cadfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Galy-Fajou?= Date: Thu, 24 Jun 2021 18:06:56 +0200 Subject: [PATCH 06/10] Update docs/make.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- docs/make.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 95048be66..532d3ea86 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -31,7 +31,12 @@ for example in readdir(EXAMPLES_SRC) using Literate Literate.markdown("$(filepath)", "$(EXAMPLES_OUT)"; name="$(example)", documenter=true, execute=true) """ - run(addenv(`$(cmd) --project=$(exampledir) -e $(code)`, Dict("JULIA_LOAD_PATH" => load_path))) + run( + addenv( + `$(cmd) --project=$(exampledir) -e $(code)`, + Dict("JULIA_LOAD_PATH" => load_path), + ), + ) Literate.notebook(filepath, EXAMPLES_OUT; name=example, documenter=true, execute=false) end # Pkg.activate(exampledir) do From 76f33519daf9016b0e0898bdeb04164d22b5e8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Galy-Fajou?= Date: Mon, 28 Jun 2021 10:41:40 +0200 Subject: [PATCH 07/10] Use withenv --- docs/make.jl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 532d3ea86..58638dddd 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -31,12 +31,9 @@ for example in readdir(EXAMPLES_SRC) using Literate Literate.markdown("$(filepath)", "$(EXAMPLES_OUT)"; name="$(example)", documenter=true, execute=true) """ - run( - addenv( - `$(cmd) --project=$(exampledir) -e $(code)`, - Dict("JULIA_LOAD_PATH" => load_path), - ), - ) + withenv(Dict("JULIA_LOAD_PATH" => load_path)) do + run(`$(cmd) --project=$(exampledir) -e $(code)`) + end Literate.notebook(filepath, EXAMPLES_OUT; name=example, documenter=true, execute=false) end # Pkg.activate(exampledir) do From 32c079bb8aa8c37eae9504701245960b90e59479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Galy-Fajou?= Date: Mon, 28 Jun 2021 10:42:54 +0200 Subject: [PATCH 08/10] Add notebooks to examples --- docs/make.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 58638dddd..3a2ad31dd 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -30,11 +30,11 @@ for example in readdir(EXAMPLES_SRC) Pkg.instantiate() 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(Dict("JULIA_LOAD_PATH" => load_path)) do run(`$(cmd) --project=$(exampledir) -e $(code)`) end - Literate.notebook(filepath, EXAMPLES_OUT; name=example, documenter=true, execute=false) end # Pkg.activate(exampledir) do # Pkg.develop(; path=PACKAGE_DIR) From 8a04449e409e803ae1a0914dc1793f1891103c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Galy-Fajou?= Date: Mon, 28 Jun 2021 11:42:07 +0200 Subject: [PATCH 09/10] Correct withenv --- docs/make.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 3a2ad31dd..b05da05ca 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -32,7 +32,7 @@ for example in readdir(EXAMPLES_SRC) Literate.markdown("$(filepath)", "$(EXAMPLES_OUT)"; name="$(example)", documenter=true, execute=true) Literate.notebook("$(filepath)", "$(EXAMPLES_OUT)"; name="$(example)", documenter=true, execute=true) """ - withenv(Dict("JULIA_LOAD_PATH" => load_path)) do + withenv(JULIA_LOAD_PATH" => load_path) do run(`$(cmd) --project=$(exampledir) -e $(code)`) end end From a160422cafb3df3f7046829e86f2d4ddc414cb83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Galy-Fajou?= Date: Mon, 28 Jun 2021 11:49:10 +0200 Subject: [PATCH 10/10] Missing character --- docs/make.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index b05da05ca..8ecdb7252 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -32,7 +32,7 @@ for example in readdir(EXAMPLES_SRC) 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 + withenv("JULIA_LOAD_PATH" => load_path) do run(`$(cmd) --project=$(exampledir) -e $(code)`) end end