1- using CalibrationErrors
2- using Literate: Literate
3- using Pkg: Pkg
4-
5- if haskey (ENV , " GITHUB_ACTIONS" )
6- # Print `@debug` statements (https://github.com/JuliaDocs/Documenter.jl/issues/955)
7- ENV [" JULIA_DEBUG" ] = " Documenter"
8- # Bypass the accept download prompt
9- ENV [" DATADEPS_ALWAYS_ACCEPT" ] = " true"
10- end
11-
12- const EXAMPLES = (" classification" , " distribution" )
13- const INPUT = joinpath (@__DIR__ , " .." , " examples" )
14- const OUTPUT = joinpath (@__DIR__ , " src" , " examples" )
15-
16- ispath (OUTPUT) && rm (OUTPUT; recursive= true )
17- mkpath (joinpath (OUTPUT, " figures" ))
18-
19- # Add link to nbviewer below the first heading of level 1
20- function preprocess (content)
21- sub = SubstitutionString (
22- """
23- \\ 0
24- #
25- #md # [](@__NBVIEWER_ROOT_URL__/examples/@__NAME__.ipynb)
26- #md #
27- # You are seeing the
28- #md # HTML output generated by [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl) and
29- #nb # notebook output generated by
30- # [Literate.jl](https://github.com/fredrikekre/Literate.jl) from the
31- # [Julia source file](@__REPO_ROOT_URL__/examples/@__NAME__/script.jl).
32- # The corresponding
33- #md # notebook can be viewed in [nbviewer](@__NBVIEWER_ROOT_URL__/examples/@__NAME__.ipynb).
34- #nb # HTML output can be viewed [here](https://devmotion.github.io/CalibrationErrors.jl/dev/examples/@__NAME__/).
35- #md #
36- #md # ```@setup @__NAME__
37- #md # using Pkg: Pkg
38- #md # Pkg.activate("$(INPUT) /@__NAME__")
39- #md # Pkg.instantiate()
40- #md # ```
41- #
42- """ ,
43- )
44- return replace (content, r" ^# # [^\n ]*" m => sub; count= 1 )
1+ # Always rerun examples
2+ const EXAMPLES_OUT = joinpath (@__DIR__ , " src" , " examples" )
3+ ispath (EXAMPLES_OUT) && rm (EXAMPLES_OUT; recursive= true )
4+ mkpath (EXAMPLES_OUT)
5+
6+ # Run examples asynchronously
7+ const EXAMPLES_SRC = joinpath (@__DIR__ , " .." , " examples" )
8+ const LITERATEJL = joinpath (@__DIR__ , " literate.jl" )
9+ processes = map (filter! (isdir, readdir (EXAMPLES_SRC; join= true ))) do example
10+ scriptjl = joinpath (example, " script.jl" )
11+ return run (
12+ pipeline (
13+ ` $(Base. julia_cmd ()) $LITERATEJL $scriptjl $EXAMPLES_OUT ` ;
14+ stdin = devnull ,
15+ stdout = devnull ,
16+ stderr = stderr ,
17+ );
18+ wait= false ,
19+ ):: Base.Process
4520end
4621
47- for name in EXAMPLES
48- file = joinpath (INPUT, name, " script.jl" )
49-
50- # Activate project environment
51- Pkg. activate (dirname (file)) do
52- Pkg. instantiate ()
53-
54- Literate. markdown (file, OUTPUT; name= name, documenter= true , preprocess= preprocess)
55- Literate. notebook (file, OUTPUT; name= name, documenter= true , preprocess= preprocess)
56- end
57- end
22+ # Check that all examples were run successfully
23+ isempty (processes) || success (processes) || error (" some examples were not run successfully" )
5824
25+ # Build documentation
26+ using CalibrationErrors
5927using Documenter
6028
6129makedocs (;
@@ -74,7 +42,10 @@ makedocs(;
7442 " ece.md" ,
7543 " kce.md" ,
7644 " others.md" ,
77- " Examples" => [joinpath (" examples" , " $(name) .md" ) for name in EXAMPLES],
45+ " Examples" =>
46+ map (filter! (filename -> endswith (filename, " .md" ), readdir (EXAMPLES_OUT))) do x
47+ return joinpath (" examples" , x)
48+ end ,
7849 ],
7950 strict= true ,
8051 checkdocs= :exports ,
0 commit comments