1
1
module SciMLTutorials
2
2
3
- using Weave, Pkg, InteractiveUtils, IJulia
3
+ using Weave, Pkg, IJulia, InteractiveUtils, Markdown
4
4
5
5
repo_directory = joinpath (@__DIR__ ," .." )
6
6
cssfile = joinpath (@__DIR__ , " .." , " templates" , " skeleton_css.css" )
7
7
latexfile = joinpath (@__DIR__ , " .." , " templates" , " julia_tex.tpl" )
8
8
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
+
13
20
args = Dict {Symbol,String} (:folder => folder,:file => file)
14
21
if :script ∈ build_list
15
22
println (" Building Script" )
16
- dir = joinpath (repo_directory," script" ,folder)
23
+ dir = joinpath (repo_directory," script" ,basename ( folder) )
17
24
mkpath (dir)
18
- args[:doctype ] = " script"
19
- tangle (tmp;out_path= dir)
25
+ tangle (target; out_path= dir)
20
26
end
21
27
if :html ∈ build_list
22
28
println (" Building HTML" )
23
- dir = joinpath (repo_directory," html" ,folder)
29
+ dir = joinpath (repo_directory," html" ,basename ( folder) )
24
30
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" )
27
32
end
28
33
if :pdf ∈ build_list
29
34
println (" Building PDF" )
30
- dir = joinpath (repo_directory," pdf" ,folder)
35
+ dir = joinpath (repo_directory," pdf" ,basename ( folder) )
31
36
mkpath (dir)
32
- args[:doctype ] = " pdf"
33
37
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 )
35
39
catch ex
36
40
@warn " PDF generation failed" exception= (ex, catch_backtrace ())
37
41
end
38
42
end
39
43
if :github ∈ build_list
40
44
println (" Building Github Markdown" )
41
- dir = joinpath (repo_directory," markdown" ,folder)
45
+ dir = joinpath (repo_directory," markdown" ,basename ( folder) )
42
46
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)
45
48
end
46
49
if :notebook ∈ build_list
47
50
println (" Building Notebook" )
48
- dir = joinpath (repo_directory," notebook" ,folder)
51
+ dir = joinpath (repo_directory," notebook" ,basename ( folder) )
49
52
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" ))
52
54
end
53
55
end
54
56
@@ -60,38 +62,49 @@ function weave_all()
60
62
end
61
63
62
64
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
+
65
71
try
66
72
weave_file (folder,file)
67
- catch
73
+ catch e
74
+ @error (e)
68
75
end
69
76
end
70
77
end
71
78
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 """
74
81
## Appendix
75
82
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
+
78
86
""" )
79
87
if folder != = nothing && file != = nothing
80
- display (" text/markdown " , """
88
+ display (Markdown . parse ( """
81
89
To locally run this tutorial, do the following commands:
82
90
```
83
91
using SciMLTutorials
84
92
SciMLTutorials.weave_file("$folder ","$file ")
85
93
```
86
- """ )
94
+ """ ))
87
95
end
88
- display (" text/markdown " , " Computer Information:" )
96
+ display (md " Computer Information:" )
89
97
vinfo = sprint (InteractiveUtils. versioninfo)
90
- display (" text/markdown " , """
98
+ display (Markdown . parse ( """
91
99
```
92
100
$(vinfo)
93
101
```
102
+ """ ))
103
+
104
+ display (md """
105
+ Package Information:
94
106
""" )
107
+
95
108
proj = sprint (io -> Pkg. status (io= io))
96
109
mani = sprint (io -> Pkg. status (io= io, mode = Pkg. PKGMODE_MANIFEST))
97
110
@@ -106,7 +119,7 @@ function tutorial_footer(folder=nothing, file=nothing; remove_homedir=true)
106
119
$(chomp (mani))
107
120
```
108
121
"""
109
- display (" text/markdown " , md )
122
+ display (Markdown . parse (md) )
110
123
end
111
124
112
125
function open_notebooks ()
0 commit comments