Best Debug Workflow for Dr Watson

I am extremely frustrated by my current workflow. There has to be a better way and I wanted to ask for advice.

Here is how I have been working. I use Dr. Watson for all of my projects. I write all my store all my source code in the /src dir of the project and will test and implement new features/debug in a .jl file in the scripts directory.

I write code in a .jl file and run them one by one in the REPL which works well. The problem comes when I am trying to debug/modify code I have already written in an src file. In order to load the changes to a file I have to restart the REPL which means I have to reimport all my packages. This process can take upwards of 30 seconds every time I want to change anything.

I have tried using Infiltrator but It seems to work sporadically. It won’t always activate when it hits a @infiltrator macro and will close the REPL if an error is encountered.

What I really want is an equivalent of the Ipython autoreload.
There seem to be lots of options like AutoReload.jl but I can seem to get them to work.
I also tried to use Pluto as I read it automatically included changes but I could not get it to work with DrWatson.

It seems like this must be a very common problem. Is there an easy way around it?

Revise.jl should pretty much take care of that for you. It’s extremely common in almost any Julia workflow.


Also, what problems did you have with Pluto and DrWatson?

I think it just work provided you don’t use Pluto’s package managing. So the first cell should always be.

  import Pkg
  using DrWatson

Or something similar.

P.s. Yes, autoreload.jl seems to be a very old package so I would not expect it to work. The usual method is Revise.jl, which is even recommended in the Julia documentation


Hmm thank you for the suggestions.

I was previously trying to use the @quickactivate macro. I tried using the way you suggested.

I have one file in my /src dir called main.jl which imports all my dependencies and includes all of the other files in the DrWatson project

So main.jl may look like this

using Distributions

and foo.jl could look like this

function bar()
println("Why must this be so difficult?")

So then I have a Pluto cell that looks like this

  import Pkg
  using DrWatson

I get output from this cell - clearly it is running “main.jl” which means it has imported DrWatson properly and has activated the correct environment.

However, if I run a Pluto cell that looks like this


I get the following error UndefVarError: Normal not defined

And If I run a cell that looks like this


I get this output

MethodError: no method matching bar()

Closest candidates are:

bar(!Matched::Main.var"workspace#2".foo) at path/to/foo.jl

It seems like Revise.jl requires your code to be an a package which is very difficult to do with a Dr Watson project.

That’s definitely not true. I use Revise outside of packages all the time, e.g. in Jupyter notebooks. You may have to replace include with includet.

I had the same issues as you.
What I do now is making a module in the src folder which has the same name as the project. All my source files are included in that module.
With pluto I don’t know, but with normal script files in the script folder, all my script files start with

using DrWatson
@quickactivate :MyProjectName

With Revise.jl I can then load my script files simply with
Includet(“scripts/scriptfile.jl”) (note the t in includet)
I can then freely modify the contents of my script.jl and the main module without having to restart the repl.

The procedure is described here.

Hope this helps

Thanks this is the exact combination of solutions that I had been looking for!

1 Like