Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 2.17 KB

README.md

File metadata and controls

54 lines (42 loc) · 2.17 KB

IndirectImports

Stable Dev GitHub commits since tagged version Build Status Codecov Coveralls

IndirectImports.jl lets Julia packages call and extend (a special type of) functions without importing the package defining them. This is useful for managing optional dependencies.

  • Compared to Requires.jl, IndirectImports.jl's approach is more static and there is no run-time eval hence more compiler friendly. However, unlike Requires.jl, both upstream and downstream packages need to rely on IndirectImports.jl API.

  • Compared to "XBase.jl" approach, IndirectImports.jl is more flexible in the sense that you don't need to create an extra package and keep it in sync with the "implementation" package(s). However, unlike "XBase.jl" approach, IndirectImports.jl is usable only for functions, not for types.

Example

# MyPlot/src/MyPlot.jl
module MyPlot
    using IndirectImports

    @indirect function plot end  # declare an "indirect function"

    @indirect function plot(x)  # optional
        # generic implementation
    end
end

# MyDataFrames/src/MyDataFrames.jl
module MyDataFrames
    using IndirectImports

    @indirect import MyPlot  # this does not actually load MyPlot.jl

    # you can extend indirect functions
    @indirect function MyPlot.plot(df::MyDataFrame)
        # you can call indirect functions
        MyPlot.plot(df.columns)
    end
end

You can install it with ]add IndirectImports. See more details in the documentation.