Julia, Revise, and DrWatson
Dec 27, 2022
So the blogging about Julia continues. I didn't really anticipate I'd blog so much about Julia (or crosswords, for that matter), but here we are, I guess.
Just like my post about the mechanics of setting up to write a Julia package, this post is mostly for my own reference, so I can remember how to do things later down the road.
So here's the problem: I want to use both
DrWatson.jl with my project.
The problem is that
Revise.jl mostly expects you to be working on something that's semantically packaged, while
DrWatson.jl doesn't really generate Julia packages.
In fact, if you use the built-in
] generate NewProject functionality that lays out the skeleton of a package for you,
DrWatson.jl will refuse to initialise it as a new project.
The reason is, of course, that the folder isn't empty — it's got all the files associated with a new package.
If you ask
DrWatson.jl to forcibly initialise the project, it will first erase the directory's contents.
That's definitely not what we want.
So how do we get the two productivity tools to play nice with each other? Here's my extremely roundabout solution. If someone knows a more graceful way, I'd be happy to hear it.
Create a package using
] generate NewProject. You will get a folder called NewProject in your current directory.
Initialise a new DrWatson project with
or whatever temporary name you'd like. You'll get another new directory called tmp.
using DrWatson DrWatson.initialize_project("tmp")
Move everything from the tmp directory to the NewProject directory, except the
Project.tomlfile and the
srcdirectory. The NewPackage directory should already have its own versions of them (that were generated earlier). Make sure to move the hidden items too, namely the git stuff.
- Delete the tmp directory if you'd like — you've already gotten what you wanted out of it.
Optionally, write a little helper file that will pull everything in for you:
This little script will add the current directory to the list of locations that Julia looks to find packages. It then activates the current directory as a project, pulls in DrWatson and Revise, then finally loads the current project. Of course, the script assumes that you're running Julia in the project's directory. I usually call it
import Pkg; Pkg.activate(pwd()); Pkg.instantiate() using DrWatson, Revise using NewProject
intro.jland just run it every time I open the project.
- Finally, commit all your hard setup work via git!
Yeah, a short nerdy blog for today. If the nerdiness is too much, then wait until I do an update on using Helix or a recap of setting up a vanilla Arch Linux install (oops!).
send a comment