Skip to content

Commit 8fadd74

Browse files
update builder scripts
1 parent ab78a80 commit 8fadd74

File tree

1 file changed

+45
-32
lines changed

1 file changed

+45
-32
lines changed

src/SciMLTutorials.jl

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,56 @@
11
module SciMLTutorials
22

3-
using Weave, Pkg, InteractiveUtils, IJulia
3+
using Weave, Pkg, IJulia, InteractiveUtils, Markdown
44

55
repo_directory = joinpath(@__DIR__,"..")
66
cssfile = joinpath(@__DIR__, "..", "templates", "skeleton_css.css")
77
latexfile = joinpath(@__DIR__, "..", "templates", "julia_tex.tpl")
88

9-
function weave_file(folder,file,build_list=(:script,:html,:pdf,:github,:notebook); kwargs...)
10-
tmp = joinpath(repo_directory,"tutorials",folder,file)
11-
Pkg.activate(dirname(tmp))
12-
Pkg.instantiate()
9+
function weave_file(folder,file,build_list=(:script,:html,:pdf,:github,:notebook))
10+
target = joinpath(folder, file)
11+
@info("Weaving $(target)")
12+
13+
if isfile(joinpath(folder, "Project.toml"))
14+
@info("Instantiating", folder)
15+
Pkg.activate(folder)
16+
Pkg.instantiate()
17+
Pkg.build()
18+
end
19+
1320
args = Dict{Symbol,String}(:folder=>folder,:file=>file)
1421
if :script build_list
1522
println("Building Script")
16-
dir = joinpath(repo_directory,"script",folder)
23+
dir = joinpath(repo_directory,"script",basename(folder))
1724
mkpath(dir)
18-
args[:doctype] = "script"
19-
tangle(tmp;out_path=dir)
25+
tangle(target; out_path=dir)
2026
end
2127
if :html build_list
2228
println("Building HTML")
23-
dir = joinpath(repo_directory,"html",folder)
29+
dir = joinpath(repo_directory,"html",basename(folder))
2430
mkpath(dir)
25-
args[:doctype] = "html"
26-
weave(tmp,doctype = "md2html",out_path=dir,args=args; fig_ext=".svg", css=cssfile, kwargs...)
31+
weave(target,doctype = "md2html",out_path=dir,args=args,css=cssfile,fig_ext=".svg")
2732
end
2833
if :pdf build_list
2934
println("Building PDF")
30-
dir = joinpath(repo_directory,"pdf",folder)
35+
dir = joinpath(repo_directory,"pdf",basename(folder))
3136
mkpath(dir)
32-
args[:doctype] = "pdf"
3337
try
34-
weave(tmp,doctype="md2pdf",out_path=dir,args=args; template=latexfile, kwargs...)
38+
weave(target,doctype="md2pdf",out_path=dir,template=latexfile,args=args)
3539
catch ex
3640
@warn "PDF generation failed" exception=(ex, catch_backtrace())
3741
end
3842
end
3943
if :github build_list
4044
println("Building Github Markdown")
41-
dir = joinpath(repo_directory,"markdown",folder)
45+
dir = joinpath(repo_directory,"markdown",basename(folder))
4246
mkpath(dir)
43-
args[:doctype] = "github"
44-
weave(tmp,doctype = "github",out_path=dir,args=args; kwargs...)
47+
weave(target,doctype = "github",out_path=dir,args=args)
4548
end
4649
if :notebook build_list
4750
println("Building Notebook")
48-
dir = joinpath(repo_directory,"notebook",folder)
51+
dir = joinpath(repo_directory,"notebook",basename(folder))
4952
mkpath(dir)
50-
args[:doctype] = "notebook"
51-
Weave.convert_doc(tmp,joinpath(dir,file[1:end-4]*".ipynb"))
53+
Weave.convert_doc(target,joinpath(dir,file[1:end-4]*".ipynb"))
5254
end
5355
end
5456

@@ -60,38 +62,49 @@ function weave_all()
6062
end
6163

6264
function weave_folder(folder)
63-
for file in readdir(joinpath(repo_directory,"tutorials",folder))
64-
println("Building $(joinpath(folder,file)))")
65+
for file in readdir(folder)
66+
# Skip non-`.jmd` files
67+
if !endswith(file, ".jmd")
68+
continue
69+
end
70+
6571
try
6672
weave_file(folder,file)
67-
catch
73+
catch e
74+
@error(e)
6875
end
6976
end
7077
end
7178

72-
function tutorial_footer(folder=nothing, file=nothing; remove_homedir=true)
73-
display("text/markdown", """
79+
function tutorial_footer(folder=nothing, file=nothing)
80+
display(md"""
7481
## Appendix
7582
76-
This tutorial is part of the SciMLTutorials.jl repository, found at: <https://github.com/SciML/SciMLTutorials.jl>.
77-
For more information on doing scientific machine learning (SciML) with open source software, check out <https://sciml.ai/>.
83+
These tutorials are a part of the SciMLTutorials.jl repository, found at: <https://github.com/SciML/SciMLTutorials.jl>.
84+
For more information on high-performance scientific machine learning, check out the SciML Open Source Software Organization <https://sciml.ai>.
85+
7886
""")
7987
if folder !== nothing && file !== nothing
80-
display("text/markdown", """
88+
display(Markdown.parse("""
8189
To locally run this tutorial, do the following commands:
8290
```
8391
using SciMLTutorials
8492
SciMLTutorials.weave_file("$folder","$file")
8593
```
86-
""")
94+
"""))
8795
end
88-
display("text/markdown", "Computer Information:")
96+
display(md"Computer Information:")
8997
vinfo = sprint(InteractiveUtils.versioninfo)
90-
display("text/markdown", """
98+
display(Markdown.parse("""
9199
```
92100
$(vinfo)
93101
```
102+
"""))
103+
104+
display(md"""
105+
Package Information:
94106
""")
107+
95108
proj = sprint(io -> Pkg.status(io=io))
96109
mani = sprint(io -> Pkg.status(io=io, mode = Pkg.PKGMODE_MANIFEST))
97110

@@ -106,7 +119,7 @@ function tutorial_footer(folder=nothing, file=nothing; remove_homedir=true)
106119
$(chomp(mani))
107120
```
108121
"""
109-
display("text/markdown", md)
122+
display(Markdown.parse(md))
110123
end
111124

112125
function open_notebooks()

0 commit comments

Comments
 (0)