Requires is a Julia package that will magically make loading packages faster, maybe. It supports specifying glue code in packages which will load automatically when a another package is loaded, so that explicit dependencies (and long load times) can be avoided.
Usage is as simple as
media(::MyType) = Textual()
@require Gadfly begin
media(::Gadfly.Plot) = Graphical()
endFor larger amounts of code you can also use @require Package include("glue.jl").
The code wrapped by @require will execute as soon as the given package is loaded
(which may be immediately).
julia> using Requires
julia> @require DataFrames println("foo")
julia> using DataFrames
foo
julia> @require DataFrames println("bar")
barNote that the package is not imported by default – you need an explicit using
statement if you want to use the packages names without qualifying them.
See here for some more detailed examples.
This package also provides the @lazymod macro, which provides a way to load
modules the first time they are used.
julia> using Requires
julia> @lazymod DataFrames
dataframes (generic function with 1 method)
julia> dataframes().DataFrame # This will take a few seconds
DataFrame (constructor with 22 methods)
julia> dataframes().DataFrame # This will be instant
DataFrame (constructor with 22 methods)If the module you want to load lazily lives in its own file within your package, you can also use
@lazymod MyMod "src/mymod.jl"The source file will then be includeed when the module is first used.
See here for an example.