Skip to content

Commit cdd9630

Browse files
committed
Automatically generate badges from using commands in file
1 parent 707036c commit cdd9630

File tree

6 files changed

+43
-34
lines changed

6 files changed

+43
-34
lines changed

config.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@ For instance:
2727
* \newcommand{\phrase}{This is a long phrase to copy.}
2828
-->
2929
\newcommand{\R}{\mathbb R}
30-
\newcommand{\scal}[1]{\langle #1 \rangle}
30+
\newcommand{\scal}[1]{\langle #1 \rangle}
31+
\newcommand{\preamble}[1]{
32+
# {{ title }}
33+
34+
@@author
35+
by #1
36+
@@
37+
38+
{{ list_versions }}
39+
}

pages/how-to/create-a-manual-model.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
@def showall = true
33
@def tags = ["solvers", "NLPModels", "ManualNLPModels"]
44

5-
# {{title}}
6-
7-
@@author
8-
by Abel S. Siqueira
9-
@@
5+
\preamble{Abel S. Siqueira}
106

117
\literate{/_literate/how-to/create-a-manual-model.jl}

pages/how-to/solve-an-optimization-problem-with-ipopt.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
@def showall = true
33
@def tags = ["solvers", "NLPModelsIpopt", "ADNLPModels", "NLPModelsJuMP"]
44

5-
# {{title}}
6-
7-
@@author
8-
by Abel S. Siqueira
9-
@@
10-
11-
{{ list_versions ADNLPModels NLPModelsIpopt NLPModelsJuMP }}
5+
\preamble{Abel S. Siqueira}
126

137
\literate{/_literate/how-to/solve-an-optimization-problem-with-ipopt.jl}
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
@def title = "Creating a JSO-compliant solver"
22
@def showall = true
3-
@def tags = ["models", "solvers", "NLPModels", "SolverCore", "ADNLPModels", "JSOSolvers", "SolverBenchmark"]
3+
@def tags = ["models", "solvers", "NLPModels", "SolverCore", "SolverBenchmark"]
44

5-
# {{title}}
6-
7-
@@author
8-
by Abel S. Siqueira and João Okimoto
9-
@@
10-
11-
{{ list_versions ADNLPModels JSOSolvers LinearAlgebra NLPModels Plots SolverBenchmark SolverCore }}
5+
\preamble{Abel S. Siqueira and João Okimoto}
126

137
\literate{/_literate/tutorials/creating-a-jso-compliant-solver.jl}

pages/tutorials/introduction-to-linear-operators.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
@def showall = true
33
@def tags = ["linear-algebra", "LinearOperators"]
44

5-
# {{title}}
6-
7-
@@author
8-
by Geoffroy Leconte and Dominique Orban
9-
@@
10-
11-
{{ list_versions LinearOperators FFTW}}
5+
\preamble{Geoffroy Leconte and Dominique Orban}
126

137
\literate{/_literate/tutorials/introduction-to-linear-operators.jl}

utils.jl

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
11
using Pkg, Markdown
22

3-
const jso_pkgs = ["ADNLPModels", "JSOSolvers", "LinearOperators", "NLPModels", "NLPModelsIpopt", "NLPModelsJuMP", "SolverBenchmark", "SolverCore", "SolverTools"]
3+
function installed()
4+
deps = Pkg.dependencies()
5+
installs = Dict{String, Any}()
6+
for (_, dep) in deps
7+
dep.is_direct_dep || continue
8+
installs[dep.name] = dep.version
9+
end
10+
return installs
11+
end
12+
13+
const jso_pkgs = ["ADNLPModels", "JSOSolvers", "LinearOperators", "ManualNLPModels", "NLPModels", "NLPModelsIpopt", "NLPModelsJuMP", "SolverBenchmark", "SolverCore", "SolverTools"]
414

515
function badge(name, version)
616
color, lbl_color = if name in jso_pkgs
717
h = div(360 * findfirst(name .== jso_pkgs), length(jso_pkgs))
818
"hsl($h,100%25,30%25)", "hsl($h,30%25,30%25)"
9-
else
19+
elseif version == "STDLIB"
1020
"666", "444"
21+
else
22+
"666", "999"
1123
end
1224

1325
"<img class=\"badge\" src=\"https://img.shields.io/badge/$name-$version-$color?style=flat-square&labelColor=$lbl_color\">"
1426
end
1527

16-
function hfun_list_versions(pkgs)
17-
dict = Pkg.installed()
28+
function hfun_list_versions()
29+
lt_file = "_literate" * locvar("fd_rpath")[6:end-2] * "jl"
30+
lines = readlines(lt_file)
31+
pkgs = String[]
32+
for line in lines
33+
if match(r"^using", line) !== nothing
34+
sline = split(line[7:end], ", ")
35+
append!(pkgs, sline)
36+
end
37+
end
38+
pkgs = unique(sort(pkgs))
39+
dict = installed()
1840
out = ""
1941
for pkg in pkgs
2042
if haskey(dict, pkg)
2143
out *= badge(pkg, dict[pkg]) * "\n"
22-
else
23-
out *= badge(pkg, "stdlib") * "\n"
44+
elseif pkg in readdir(Base.Sys.STDLIB)
45+
out *= badge(pkg, "STDLIB") * "\n"
2446
end
2547
end
2648
out

0 commit comments

Comments
 (0)