# Exportall?

**URL:** <https://discourse.julialang.org/t/exportall/4970>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 20, 2017, 8:52am UTC](https://discourse.julialang.org/t/exportall/4970 "2017-07-20T08:52:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [July 20, 2017, 8:52am UTC](https://discourse.julialang.org/t/exportall/4970/1 "2017-07-20T08:52:27Z")

</div>

Is there a way to export ALL the symbols declared in a module? Just to avoid writing them all under `export`.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 20, 2017, 8:57am UTC](https://discourse.julialang.org/t/exportall/4970/2 "2017-07-20T08:57:19Z")

</div>

No. You typically don’t want to do this.

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [July 20, 2017, 9:05am UTC](https://discourse.julialang.org/t/exportall/4970/3 "2017-07-20T09:05:57Z")

</div>

> [@kristoffer.carlsson](#):
>
> No. You typically don’t want to do this.

I am just following this tip:  
[https://docs.julialang.org/en/stable/manual/workflow-tips/](https://docs.julialang.org/en/stable/manual/workflow-tips/)

which I find very useful. However since I am constantly changing the package, it is very inconvenient to track exported variables. So I think this is a use-case for exportall. Why is it so dangerous? I think it could be useful in certain scenarios.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 20, 2017, 9:36am UTC](https://discourse.julialang.org/t/exportall/4970/4 "2017-07-20T09:36:38Z")

</div>

I would prefix the module name before the functions you are using when developing (or do something like `const m = MyPackage` and use `m.f()`.

For improved workflow, I would look at [https://github.com/timholy/Revise.jl](https://github.com/timholy/Revise.jl)

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [July 20, 2017, 10:21am UTC](https://discourse.julialang.org/t/exportall/4970/5 "2017-07-20T10:21:07Z")

</div>

> [@kristoffer.carlsson](#):
>
> I would prefix the module name before the functions you are using when developing (or do something like const m = MyPackage and use m.f().

What is the advantage of that, versus `exportall`? I am just trying to see the downside of having `exportall` as a feature.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 20, 2017, 10:26am UTC](https://discourse.julialang.org/t/exportall/4970/6 "2017-07-20T10:26:41Z")

</div>

Global namespace is global.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [July 20, 2017, 2:16pm UTC](https://discourse.julialang.org/t/exportall/4970/7 "2017-07-20T14:16:25Z")

</div>

Julz has a function for exporting all vars (that were included using the package)

Maybe you can do something like this:

[https://github.com/djsegal/Julz.jl/blob/master/src/macros/export\_all\_files.jl](https://github.com/djsegal/Julz.jl/blob/master/src/macros/export_all_files.jl)

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [July 20, 2017, 2:22pm UTC](https://discourse.julialang.org/t/exportall/4970/8 "2017-07-20T14:22:05Z")

</div>

A practice which I like but I see others employ only rarely is putting `export` statements immediately following definitions like so

```julia
f(x::AbstractFloat) = # do some stuff
function f(x::Complex{<:AbstractFloat})
    # do some other stuff
end
export f

```

I agree that creating an `exportall` keyword would be asking for trouble.

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [July 20, 2017, 2:44pm UTC](https://discourse.julialang.org/t/exportall/4970/10 "2017-07-20T14:44:09Z")

</div>

> [@djsegal](#):
>
> macro export\_all\_files(cur\_item)  
> all\_files = get\_all\_files(eval(cur\_item))
> 
> cur\_expression = quote end  
> for file in all\_files  
> exported\_object = Symbol("(file)") cur\_block = quote export (esc(exported\_object))  
> end  
> append!(cur\_expression.args, cur\_block.args)  
> end  
> cur\_expression  
> end

Can you explain this code a bit? It seems to be exporting all _files_, not symbols of a module.

---

<div class="post-metadata">

**Author:** ![adamslc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamslc/32/3452_2.png) [@adamslc](https://discourse.julialang.org/u/adamslc)\
**Post date:** [July 20, 2017, 2:55pm UTC](https://discourse.julialang.org/t/exportall/4970/11 "2017-07-20T14:55:42Z")

</div>

That does seem good for readability while the code is being written, but I wonder if it will become more difficult for other people (or a future you) to understand what the code does. Looking at a list of exports is one of the ways that I typically start to understand a new package.

I think I might try this style on my next project and see how it works…

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [July 20, 2017, 2:59pm UTC](https://discourse.julialang.org/t/exportall/4970/12 "2017-07-20T14:59:14Z")

</div>

I haven’t particularly found reading the export lists useful without a good handle on what the functions actually do. Sometimes having argument types is enough for this, but the names alone usually aren’t (for me at least).

Granted, it does make it easy to lose track of which functions are being exported.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [July 21, 2017, 7:08pm UTC](https://discourse.julialang.org/t/exportall/4970/13 "2017-07-21T19:08:10Z")

</div>

Yea, I felt like exportall was a little dodgy (so I scoped it on files for Julz).

I believe the following code does exactly what you want

// at least it did in v0.5

[https://github.com/djsegal/julz\_legacy/blob/master/app/templates/config/export\_all\_except.jl](https://github.com/djsegal/julz_legacy/blob/master/app/templates/config/export_all_except.jl)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 21, 2017, 8:59pm UTC](https://discourse.julialang.org/t/exportall/4970/14 "2017-07-21T20:59:30Z")

</div>

The following simple snippet seems to work:

```julia
module Foo
        foo(x) = x+1
        bar(x) = x-1
 
        # exportall:
        for n in names(current_module(), true)
            if Base.isidentifier(n) && n ∉ (Symbol(current_module()), :eval)
                @eval export $n
            end
        end
end

```

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [November 13, 2017, 1:44pm UTC](https://discourse.julialang.org/t/exportall/4970/15 "2017-11-13T13:44:21Z")

</div>

@stevengj Sometimes I have a module spread over multiple files. Is there a way to specialize this to only export symbols defined in the current file?

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [July 22, 2020, 9:47pm UTC](https://discourse.julialang.org/t/exportall/4970/16 "2020-07-22T21:47:08Z")

</div>

Here’s a version of the export-all code chunk from @stevengj that is updated for Julia v1.0. (Well, for v1.4 at least. I haven’t tested on v1.0).

```julia
# export all
for n in names(@ __MODULE__ ; all=true)
    if Base.isidentifier(n) && n ∉ (Symbol(@ __MODULE__ ), :eval, :include)
        @eval export $n
    end
end

```

When I’m developing a new package, I find it pretty convenient to just export all the functions in the package. Later when the code stabilizes I can choose which functions to export, but initially I’m usually the only user of my package and it’s easier just to export everything.

Here’s the new code in action:

```julia
julia> module Foo
           x = 1
           y = 2
       
           for n in names(@ __MODULE__ ; all=true)
               if Base.isidentifier(n) && n ∉ (Symbol(@ __MODULE__ ), :eval, :include)
                   @eval export $n
               end
           end
       end
Main.Foo

julia> using .Foo

julia> x
1

julia> y
2

```

---

<div class="post-metadata">

**Author:** ![Rana\_Ian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rana_ian/32/13554_2.png) [@Rana\_Ian](https://discourse.julialang.org/u/Rana_Ian)\
**Post date:** [September 20, 2020, 3:54am UTC](https://discourse.julialang.org/t/exportall/4970/17 "2020-09-20T03:54:25Z")

</div>

@CameronBieganek Thanks for posting. Adding `export all` to my toolbox.

---

<div class="post-metadata">

**Author:** ![Clemapfel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/clemapfel/32/32261_2.png) [@Clemapfel](https://discourse.julialang.org/u/Clemapfel)\
**Post date:** [December 29, 2021, 8:18pm UTC](https://discourse.julialang.org/t/exportall/4970/18 "2021-12-29T20:18:42Z")

</div>

I wrote my own convenient macros for this, one exports all names and one follows all sub-modules recursively. Only tested under 1.7.1

Usage:

```julia
module MyModule
    # code here
end
@make_public MyModule
# or, if you want to follow sub-modules recursively:
@make_public_rec MyModule

```

Code:

```julia
#
# Copyright 2021 Clemens Cords
# Created on 26.12.2021 by clem (mail@clemens-cords.com)
#

"""
export all non-temporary, non-imported values (values not having a '#' at the
start of it's symbol when listed via Base.names) in a module

Example:
    module MyModule

        module SubModule
            _sub_variable
        end

        _variable
    end

    @make_public MyModule

    # exports:
    # MyModule
    # MyModule.SubModule
    # MyModule._variable

See also: @make_public_rec
"""
macro make_public(module_name::Symbol)

    eval(Meta.parse("export " * string(module_name)))

    as_module = eval(module_name)
    @assert as_module isa Module

    for name in names(as_module; all = true)
        if (string(name)[1] != '#')
            #println("export " * string(name))
            as_module.eval(Meta.parse("export " * string(name)))
        end
    end

    return nothing
end
export make_public

"""
export all non-temporary, non-imported values (values not having a '#' at the
start of it's symbol when listed via Base.names) in a module and all
such values in any submodule, recursively

Example:
    module MyModule

        module SubModule
            _sub_variable
        end

        _variable
    end

    @make_public_rec MyModule

    # exports:
    # MyModule
    # MyModule.SubModule
    # MyModule.SubModule._sub_variable
    # MyModule._variable

See also: @make_public
"""
macro make_public_rec(module_name::Symbol)

    function make_public_aux(child_name::Symbol, super::Module) ::Nothing

        if (string(child_name)[1] != '#')
            #println("export " * string(child_name))
            super.eval(Meta.parse("export " * string(child_name)))
        end

        child = super.eval(child_name)
        if (child isa Module && child != super)
            for name in names(child; all = true)
                make_public_aux(name, child)
            end
        end

        return nothing
    end

    origin = eval(module_name)
    @assert origin isa Module

    for name in names(origin; all = true)
        make_public_aux(name, origin)
    end

    return nothing
end
export make_public_rec

```

It will be part of [jlwrap](https://github.com/Clemapfel/jlwrap) which I am the author of and can be used freely with attribution under GNU license

---

<div class="post-metadata">

**Author:** ![ultrapoci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ultrapoci/32/25356_2.png) [@ultrapoci](https://discourse.julialang.org/u/ultrapoci)\
**Post date:** [April 25, 2022, 9:17am UTC](https://discourse.julialang.org/t/exportall/4970/19 "2022-04-25T09:17:36Z")

</div>

I think that a good in-between would be the ability to write something like

```julia
export function myfn()
    # ...
end

```

This way you would be explicit about exported function, but you don’t have to review the code every so often to export whatever you wrote: you just put `export` in front of every function you write and you’re sure is going to be exported.

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [April 25, 2022, 9:32am UTC](https://discourse.julialang.org/t/exportall/4970/20 "2022-04-25T09:32:08Z")

</div>

Attaching `export` to _method_ definitions is not a good idea, I think. Export cares about _functions_, not methods (i.e. you cannot export a subset of methods of a given function; it’s all or none).

---

<div class="post-metadata">

**Author:** ![ultrapoci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ultrapoci/32/25356_2.png) [@ultrapoci](https://discourse.julialang.org/u/ultrapoci)\
**Post date:** [April 25, 2022, 9:35am UTC](https://discourse.julialang.org/t/exportall/4970/21 "2022-04-25T09:35:17Z")

</div>

Makes sense

[Next page](https://discourse.julialang.org/t/exportall/4970.md?page=2)
