Julia packages consist of modules. Hence, before creating a package, make sure to understand how modules work in Julia.
In case of any issues, remember that help is available.
a GitHub account
You need to create a folder to store a new package. For example, if you use Atom as an IDE, create a new folder called
tiddlywinks.jl. Then, open the GitHub panel and select Initialize and publish on GitHub. Now, you can go to your GitHub page and see that 'tiddlywinks.jl' has appeared there, as well as locally.
In your terminal application, use the change directory (cd) command to change the current working directory to the location of your package.
In the Julia REPL, install
PkgTemplate.jl as follows:
using Pkg Pkg.add("PkgTemplates")
PkgTemplates.jl has been installed and we want to use it to create a template for a package.
Run the following commands in the Julia REPL to create the template:
using PkgTemplates t = Template(; user="elizavetasemenova", license="MIT", authors=["ES"], plugins=[ TravisCI(), Codecov(), Coveralls(), AppVeyor(), ], )
The package called "tiddlywinks" can now be created using the template
t by running the following line in Julia REPL:
As the folder has not been specified, the package has been created at
~/.julia/dev on Linux, and at
username/julia/dev in Windows. If this is not the repository you want to be working from, move the files to the original repo which you have created. Now in
tiddlywinks.jl you should have
LICENSE (the MIT license which we have chosen),
Manifest.toml (includes ifnormation on dependencies, very useful for reproducibility, see mode details about Project annd Manifest files),
Project.toml (contains high level information about the project),
src folder (here we will write the code for the package;)
test folder (here we will be placng tests).
Everything is ready for us to write code. Folder
/src already contains a file with the same name as the name of our package (
tiddlywinks.jl). We may not want to write all of the code in this file directly. Instead, we can create varaious pieces in external files within the
/src directory, and then assemble them in the main file with the
include command. Let us go ahead and
create a file called
functions.jl where we define a function
function tiddly_greet() println("tiddlywinks") end
include the file with functions into the main file
tiddlywinks.jl using the following line:
export the function to be available to users with
Tests are necessary to make sure that the code is working correctly. There is never enought testing. The
/test folder already has a starter. We edit it to call the newly implemented function:
using tiddlywinks using Test @testset "tiddlywinks.jl" begin @test tiddlywinks.tiddly_greet() == "tiddlywinks is working" @test tiddlywinks.tiddly_greet() != "hello world" end
To run tests on your package:
in your REPL, check that you are still in the repository of the project by running
] which will get you into the "package mode"
activate . to activate the environment from Project.toml
test to perform tests
Make sure to have pushed all of the changes to GitHub. Click on the first badge which has appeared in the GitHub repository of the package, and sign in with Travis CI.
Stay tuned for more: continuous integration, publishing a package, branches and pull requests, code review