I am trying to create a package of the julia language and use it in a project.
For now I have only a jl file, I dont know how to create a package with it.
I have rea
You should put the file in
~/.julia/v0.X/MyPackage/src/MyPackage.jl
Where ~ is your home directory and X is the version number of Julia that you are using. X will be 3, unless you are on the development or nightly version of Julia, in which case it will be 4.
Also note that for this to work the file MyPackage.jl should define the module MyPackage and export the definitions you want to have available after calling using MyPackage.
To automate the creation of this structure to you can call Pkg.generate("MyPackage", "MIT"), where MIT can be replaced by another supported default licence. This will create the folder in the correct place and set up the module structure for you. Then you just need to incorporate your code into that structure.
Here is an example of two possible contents for the file ~/.julia/v0.3/MyPackage/src/MyPackage.jl
:
module MyPackage
function test()
1
end
end # module
and
module MyPackage
export test
function test()
1
end
end # module
In the first case I have not export
ed anything. Thus, when calling using MyPackage
only the module MyPackage
itself would be made available to the user. If I wanted to use the test
function, I would have to use the fully qualified name: MyPackage.test()
.
In the second case I chose to export the function test
. This happened on the line export test
. Now when I call using MyPackage
, both the module MyPackage
and the function test
are available to the user. I do not need to use a fully qualified name to access test
anymore: test()
will work.