Package management in Julia
Official documentation for Pkg.jl: https://pkgdocs.julialang.org/
Show which package(s) could be updated
using Pkg
Pkg.status(; outdated=true)Include other files as submodules
You could include julia files as submodules like this
## main.jl
include("foo.jl")
using .Foo
include("bar.jl")
using .Bar## foo.jl
module Foo
# content of Foo module
end## bar.jl
module Bar
# content of Bar module
end- Best when the submodules are used exclusively for this project and will not be shared with others.
- Usually you want to include all dependent submodules in the top-most file, like a table of contents.
- The
includeandusinglines need to be re-execute when the code in the submodule changes. (ifRevise.includet("foo.jl")is not used) - Use relative module path when
Bardepends onFoo.
FromFile.jl
FromFile.jl provides a macro @from to replace include(). Using @from to access a file multiple times (for example calling @from “file.jl” import foo in multiple files) will access the same objects each time; i.e. without the duplication issues that include("file.jl") would introduce.
# file1.jl
import FromFile: @from
@from "file2.jl" import foo
bar() = foo()#file2.jl
foo() = println("hi")Make a Julia package
To create a minimal package:
pkg> generate HelloWorldBut it’s recommended to use PkgTemplates.jl for the CI, unit tests, documentation, etc.
You could also register your package to the general Julia registry to be accessible to Julia users.
Unit testing
You can have local dependencies for running tests in test/Project.toml without the need of extra and targets sections in the main project’s Project.toml.
Though the build-in unit-test framework is good, but Jive.jl provides more flexibilities. See TestJive.jl for code examples.
- Discover unit testing
jlfiles automatically. - Skip or select which test(s) to run.
- Multiprocessing for faster runs.
Documentation
Use Documenter.jl to generate the documentation for Julia packages.
You need an SSH deploy key to deploy docs to GitHub pages.
using DocumenterTools
DocumenterTools.genkeys(user="you", repo="YourPackage.jl")Continuous integration / delivery (CI/CD)
PkgTemplates.jl should set up the appropriate code structure for you. I would recommend to use GitHub to host Julia packages because
- Running GH actions is unlimited for public repositories, with multiple operating systems running concurrently (matrix build).
- Julia github actions are convenient to use.
- Automation bots integrate better with GitHub. e.g. TagBot, Registerbot, and Compat Helper.