How to export names from a lower level module without explicitly listing all of them?

I often organize code into modules inside a single package.

Let’s say I have a pacakge named AB.jl, and inside I have modules A.jl, B.jl, all in the src folder.

A nice way to organize them is demonstrated by Jacob Quinn in the JuliaCon Workshop “Building microservices and applications in Julia”:

module AB

export A, B

include("A.jl")
using .A

include("B.jl")
using .B

end

Now assume module B exports the names “foo” and “bar”:

module B

export foo, bar

# module code ...

end

If I use the package by “using AB”, I will be able to call “B.foo”, “B.bar”.

However, if I want to directly use “foo”, “bar” without the namespace B, the only way I can do that now is explicitly exporting these names at module AB again:

module AB

export A, B, foo, bar

include("A.jl")
using .A

include("B.jl")
using .B

end

If B exports many names, this is both tedious and error prone.

Is there a simpler way to export all names B exports at the level of module AB?

Thanks!

3 Likes