Skip to content

Commit 338f75b

Browse files
authored
Sunny version check in generated scripts (#335)
1 parent c812245 commit 338f75b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

docs/make.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function build_examples(example_sources, destdir)
2929
for source in example_sources
3030
# Extract "example" from "path/example.jl"
3131
name = splitext(basename(source))[1]
32-
32+
3333
# Preprocess each example by adding a notebook download link at the top. The
3434
# relative path is hardcoded according to the layout of `gh-pages` branch,
3535
# which is set up by `Documenter.deploydocs`.
@@ -47,20 +47,25 @@ function build_examples(example_sources, destdir)
4747
# Create Jupyter notebooks and Julia script for each Literate example. These
4848
# will be stored in the `assets/` directory of the hosted docs.
4949
for source in example_sources
50-
function preprocess(str)
50+
function pp_vcheck(str)
51+
check = "@assert pkgversion(Sunny) >= " * repr(pkgversion(Sunny))
52+
return replace(str, r"^(using.*Sunny.*)$"m => SubstitutionString("\\1\n"*check))
53+
end
54+
function pp_wglmakie(str)
5155
# Ideally, notebooks would use WGLMakie instead of GLMakie, but
5256
# there are currently too many bugs to enable by default:
5357
# https://github.com/SunnySuite/Sunny.jl/issues/211
5458
#=
55-
str = replace(str, r"^using(.*?)GLMakie"m => s"using\1WGLMakie")
59+
return replace(str, r"^using(.*?)GLMakie"m => s"using\1WGLMakie")
5660
=#
57-
str
61+
return str
5862
end
63+
5964
# Build notebooks
60-
Literate.notebook(source, notebooks_path; preprocess, execute=false, credit=false)
65+
Literate.notebook(source, notebooks_path; preprocess=pp_wglmakiepp_vcheck, execute=false, credit=false)
6166

6267
# Build julia scripts
63-
Literate.script(source, scripts_path; credit=false)
68+
Literate.script(source, scripts_path; preprocess=pp_vcheck, credit=false)
6469
end
6570

6671
# Return paths `$destpath/$name.md` for each new Markdown file (relative to

0 commit comments

Comments
 (0)