# Best Debug Workflow for Dr Watson

**URL:** https://discourse.julialang.org/t/best-debug-workflow-for-dr-watson/97234
**Category:** Performance
**Tags:** question, drwatson
**Created:** [April 7, 2023, 7:49pm UTC](https://discourse.julialang.org/t/best-debug-workflow-for-dr-watson/97234 "2023-04-07T19:49:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![WillHWThompson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willhwthompson/32/44842_2.png) [@WillHWThompson](https://discourse.julialang.org/u/WillHWThompson)
#### Post date: [April 7, 2023, 7:49pm UTC](https://discourse.julialang.org/t/best-debug-workflow-for-dr-watson/97234/1 "2023-04-07T19:49:50Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)
#### Post date: [April 7, 2023, 8:38pm UTC](https://discourse.julialang.org/t/best-debug-workflow-for-dr-watson/97234/2 "2023-04-07T20:38:47Z")

</div>

[Revise.jl](https://github.com/timholy/Revise.jl) should pretty much take care of that for you. It’s extremely common in almost any Julia workflow.

---

<div class="post-metadata">

### Author: ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)
#### Post date: [April 7, 2023, 9:14pm UTC](https://discourse.julialang.org/t/best-debug-workflow-for-dr-watson/97234/3 "2023-04-07T21:14:34Z")

</div>

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.

```julia
begin
  import Pkg
  Pkg.activate("path/to/your/environment")
  using DrWatson
end

```

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](https://docs.julialang.org/en/v1/manual/workflow-tips/#man-workflow-tips)

---

<div class="post-metadata">

### Author: ![WillHWThompson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willhwthompson/32/44842_2.png) [@WillHWThompson](https://discourse.julialang.org/u/WillHWThompson)
#### Post date: [April 7, 2023, 10:22pm UTC](https://discourse.julialang.org/t/best-debug-workflow-for-dr-watson/97234/4 "2023-04-07T22:22:09Z")

</div>

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

```julia
using Distributions
include(srcdir("foo.jl"))

```

and `foo.jl` could look like this

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

```

So then I have a Pluto cell that looks like this

```julia
begin
  import Pkg
  Pkg.activate("path/to/your/environment")
  using DrWatson
  include(srcdir("main.jl"))
end

```

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

```julia
Normal(1)

```

I get the following error `UndefVarError: Normal not defined`

And If I run a cell that looks like this

```julia
bar()

```

I get this output

```julia
MethodError: no method matching bar()

Closest candidates are:

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

```

---

<div class="post-metadata">

### Author: ![WillHWThompson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willhwthompson/32/44842_2.png) [@WillHWThompson](https://discourse.julialang.org/u/WillHWThompson)
#### Post date: [April 7, 2023, 10:22pm UTC](https://discourse.julialang.org/t/best-debug-workflow-for-dr-watson/97234/5 "2023-04-07T22:22:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)
#### Post date: [April 7, 2023, 10:45pm UTC](https://discourse.julialang.org/t/best-debug-workflow-for-dr-watson/97234/6 "2023-04-07T22:45:26Z")

</div>

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`.

---

<div class="post-metadata">

### Author: ![Olivier\_Merchiers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olivier_merchiers/32/4073_2.png) [@Olivier\_Merchiers](https://discourse.julialang.org/u/Olivier_Merchiers)
#### Post date: [April 7, 2023, 11:26pm UTC](https://discourse.julialang.org/t/best-debug-workflow-for-dr-watson/97234/7 "2023-04-07T23:26:52Z")

</div>

Hi,  
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

```julia
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](https://juliadynamics.github.io/DrWatson.jl/stable/real_world/#Making-your-project-a-usable-module-1).

Hope this helps

---

<div class="post-metadata">

### Author: ![WillHWThompson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willhwthompson/32/44842_2.png) [@WillHWThompson](https://discourse.julialang.org/u/WillHWThompson)
#### Post date: [April 8, 2023, 6:03am UTC](https://discourse.julialang.org/t/best-debug-workflow-for-dr-watson/97234/8 "2023-04-08T06:03:39Z")

</div>

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