# Organizing local Julia code into modules and/or packages

**URL:** <https://discourse.julialang.org/t/organizing-local-julia-code-into-modules-and-or-packages/48350>\
**Category:** General Usage\
**Tags:** package-manager, modules, code-organization\
**Created:** [October 14, 2020, 8:54am UTC](https://discourse.julialang.org/t/organizing-local-julia-code-into-modules-and-or-packages/48350 "2020-10-14T08:54:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niclas\_Wiberg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niclas_wiberg/32/19063_2.png) [@Niclas\_Wiberg](https://discourse.julialang.org/u/Niclas_Wiberg)\
**Post date:** [October 14, 2020, 8:54am UTC](https://discourse.julialang.org/t/organizing-local-julia-code-into-modules-and-or-packages/48350/1 "2020-10-14T08:54:30Z")

</div>

I’m trying to understand how to best work with local julia modules.

Our project is in C++ but we use Julia for testing, partly because it is convenient to generate and verify the complex input/output data we are dealing with. The Julia code is complex enough to organize it in multiple modules. The Julia code is placed inside the project’s git repo, since it is quite specific to this project.

Currently, each Julia module is its own package, in its own folder inside the project repo. Then there is a top-level project environment that have all packages as dependencies.

The packages could however not be added to the project environment using Pkg.add(path), because Pkg.add() expects each package to be its own git repository. Instead each package was added using Pkg.develop(path). This works with code loading and in particular with Revise.

However this seems to work only if the project environment’s Manifest.toml file is checked in to the project repo along with the Project.toml file. The reason being that the path information is stored in Manifest.toml and not in Project.toml. However, I was under the impression that Manifest.toml files should not be checked in, but rather re-generated locally.

My question is whether this setup is reasonable. How are others working in similar scenarios? Is it “right” to use packages for local modules like this, or should packages only be seen as a tool to distribute modules on their own?

Best regards,

Niclas Wiberg

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [October 14, 2020, 9:18am UTC](https://discourse.julialang.org/t/organizing-local-julia-code-into-modules-and-or-packages/48350/2 "2020-10-14T09:18:30Z")

</div>

Seems like a perfectly fine setup, the top-level project that you describe:

> [@Niclas\_Wiberg](#):
>
> Then there is a top-level project environment that have all packages as dependencies.

is more of a standalone “application” and for such things it is good to include the manifest.

---

<div class="post-metadata">

**Author:** ![Niclas\_Wiberg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niclas_wiberg/32/19063_2.png) [@Niclas\_Wiberg](https://discourse.julialang.org/u/Niclas_Wiberg)\
**Post date:** [October 14, 2020, 9:19am UTC](https://discourse.julialang.org/t/organizing-local-julia-code-into-modules-and-or-packages/48350/3 "2020-10-14T09:19:58Z")

</div>

Thanks!

Niclas

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [October 14, 2020, 10:36am UTC](https://discourse.julialang.org/t/organizing-local-julia-code-into-modules-and-or-packages/48350/4 "2020-10-14T10:36:40Z")

</div>

I do a similar thing for those projects ( like papers ) that won’t be public while I’m developing them. I have a directory where I put modules and proto-packages that I `dev` .

This works great unless I forget to get rid of manifest.toml (with paths that only make sense on my dropbox account) before I put the modules out there when I publish. I learned this the hard way when someone tried to reproduce my results and failed thanks to a path in the manifest.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [October 14, 2020, 10:50am UTC](https://discourse.julialang.org/t/organizing-local-julia-code-into-modules-and-or-packages/48350/5 "2020-10-14T10:50:52Z")

</div>

> [@ctkelley](#):
>
> This works great unless I forget to get rid of manifest.toml (with paths that only make sense on my dropbox account) before I put the modules out there when I publish. I learned this the hard way when someone tried to reproduce my results and failed thanks to a path in the manifest.

If you use relative paths in your Manifest, this shouldn’t be a problem.

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [October 14, 2020, 11:13am UTC](https://discourse.julialang.org/t/organizing-local-julia-code-into-modules-and-or-packages/48350/6 "2020-10-14T11:13:59Z")

</div>

I could edit the manifest to do that, but it’s simpler to put it in .gitignore so nobody but me will ever see it. I did this automatically with packages to CI would work, but forgot with a module. That’s how I got burned.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 14, 2020, 11:21am UTC](https://discourse.julialang.org/t/organizing-local-julia-code-into-modules-and-or-packages/48350/7 "2020-10-14T11:21:18Z")

</div>

> [@ctkelley](#):
>
> I could edit the manifest to do that, but it’s simpler to put it in .gitignore so nobody but me will ever see it.

But if you don’t publish your manifest, how can someone reproduce your results (the manifest stores the version of all packages)?

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [October 14, 2020, 11:30am UTC](https://discourse.julialang.org/t/organizing-local-julia-code-into-modules-and-or-packages/48350/8 "2020-10-14T11:30:13Z")

</div>

Sorry, Misspoke. I publish the manifest with papers for reproducability and try and avoid my local stuff when I do that. That’s generally easy because by that time I’ve moved the files anyhow.

For notebooks and packages/modules under development, where the target audience is students and reviewers of the publications, I find it better to leave it out rather than edit the manifest. When I got busted it was a reviewer who noticed the problems in the manifest. The reviewer deleted the file and all went well.
