Is Julia able to export a module as another (aliased) name?

I am not the author of Yao.jl. I just want to use it as an example. The source code of Yao.jl is just one simple thing: reexport things defined in its sub-packages.

using Reexport
@reexport using YaoBase, YaoArrayRegister, YaoBlocks, YaoSym

So, am I able to do

@reexportas YaoArrayRegister ArrayRegister

and when users load Yao, they can access things defined in YaoArrayRegister by Yao.ArrayRegister.

I want this feature because I also have a collection of sub-packages like Yao, e.g.,

using AVeryLongNamespace, AVeryLongNamespaceBase, AVeryLongNamespaceParsers

Can I just do

using AVeryLongNamespace
AVeryLongNamespace.Base.something
AVeryLongNamespace.Parsers.anotherthing

One way to do this I think is to define a Base.jl and Parsers.jl in AVeryLongNamespace module, and reexport them respectively.

1 Like

I just found another question: Package Aliases?.

They introduce ImportMacros.jl there.

I guess what I need to do is

module AVeryLongNamespace
using ImportMacros
@import AVeryLongNamespaceBase as ABase
@import AVeryLongNamespaceParsers as Parsers

export ABase, Parsers
end

It is good that ImportMacros.jl create aliases of sub-packages, but it does not have the function of Reexport: reexporting symbols.

julia> using AVeryLongNamespace

julia> names(AVeryLongNamespace)
3-element Array{Symbol,1}:
 :ABase
 :Parsers
 :AVeryLongNamespace

However, when using Reexport, it also brings sub-packages into scope:

module AVeryLongNamespace
using Reexport
@reexport AVeryLongNamespaceBase
@reexport AVeryLongNamespaceParsers
end
julia> using AVeryLongNamespace

julia> names(AVeryLongNamespace)
5-element Array{Symbol,1}:
:something
:anotherthing
:AVeryLongNamespace
:AVeryLongNamespaceBase
:AVeryLongNamespaceParsers

Can I take the advatanges of both packages to let names(AVeryLongNamespace) to be

julia> names(AVeryLongNamespace)
5-element Array{Symbol,1}:
:something
:anotherthing
:AVeryLongNamespace
:Base
:Parsers

I understand it might be tricky to do this, but I just want to know is there any possibility.