My Julia workflow

By: Tamás K. Papp

Re-posted from: https://tamaspapp.eu/post/julia-workflow/

(edit 2017-10-22: fixed path for PkgDev.generate example)

This is a summary of the workflow I find ideal for working with Julia. Although the manual has a section on workflow, it does not mention all the tools that I find useful, so perhaps this will benefit some users of Julia.

I use Emacs, with julia-mode (for editing the source) and julia-repl (REPL integration). The latter is my own package; you can use ESS instead, which has some advantages (eg multiple inferior processes) and disadvantages (no ANSI terminal support). The choice of an editor is highly subjective: at the end of the day, all you need is one that is capable of sending code to the REPL and can, in turn, be used by the REPL to open a file at a particular point. I use

ENV["EDITOR"] = "emacsclient"

in ~/.juliarc.jl to ensure this. This helps me find code with the @edit macro.

Small code snippets and experiments below ~30 lines just go into files, from which I send regions of code to the REPL. Frequently, for throwaway code, I just open a file in /tmp/, which will get removed automatically after the next reboot.

Even very small projects get their own package. This way I get version control1 and a sensible structure for unit tests set up automatically. I put my own packages in their own directory, keeping them separate from Pkg.dir(). This allows me to use the same package across Julia versions, and makes Pkg.update() ignore them. I tell Julia where they are with

const LOCAL_PACKAGES = expanduser("~/src/julia-local-packages/")
push!(LOAD_PATH, LOCAL_PACKAGES)

I create local packages with

import PkgDev
PkgDev.generate("MyPkg", "MIT"; path = LOCAL_PACKAGES)

Then I open the file and start working on it with

using MyPkg

I use Revise.jl to automate reloading.2 This package has changed my workflow completely; it can cope with most changes, except for type redefinitions. For these, I need to restart the REPL.

To test my code, I use Pkg.test with RoguePkg.jl, which makes it find packages outside Pkg.dir() for testing and benchmarks:

Pkg.test(pkg_for"MyPkg")

  1. I use the amazing magit for interacting with git — having obtained funding on KickStarter recently, it is bound to become even more convenient. [return]
  2. You just need to set it up once according to its documentation, after that it is automatic. [return]