I don’t exactly understand what you want. Do you want to load packages conditionally, based on a parameter file? You might need @eval
to do that (a symptom that there is probably a better way to accomplish your goals). You might find using Pkg; Pkg.project().dependencies
to be useful for finding what is in your project (although this may not be the best way – this kind of introspection isn’t super-well supported because it’s not usually very useful). If you’re thinking about this, I’ll discourage it and say that there’s probably a better way. If you elaborate a little bit, someone can probably suggest it.
In any case, your MainPackage
does not need to import, depend on, or even know about your optional packages. More idiomatically, your MainPackage
might define an interface (a set of abstract types and/or functions) and your optional packages would extend it with their custom functionality. So your optional packages would depend on your main package (not so onerous when they intend to implement/extend its functionality), but not the other way around.
An example of the pattern I would propose is given in this post. This is basically the same way any interface in Julia is extended (for example, how one implements a custom AbstractArray
) except that in this case the dispatch is based on a token (that may hold no data) instead of some data-carrying object (like an AbstractArray
).