Closed Dsantra92 closed 1 year ago
Since DemoCards mainly runs on CI(where latency isn't a big deal), Requires is an okay solution already. But if you'd like to take a try, https://pkgdocs.julialang.org/dev/creating-packages/#Conditional-loading-of-code-in-packages-(Extensions) is a good "official" solution. An extra benefit using Extensions is that we can manage Pluto*'s compatibility.
Faced an interesting problem while following the official example
if !isdefined(Base, :get_extension)
using Requires
# print("Require import block reached")
# end
# if !isdefined(Base, :get_extension)
# print("Require __init__ block reached")
function __init__()
@require Pluto="c3e4b0f8-55cb-11ea-2926-15256bba5781" begin
@require PlutoStaticHTML = "359b1769-a58e-495b-9770-312e911026ad" include("../ext/PlutoNotebook.jl")
end
end
end
Results in an error
ERROR: LoadError: UndefVarError: `@require` not defined
Surprisingly works with comments removed, i.e. requires loaded as a separate if else blocks.
if !isdefined(Base, :get_extension)
using Requires
print("Require import block reached")
end
if !isdefined(Base, :get_extension)
print("Require __init__ block reached")
function __init__()
@require Pluto="c3e4b0f8-55cb-11ea-2926-15256bba5781" begin
@require PlutoStaticHTML = "359b1769-a58e-495b-9770-312e911026ad" include("../ext/PlutoNotebook.jl")
end
end
end
julia> using DemoCards
[ Info: Precompiling DemoCards [311a05b2-6137-4a5a-b473-18580a3d38b5]
Democards dir
Require import block reached
Require __init__ block reached
Any idea why this is happening? Similar problems are happening for julia 1.9 beta3.
I'm not sure. It's perhaps because macros are expanded first?
I decided to leave PlutoDemoCard
in the src
folder. It might not make sense, now that we are loading Pluto Notebook as an extension. But I didn't want to change the original democard
function:
https://github.com/JuliaDocs/DemoCards.jl/blob/d89e89d107b7fa70a1bf5670c875e7066c8e862e/src/types/card.jl#L20-L34
Awesome, thanks !
Introduce Requires and move Pluto dependency to optional. Close #130