Skip to content

Commit ae213d1

Browse files
committed
Generate badges with versions from Pkg.status
1 parent c3ba3ba commit ae213d1

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ authors = ["Abel Soares Siqueira <[email protected]>"]
44
version = "0.2.0"
55

66
[deps]
7+
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
78
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
89
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
910
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
@@ -13,6 +14,6 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
1314

1415
[compat]
1516
IJulia = "1"
16-
YAML = "0.4"
1717
Weave = "0.10"
18+
YAML = "0.4"
1819
julia = "1.6"

src/JSOTutorials.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module JSOTutorials
22

33
# We copied SciML/SciMLTutorials.jl here
44

5+
include("pkg_list.jl")
6+
57
using Weave, Pkg, IJulia, InteractiveUtils, Markdown, YAML
68

79
repo_directory = joinpath(@__DIR__, "..")
@@ -52,6 +54,7 @@ function weave_file(folder, file, build_list = default_builds)
5254
dir = joinpath(repo_directory, "markdown", basename(folder))
5355
mkpath(dir)
5456
weave(target, doctype = "github", out_path = dir, args = args)
57+
add_package_info(joinpath(dir, file[1:end-4] * ".md"))
5558
end
5659
if :notebook build_list
5760
println("Building Notebook")
@@ -83,6 +86,51 @@ function weave_folder(folder, build_list = default_builds)
8386
end
8487
end
8588

89+
function package_information()
90+
proj = sprint(io -> Pkg.status(io = io))
91+
re_str = r"\[[0-f]+\]\s+(.*) v(.*)"
92+
pkg_info = Dict{String,String}()
93+
for line in split(proj, "\n")
94+
m = match(re_str, line)
95+
if m !== nothing
96+
pkg_info[m[1]] = m[2]
97+
end
98+
end
99+
return pkg_info
100+
end
101+
102+
function badge(name, version)
103+
color, lbl_color = if name in jso_pkgs
104+
color_of_pkg(name)
105+
else
106+
"000", "fff"
107+
end
108+
109+
badge_img = "<img class=\"badge\" src=\"https://img.shields.io/badge/$name-$version-$color?style=flat-square&labelColor=$lbl_color\">"
110+
if name in jso_pkgs
111+
link = "https://juliasmoothoptimizers.github.io/$name.jl/stable/"
112+
"<a href=\"$link\">$badge_img</a>"
113+
else
114+
badge_img
115+
end
116+
end
117+
118+
function add_package_info(filename)
119+
lines = readlines(filename)
120+
j = findall(lines .== "---")[2]
121+
pkg_info = package_information()
122+
out = [
123+
lines[1:j];
124+
"";
125+
[badge(pkg, ver) for (pkg, ver) in pkg_info];
126+
"";
127+
lines[j+1:end]
128+
]
129+
open(filename, "w") do io
130+
print(io, join(out, "\n"))
131+
end
132+
end
133+
86134
function tutorial_footer(folder = nothing, file = nothing)
87135
display(
88136
md"""

src/pkg_list.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Colors
2+
3+
const model_pkgs = ["ADNLPModels", "AmplNLReader", "BundleAdjustmentModels", "CUTEst", "LLSModels", "ManualNLPModels", "NLPModels", "NLPModelsJuMP", "NLPModelsModifiers", "NLPModelsTest", "NLSProblems", "OptimizationProblems", "PDENLPModels", "QuadraticModels", "QPSReader"]
4+
const solver_pkgs = ["BenchmarkProfiles", "CaNNOLeS", "DCISolver", "JSOSolvers", "NLPModelsIpopt", "NLPModelsKnitro", "Percival", "RipQP", "SolverCore", "SolverTest", "SolverTools", "SolverBenchmark"]
5+
const la_pkgs = ["AMD", "BasicLU", "HSL", "Krylov", "LDLFactorizations", "LimitedLDLFactorizations", "LinearOperators", "PROPACK", "MUMPS", "QRMumps", "SparseMatricesCOO", "SuiteSparseMatrixCollection"]
6+
const jso_pkgs = model_pkgs solver_pkgs la_pkgs
7+
8+
const colors = [
9+
("8b0000", "cb3c33"), # Red for models
10+
("006400", "389826"), # Green for solvers
11+
("4b0082", "9558b2"), # Purple for linear algebra
12+
("fff", "000"),
13+
]
14+
15+
color_of_pkg(pkg) = if pkg in model_pkgs
16+
colors[1]
17+
elseif pkg in solver_pkgs
18+
colors[2]
19+
elseif pkg in la_pkgs
20+
colors[3]
21+
else
22+
colors[4]
23+
end

tutorials/introduction-to-linear-operators/index.jmd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ tags: ["linear-algebra", "linear-operators"]
44
author: "Geoffroy Leconte and Dominique Orban"
55
---
66

7-
[LinearOperators.jl](https://juliasmoothoptimizers.github.io/LinearOperators.jl/stable) is a package for matrix-like operators. Linear operators are defined by how they act on a vector, which is useful in a variety of situations where you don't want to materialize the matrix.
7+
[LinearOperators.jl](https://juliasmoothoptimizers.github.io/LinearOperators.jl/stable) is a package for matrix-like operators.
8+
Linear operators are defined by how they act on a vector, which is useful in a variety of situations where you don't want to materialize the matrix.
89

910
\toc
1011

@@ -264,5 +265,3 @@ opA[:,1] * ones(1)
264265
```julia
265266
opA[1,1] * ones(1)
266267
```
267-
268-

0 commit comments

Comments
 (0)