1- # oneliner fast build PLOTDOCS_PACKAGES='UnicodePlots' PLOTDOCS_EXAMPLES=1 julia --project make.jl
1+ # oneliner fast build PLOTDOCS_SUFFIX='' PLOTDOCS_PACKAGES='UnicodePlots' PLOTDOCS_EXAMPLES='1' julia --project make.jl
22import Pkg; Pkg. precompile()
33
44using Plots, RecipesBase, RecipesPipeline
@@ -23,7 +23,7 @@ const SRC_DIR = joinpath(@__DIR__, "src")
2323const BLD_DIR = joinpath(@__DIR__, " build" * suffix)
2424const WORK_DIR = joinpath(@__DIR__, " work" * suffix)
2525const GEN_DIR = joinpath(WORK_DIR, " generated" )
26- const BRANCH = (" master" , " v2" )[2 ] # transition to v2
26+ const BRANCH = (" master" , " v2" )[1 ] # transition to v2
2727
2828const ATTRIBUTE_SEARCH = Dict{String, Any}() # search terms
2929
@@ -102,7 +102,7 @@ function generate_cards(
102102 )
103103 @show backend
104104 # create folder: for each backend we generate a DemoSection "generated" under "gallery"
105- cards_path = let dn = joinpath(prefix, " $ backend" , " generated" )
105+ cards_path = let dn = joinpath(prefix, string( backend) , " generated" * suffix )
106106 isdir(dn) && rm(dn; recursive = true )
107107 mkpath(dn)
108108 end
@@ -111,32 +111,40 @@ function generate_cards(
111111 needs_rng_fix = Dict{Int, Bool}()
112112
113113 for (i, example) in enumerate(Plots. _examples)
114+ i ∈ skip && continue
114115 (slice ≢ nothing && i ∉ slice) && continue
115116 # write out the header, description, code block, and image link
116117 jlname = " $backend -$(Plots. ref_name(i)) .jl"
117118 jl = PipeBuffer()
119+
120+ # DemoCards YAML frontmatter
121+ # https://johnnychen94.github.io/DemoCards.jl/stable/quickstart/usage_example/julia_demos/1.julia_demo/#juliademocard_example
122+ asset_name = " $(backend) _$(Plots. ref_name(i)) "
123+ asset_path = asset_name * if i ∈ Plots. _animation_examples
124+ " .gif"
125+ elseif backend ∈ (:gr, :pythonplot, :gaston)
126+ " .svg"
127+ else
128+ " .png"
129+ end
130+ extra = if backend ≡ :unicodeplots
131+ " import FileIO, FreeType #hide" # weak deps for png export
132+ else
133+ " "
134+ end
135+
118136 if ! isempty(example. header)
119137 push!(sec_config[" order" ], jlname)
120138 # start a new demo file
121139 @debug " generate demo \" $(example. header) \" - writing `$jlname `"
122140
123- # DemoCards YAML frontmatter
124- # https://johnnychen94.github.io/DemoCards.jl/stable/quickstart/usage_example/julia_demos/1.julia_demo/#juliademocard_example
125- asset = if i ∈ Plots. _animation_examples
126- " anim_$(backend) _$(Plots. ref_name(i)) .gif"
127- else
128- " $(backend) _$(Plots. ref_name(i)) .png"
129- end
130- extra = if backend ≡ :unicodeplots
131- " import FileIO, FreeType #hide" # weak deps for png export
132- else
133- " "
134- end
141+
135142 write(
136143 jl, """
137144 # ---
138145 # title: $(example. header)
139- # id: $(backend) _$(Plots. ref_name(i)) $(i ∈ skip ? " " : " \n # cover: assets/$asset " )
146+ # id: $asset_name
147+ # cover: $asset_path
140148 # author: "$(author()) "
141149 # description: ""
142150 # date: $(Dates. now())
@@ -145,12 +153,7 @@ function generate_cards(
145153 using Plots
146154 $backend ()
147155 $extra
148- """
149- )
150156
151- i ∈ skip && @goto write_file
152- write(
153- jl, """
154157 Plots.reset_defaults() #hide
155158 using StableRNGs #hide
156159 rng = StableRNG($(Plots. PLOTS_SEED) ) #hide
@@ -168,35 +171,30 @@ function generate_cards(
168171 # from the docs: """
169172 # #src and #hide are quite similar. The only difference is that #src lines are filtered out before execution (if execute=true) and #hide lines are filtered out after execution.
170173 # """
171- asset = if i ∈ Plots. _animation_examples
172- " gif(anim, \" assets/anim_$(backend) _$(Plots. ref_name(i)) .gif\" )\n " # NOTE: must not be hidden, for appearance in the rendered `html`
173- else
174- " png(\" assets/$(backend) _$(Plots. ref_name(i)) .png\" ) #src\n "
175- end
176- write(
177- jl, """
178- mkpath("assets") #src
179- $asset
174+ asset_cmd = if i ∈ Plots. _animation_examples
175+ " Plots.gif(anim, \" $asset_path \" )\n " # NOTE: must not be hidden, for appearance in the rendered `html`
176+ elseif backend ∈ (:gr, :pythonplot, :gaston)
177+ " Plots.svg(\" $asset_path \" ) #src\n "
178+ elseif backend ≡ :plotlyjs
180179 """
181- )
182- backend ≡ :plotlyjs && write(
183- jl, """
180+ Plots.png("$asset_path ") #src\n
184181 nothing #hide
185- #  _ $(Plots . ref_name(i)) .png )
182+ # 
186183 """
187- )
184+ else
185+ " Plots.png(\" $asset_path \" ) #src\n "
186+ end
187+
188+ write(jl, """ mkpath("assets") #src\n $asset_cmd \n """ )
188189
189- @label write_file
190190 fn, mode = if isempty(example. header)
191191 " $backend -$(Plots. ref_name(i - 1 )) .jl" , " a" # continued example
192192 else
193193 jlname, " w"
194194 end
195195 card = joinpath(cards_path, fn)
196196 # @info "writing" card
197- open(card, mode) do io
198- write(io, read(jl, String))
199- end
197+ open(io -> write(io, read(jl, String)), card, mode)
200198 # DEBUG: sometimes the generated file is still empty when passing to `DemoCards.makedemos`
201199 sleep(0.01 )
202200 end
@@ -514,9 +512,7 @@ generate_colorschemes_markdown() = open(joinpath(GEN_DIR, "colorschemes.md"), "w
514512 ```
515513 """
516514 )
517- for line in readlines(joinpath(SRC_DIR, " colorschemes.md" ))
518- write(md, line * ' \n ' )
519- end
515+ foreach(line -> write(md, line * ' \n ' ), readlines(joinpath(SRC_DIR, " colorschemes.md" )))
520516 write(
521517 md, """
522518 ## misc
@@ -610,10 +606,10 @@ function main(args)
610606 inspectdr()
611607
612608 # NOTE: for a faster representative test build use `PLOTDOCS_PACKAGES='GR' PLOTDOCS_EXAMPLES='1'`
613- default_packages = " GR, PythonPlot, PlotlyJS, PGFPlotsX, UnicodePlots, Gaston, InspectDR"
614- packages = get(ENV , " PLOTDOCS_PACKAGES" , default_packages )
615- packages = let val = packages == " ALL" ? default_packages : packages
616- Symbol.(filter(! isempty, strip.(split(val, " , " ))))
609+ all_packages = " GR PythonPlot PlotlyJS PGFPlotsX UnicodePlots Gaston InspectDR"
610+ packages = get(ENV , " PLOTDOCS_PACKAGES" , " ALL " )
611+ packages = let val = packages == " ALL" ? all_packages : packages
612+ Symbol.(filter(! isempty, strip.(split(val))))
617613 end
618614 packages_backends = NamedTuple(p => Symbol(lowercase(string(p))) for p in packages)
619615 backends = values(packages_backends) |> collect
@@ -653,13 +649,13 @@ function main(args)
653649 @time " gallery" for pkg in packages
654650 be = packages_backends[pkg]
655651 needs_rng_fix[pkg] = generate_cards(joinpath(@__DIR__, " gallery" ), be, slice)
656- let (path, cb, assets ) = makedemos(
652+ let (path, cb, asset ) = makedemos(
657653 joinpath(" gallery" , string(be));
658654 root = @__DIR__, src = joinpath(work, " gallery" ), edit_branch = BRANCH
659655 )
660656 push!(gallery, string(pkg) => joinpath(" gallery" , path))
661657 push!(gallery_callbacks, cb)
662- push!(gallery_assets, assets )
658+ push!(gallery_assets, asset )
663659 end
664660 end
665661 if ! debug
@@ -830,7 +826,7 @@ function main(args)
830826 # [1, 4, 5, 7:12, 14:21, 25:27, 29:30, 33:34, 36, 38:39, 41, 43, 45:46, 48, 52, 54, 62]
831827 @time " post-process `rng`" for pkg in packages
832828 be = packages_backends[pkg]
833- prefix = joinpath(BLD_DIR, " gallery" , string(be), " generated" )
829+ prefix = joinpath(BLD_DIR, " gallery" , string(be), " generated" * suffix )
834830 must_fix = needs_rng_fix[pkg]
835831 for file in Glob. glob(" */index.html" , prefix)
836832 (m = match(r" -ref(\d +)" , file)) ≡ nothing && continue
@@ -889,7 +885,7 @@ function main(args)
889885 root = @__DIR__,
890886 target = build,
891887 versions = [" stable" => " v^" , " v#.#" , " dev" => " dev" , " latest" => " dev" ],
892- # devbranch = BRANCH,
888+ devbranch = BRANCH,
893889 deploy_repo = " github.com/JuliaPlots/PlotDocs.jl" , # see https://documenter.juliadocs.org/stable/man/hosting/#Out-of-repo-deployment
894890 repo_previews = " github.com/JuliaPlots/PlotDocs.jl" ,
895891 push_preview = Base. get_bool_env(" PLOTDOCS_PUSH_PREVIEW" , false ),
0 commit comments