Julia package workflow

published on 2021-04-13

This post serves to briefly explain the Julia[undefined] workflow I have developed which allows me to use my favorite editor Vim[undefined] very interactively with the REPL. I split this into two sections: one for when I am testing simple scripts and another for larger packages. This is of course a quick reference for myself, but hopefully it will help other developers out there.

Scripting

An important thing for me is to be able to develop in the directory of my choosing. Let's call the following in a shell.

mkdir ~/dev/my-new-script-directory
cd ~/dev/my-new-script-directory

From here, I declare a local environment and immediately add Revise.jl[undefined].

julia
]activate .
add Revise

In another shell in this same directory, I then open Vim at some file index.jl. Here, I write whatever scripts I please and be sure to add the necessary packages to my activated environment. As I write new functions within my script, I interact with them in the REPL by using the Revise.includet(::String) method. For instance, back in the Julia REPL (being sure to backspace to migrate from pkg> to juila>),

using Revise
includet("index.jl")

will expose the namespace of index.jl and dynamically update with new writes to the file.

Packaging

When developing a package, I effectively do the same thing. Suppose I already have some package.

~/dev/SomePackage.jl/
├── Manifest.toml
├── Project.toml
├── src
│   └── SomePackage.jl
│   └── ...
└── test
    └── runtests.jl
    └── ...

With a shell in the project directory, I create a new directory sandbox and activate a new Julia environment with Revise and the parent package in development mode.

mkdir sandbox
cd sandbox
julia
]activate .
add Revise
dev ../

As before, with a shell in this sandbox directory, I may use Vim to edit some file index.jl and interactively have access to the namespace in the REPL.

using Revise
using SomePackage
includet("index.jl")

More importantly, because I told Pkg to develop SomePackage.jl relatively when running dev ../, I may also edit the source files of SomePackage in the parent directory and ensure changes propogate to the REPL.

On separate development sessions, the sandbox environment will still have SomePackage.jl in the Manifest, so all we must do is be sure to include Revise. In other words, each time I return back to developing, I go to the ~/dev/SomePackage.jl/sandbox directory in a shell and run the following,

julia
]activate .

type a backspace to move from pkg> to julia>, and import accordingly.

using Revise
using SomePackage

References

[1]The Julia Programming Language.Website. https://julialang.org
[2]Vim.Website. https://www.vim.org