# DrWatson Common Code as Module Issue

**URL:** https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203
**Category:** General Usage
**Tags:** drwatson
**Created:** [June 5, 2024, 2:31am UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203 "2024-06-05T02:31:00Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)
#### Post date: [June 5, 2024, 2:31am UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203/1 "2024-06-05T02:31:00Z")

</div>

Hello,

I am trying to use the functionality of DrWatson described [here](https://juliadynamics.github.io/DrWatson.jl/dev/real_world/#Making-your-project-a-usable-module). But I can’t get it to work.

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

```julia
./
../
.git/
.gitignore
Manifest.toml
Project.toml
README.md
analysis1/
analysis2/
main.jl
src/

```

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.

```julia
[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

```julia
begin
    includet(srcdir("helpers1.jl"))
    includet(srcdir("helpers2.jl"))
end

```

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.

```julia
module MyProject

using Reexport
@reexport using HDF5, MyLocalPackage, CairoMakie

export helper1, helper2, helper3, helper4

include(srcdir("helpers1.jl"))
include(srcdir("helpers2.jl"))

end # module

```

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

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

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

```

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

---

<div class="post-metadata">

### Author: ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)
#### Post date: [June 5, 2024, 5:28am UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203/2 "2024-06-05T05:28:15Z")

</div>

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:

```toml
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 🙂

---

<div class="post-metadata">

### Author: ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)
#### Post date: [June 5, 2024, 7:35am UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203/3 "2024-06-05T07:35:44Z")

</div>

> [@abraemer](#):
>
> You can use that UUID, I just generated it but shouldn’t matter anyways 🙂

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 😁

---

<div class="post-metadata">

### Author: ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)
#### Post date: [June 5, 2024, 11:20am UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203/4 "2024-06-05T11:20:24Z")

</div>

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](https://stackoverflow.com/questions/69945658/how-to-create-a-uuid-for-a-julia-package) for generating your own UUIDs. I modified my Project.toml to look like this.

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

```

Afterwards was like this.

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

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

```

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

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [June 5, 2024, 11:59am UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203/5 "2024-06-05T11:59:48Z")

</div>

> [@abraemer](#):
>
> [DrWatson.jl](https://juliahub.com/ui/Packages/General/DrWatson) does not generate everything in `Project.toml` that is required for a module (I think the UUID is missing or something like that)

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](https://juliadynamics.github.io/DrWatson.jl/stable/real_world/#Making-your-project-a-usable-module) ) is accurate, I can 100% guarantee that, but it assumes (without saying so explicitly) that the project was generated using `initialize_project`.

> [@TI36XPro](#):
>
> I wonder why the DrWatson documentation mentions nothing of this?

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

![image](https://global.discourse-cdn.com/julialang/original/3X/4/9/49f0408847b12623bb7e6d4ad48e7a6c8f6a1b52.png)

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

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [June 5, 2024, 12:01pm UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203/6 "2024-06-05T12:01:55Z")

</div>

proof: [FractalDimensionComparison/Project.toml at main · Datseris/FractalDimensionComparison · GitHub](https://github.com/Datseris/FractalDimensionComparison/blob/main/Project.toml) allows this ‘project-as-module’ approach with only a name entry.

---

<div class="post-metadata">

### Author: ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)
#### Post date: [June 5, 2024, 12:05pm UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203/7 "2024-06-05T12:05:54Z")

</div>

> [@Datseris](#):
>
> 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](https://juliadynamics.github.io/DrWatson.jl/stable/real_world/#Making-your-project-a-usable-module) ) is accurate, I can 100% guarantee that, but it assumes (without saying so explicitly) that the project was generated using `initialize_project`.

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

> [@Datseris](#):
>
> Itt would literally take you as much time as writing this, to actually fix it as well. Would you consider doing so?

Good suggestion. Yes, I will do that.

---

<div class="post-metadata">

### Author: ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)
#### Post date: [June 5, 2024, 12:06pm UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203/8 "2024-06-05T12:06:29Z")

</div>

No offense 🙂 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.

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [June 5, 2024, 12:07pm UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203/9 "2024-06-05T12:07:12Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [June 5, 2024, 12:08pm UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203/10 "2024-06-05T12:08:15Z")

</div>

It does: [DrWatson.jl/src/project\_setup.jl at ba90137550819a517057fef8cda2a16d7dea8422 · JuliaDynamics/DrWatson.jl · GitHub](https://github.com/JuliaDynamics/DrWatson.jl/blob/ba90137550819a517057fef8cda2a16d7dea8422/src/project_setup.jl#L274)

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

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [June 5, 2024, 12:09pm UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203/11 "2024-06-05T12:09:56Z")

</div>

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

> [@abraemer](#):
>
> the docs of your package

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!

---

<div class="post-metadata">

### Author: ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)
#### Post date: [June 5, 2024, 12:15pm UTC](https://discourse.julialang.org/t/drwatson-common-code-as-module-issue/115203/12 "2024-06-05T12:15:02Z")

</div>

> [@Datseris](#):
>
> 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 🙂  
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 😃
