Skip to content

Commit be24711

Browse files
committed
Run examples in separate processes (#107)
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
1 parent 7f8f1a9 commit be24711

13 files changed

Lines changed: 206 additions & 137 deletions

File tree

.github/workflows/CompatHelper.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,32 @@ name: CompatHelper
22

33
on:
44
schedule:
5-
- cron: '00 00 * * *'
5+
- cron: 0 0 * * *
66
workflow_dispatch:
77

88
jobs:
99
CompatHelper:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- name: Pkg.add("CompatHelper")
13-
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
14-
- name: CompatHelper.main()
12+
- name: "Install CompatHelper"
13+
run: |
14+
import Pkg
15+
name = "CompatHelper"
16+
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
17+
version = "2"
18+
Pkg.add(; name, uuid, version)
19+
shell: julia --color=yes {0}
20+
- name: "Run CompatHelper"
21+
run: |
22+
import CompatHelper
23+
subdirs = ["", "test", "docs"]
24+
for f in readdir(joinpath(@__DIR__, "examples"); join=true)
25+
if isdir(f)
26+
push!(subdirs, joinpath("examples", basename(f)))
27+
end
28+
end
29+
CompatHelper.main(; subdirs=subdirs)
30+
shell: julia --color=yes {0}
1531
env:
1632
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17-
COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }}
18-
run: julia -e 'using CompatHelper; CompatHelper.main(; subdirs = ["", "docs", "test", "examples/classification", "examples/distribution"])'
33+
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}

.github/workflows/Docs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ jobs:
3636
doctest(CalibrationErrors)'
3737
- run: julia --project=docs docs/make.jl
3838
env:
39+
DATADEPS_ALWAYS_ACCEPT: true # Bypass the accept download prompt
3940
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
JULIA_DEBUG: Documenter # Print `@debug` statements (https://github.com/JuliaDocs/Documenter.jl/issues/955)
4042
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

docs/Manifest.toml

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/Project.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
[deps]
22
CalibrationErrors = "33913031-fe46-5864-950f-100836f47845"
33
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
4-
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
5-
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
64

75
[compat]
86
CalibrationErrors = "0.5.13"
97
Documenter = "0.27"
10-
Literate = "2.7"
118
julia = "1.5"

docs/literate.jl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Retrieve filename of literate script
2+
if length(ARGS) != 2
3+
error("please specify the literate script and the output directory")
4+
end
5+
const SCRIPTJL = ARGS[1]
6+
const OUTDIR = ARGS[2]
7+
8+
# Activate environment
9+
using Pkg: Pkg
10+
Pkg.activate(dirname(SCRIPTJL))
11+
Pkg.instantiate()
12+
using Literate: Literate
13+
14+
# Add link to nbviewer below the first heading of level 1
15+
function preprocess(content)
16+
sub = SubstitutionString(
17+
"""
18+
#md # ```@meta
19+
#md # EditURL = "@__REPO_ROOT_URL__/examples/@__NAME__/script.jl"
20+
#md # ```
21+
#md #
22+
\\0
23+
#
24+
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/examples/@__NAME__.ipynb)
25+
#md #
26+
# *You are seeing the
27+
#md # HTML output generated by [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl) and
28+
#nb # notebook output generated by
29+
# [Literate.jl](https://github.com/fredrikekre/Literate.jl) from the
30+
# [Julia source file](@__REPO_ROOT_URL__/examples/@__NAME__/script.jl).
31+
# The corresponding
32+
#md # notebook can be viewed in [nbviewer](@__NBVIEWER_ROOT_URL__/examples/@__NAME__.ipynb).*
33+
#nb # HTML output can be viewed [here](https://devmotion.github.io/CalibrationErrors.jl/dev/examples/@__NAME__/).*
34+
#
35+
""",
36+
)
37+
return replace(content, r"^# # [^\n]*"m => sub; count=1)
38+
end
39+
40+
# Convert to markdown and notebook
41+
Literate.markdown(
42+
SCRIPTJL,
43+
OUTDIR;
44+
name=basename(dirname(SCRIPTJL)),
45+
documenter=false,
46+
execute=true,
47+
preprocess=preprocess,
48+
)
49+
Literate.notebook(
50+
SCRIPTJL,
51+
OUTDIR;
52+
name=basename(dirname(SCRIPTJL)),
53+
documenter=false,
54+
execute=true,
55+
preprocess=preprocess,
56+
)

docs/make.jl

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,29 @@
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 # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__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
4520
end
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
5927
using Documenter
6028

6129
makedocs(;
@@ -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,

docs/src/introduction.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ target with absolute certainty) or caused by insufficient knowledge of the
1010
underlying relation between feature and target (e.g., if only a small number
1111
of observations of features and corresponding targets are available).[^1]
1212

13-
The following plot shows measurements of the bill length and the flipper length
14-
for three different penguin species in the
15-
[Palmer penguins dataset](https://github.com/allisonhorst/palmerpenguins).
16-
17-
![](./examples/figures/penguins.svg)
18-
19-
There exist many different probabilistic predictive models for predicting the
20-
probability of the penguin species (*target*) given the bill and flipper length
21-
(*feature*). We denote the feature by $X$ and the target by $Y$, and let
13+
In the [classification example](../examples/classification) we study the
14+
[Palmer penguins dataset](https://github.com/allisonhorst/palmerpenguins) with
15+
measurements of three different penguin species and consider the task of predictin
16+
the probability of a penguin species (*target*) given the bill and flipper length
17+
(*feature*). For this classification task there exist many different probabilistic
18+
predictive models. We denote the feature by $X$ and the target by $Y$, and let
2219
$P_X$ be the prediction of a specific model $P$ for a feature $X$. Ideally, we would
2320
like that
2421
```math

examples/classification/Manifest.toml

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
[deps]
2+
AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67"
23
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
34
CalibrationErrors = "33913031-fe46-5864-950f-100836f47845"
45
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
56
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
7+
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
68
PalmerPenguins = "8b842266-38fa-440a-9b57-31493939ab85"
79
Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1"
810

911
[compat]
12+
AlgebraOfGraphics = "0.4"
1013
CairoMakie = "0.6"
1114
CalibrationErrors = "0.5.13"
1215
DataFrames = "0.22.5, 1.0"
1316
Distributions = "0.24.15, 0.25"
17+
Literate = "2.8"
1418
PalmerPenguins = "0.1.2"
1519
Query = "1.0"
1620
julia = "1.3"

0 commit comments

Comments
 (0)