Load subfolder in src like in python

Hi, all. I am wondering how I can load a folder as a submodule in Julia, similar to how it is done in Python.
For example, I want to load the modules in SubModuleA in the form of MyPackage.SubModuleA.file_a_1 and MyPackage.SubModuleA.file_a_2 in the following directory.

MyPackage/
├── Project.toml
├── src/
│   ├── MyPackage.jl
│   ├── SubModuleA/
│   │   └── file_a_1.jl
|     |    └── file_a_2.jl
│   └── SubModuleB/
│       └── file_b.jl
└── test/
    └── runtests.jl

Natively, Julia is different from Python. Julia’s modules are completely independent from any particular filesystem layout of files. You explicitly name them in the source code with module SubModuleA #= ... =# end, and can arrange files as you like by includeing them.

Folks have opinions about this — and strong ones at that. There’ve been many discussions about this and some folks have implemented their own preferred semantics in packages. See Julia#4600 and the topics tagged as “related” below for more.

Edit: here’s a fairly targeted search for more related topics: Search results for 'fromfile.jl order:latest' - Julia Programming Language

1 Like

Thanks. I partially solved this problem via create a SubModuleA.jl file which includes all modules in folder SubModule_A. It might be an easy way to achieve the goals.

2 Likes

This probably deserves a FAQ in the docs. Perhaps in the “migrating from Python” section:

5 Likes

Someone asked a similar question yesterday:

And the answer pointed to another long thread:

3 Likes