How to include more modules in one package?


#1

I’m making my first package for Julia (text generator based on Markov chains) and I’d like it to export two modules: Markovify and Markovify.Tokenizer, so that both will be available to be used in the users code. How do I do this as a developer?

Currently I have simply two files with two modules, but only the module named Markovify (which is the same as the package name) seems to be exported.

Thank you.


#2

The user would not be able to input using Markovify.Tokenizer before using Markovify first. If you wish to be able to load the Tokenizer package without first invoking Markovify, then it needs to be a separate package, so that the package manager recognizes it separately.


#3

That doesn’t concern me, Markovify.Tokenizer will be used only when using Markovify anyway. Just to be sure; to be able to make this, I should do something like:

file1.jl

module Markovify
[...]
end

file2.jl

module Markovify
    module Tokenizer
    [...]
    end
end

Right?


#4

Probably more like this, actually

Markovify.jl

module Markovify
include("file2.jl")
[...]
end

file2.jl

module Tokenizer
    [...]
end

#5

That was what I’ve been missing! Worked great, thanks. No clue why my version didn’t work, though; any pointers?


#6

In your version you’ve defined two different modules with the same name, Markovify. One contained the Tokenizer module and one didn’t.


#7

The package manager looks in the src directory for a file with the same name as the package, so file1.jl will not be found. You have to include the other files from the main module file to load them.