Modular local projects and `include(...)`

tgross35
Thu, 09 Mar 2023 03:23:28 +0000
New to Julia

Are local files/modules ever immediately importable with using , or is include always required?

For example, with a structure like this:

Project.toml
src/                # Source for a local library `MyLib`
    MyLib.jl        # contains `module MyLib`
    SomeModule.jl   # contains `module SomeModule`
    SomeModule/
        Foo.jl
        Bar.jl
runnable_file_1.jl  # these two rely on MyLib.jl
runnable_file_2.jl

Is all of the following necessary?

runnable_file_1 and 2 have include("src/MyLib.jl"); using MyLib

MyLib.jl has include("SomeModule.jl"); export SomeModule

SomeModule.jl has include("SomeModule/Foo.jl"); export Foo and the same for bar

It seems to me that there might be a way for directory structure to create module structure without manually including then exporting everything - such that a top level runnable file could simply using MyLib.SomeModule.Foo without needing the include statement at all (ala Python with __init__.py or Rust with pub mod).

Is something simpler possible? Alternatively, is there a better structure for a local package than what I describe?

9 posts - 5 participants