DrWatson Common Code as Module Issue


I am trying to use the functionality of DrWatson described here. But I can’t get it to work.

Here is what I have. I’ve got a very basic project that looks like this.


Here are the packages I am using. I am also using Julia 1.10. My project environment is called MyProject. I’m doing all my coding via the Julia extension in VSCode.

[13f3f980] CairoMakie v0.11.4
[634d3b9d] DrWatson v2.15.0
[f67ccb44] HDF5 v0.17.2
[a7d1346e] MyLocalPackage v0.4.0 `src/MyLocalPackage.jl`
[189a3867] Reexport v1.2.2

I have some common code defined in files within src/ I’d like to have run at the beginning of each analysis. So I’d like to put that into a module. I could of course just do


But I’d rather take advantage of DrWatson to the fullest extent possible.

So following the example from the link above, inside src/ I’ve created a file called MyProject.jl and it contains the following.

module MyProject

using Reexport
@reexport using HDF5, MyLocalPackage, CairoMakie

export helper1, helper2, helper3, helper4


end # module

Then I try to use this in the manner shown in the DrWatson pages like so.

# analysis1/analysis1.jl
using DrWatson
@quickactivate :MyProject

# more code here...

When I do shift+enter in VScode to evaluate the second line I get the following error.

ERROR: ArgumentError: Package MyProject not found in current path.

Has anyone gotten this to work? Could it be something wrong with VSCode? Any suggestions?

Please post the contents of Project.toml. IIRC DrWatson.jl does not generate everything in Project.toml that is required for a module (I think the UUID is missing or something like that). Thus Julia does not recognize the folder as a proper package.

Edit: Just checked one of my DrWatson.jl projects and yes the UUID and version fields are indeed missing from Project.toml.
Try adding something like:

version = "0.1.0-DEV"
uuid = "cec25042-51c3-436f-8186-bce8411cd328"

You can use that UUID, I just generated it but shouldn’t matter anyways :slight_smile:

1 Like

I was just wondering how likely this exact UUID will now be reproduced by some AI or another. Probably not very likely, but I just imagined ChatGPT going around recommending people to use this UUID with it’s typical “trust me bro” attitude :grin:

1 Like

Awesome. Thank you. I wonder why the DrWatson documentation mentions nothing of this? As you said, this was a simple project so it was missing the name, uuid, authors, and version fields. I added all four but per your comment only the uuid and version are required.

See here for generating your own UUIDs. I modified my Project.toml to look like this.

# Was initially this
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DrWatson = "634d3b9d-ee7a-5ddf-bec9-22491ea816e1"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

Afterwards was like this.

name = "MyProject"
authors = ["Me <me@mail.com>"]
version = "0.1.0-DEV"

CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DrWatson = "634d3b9d-ee7a-5ddf-bec9-22491ea816e1"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

Now I can do @quickactivate :MyProject and it works as described in the docs.

DrWatson does generate everything necessary, UUID is not one of the necessary components. If the project was generated with the provided function initialize_project() then for sure it has everything necessary, which is only a project name. No version or UUID.

The user @TI36XPro has not used this function to start their project, because the project only had a [deps] entry and initialize_project() would add at a minimum a project name and a [compat] entry.

The documentation on making your project (Real World Examples · DrWatson.jl ) is accurate, I can 100% guarantee that, but it assumes (without saying so explicitly) that the project was generated using initialize_project.

Itt would literally take you as much time as writing this, to actually fix it as well. Would you consider doing so?

Simply go to Real World Examples · DrWatson.jl, click this button


and add a statement: “notice, this assumes that the project has a name entry, which matches the name of hte folder and the .jl file. initialize_project() does all of this automatically”.

proof: FractalDimensionComparison/Project.toml at main · Datseris/FractalDimensionComparison · GitHub allows this ‘project-as-module’ approach with only a name entry.

This is a good clarification. You are correct. I started my analysis then remembered I wanted to use DrWatson.

Good suggestion. Yes, I will do that.

1 Like

No offense :slight_smile: I just wanted to write something for the docs of DrWatson.jl and went to test some stuff.

It turns out that if you just use DrWatson.initialize_project(path) then infact DrWatson does not put a name in the Project.toml. Only if you do DrWatson.initialize_project(path, name) then the name is written to the Project.toml.

Probably it would make sense to use the folder name as name for the project. What do you think?

Edit: Just tried this again and now it seems to be there. Maybe I made a mistake.

1 Like

Yes, that is a good idea! I thought that name defaults to the folder name, but I guess not? In any case please do consider doing a PR if you have the time!

It does: DrWatson.jl/src/project_setup.jl at ba90137550819a517057fef8cda2a16d7dea8422 · JuliaDynamics/DrWatson.jl · GitHub

So if indeed initialize_project(path) doesn’t put a name at the project.toml that’s a weird bug! please open an issue

thanks a lot for helping the user at the first place!!!

In the future, please don’t call it “my” package, as I am just one of the developers, I don’t feel any more ownership than other contributors!

Sorry - changed :slight_smile:
I’ll do my best to not call it that, although I must admit that my association between the package and you is very strong thanks to your great talk at JuliaCon with the mustache and hat :smiley: