Import and extend packages without importing them
Author tkf
5 Stars
Updated Last
2 Years Ago
Started In
April 2019


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.


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

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

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

# 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

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

Required Packages

Used By Packages

No packages found.