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 read this link but I still dont know how to do it. I want to create a local package with a jl file and use it in my own local project with this code: using MyPackage
.
Could someone help me?
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.
EDIT
Here is an example of two possible contents for the file
~/.julia/v0.3/MyPackage/src/MyPackage.jl
:and
In the first case I have not
export
ed anything. Thus, when callingusing MyPackage
only the moduleMyPackage
itself would be made available to the user. If I wanted to use thetest
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 lineexport test
. Now when I callusing MyPackage
, both the moduleMyPackage
and the functiontest
are available to the user. I do not need to use a fully qualified name to accesstest
anymore:test()
will work.