# Basic Revise.jl usage when developing a module

**URL:** <https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140>\
**Category:** New to Julia\
**Tags:** module, revise\
**Created:** [December 30, 2018, 11:53pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140 "2018-12-30T23:53:10Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [December 30, 2018, 11:53pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/1 "2018-12-30T23:53:10Z")

</div>

I am having trouble running `Revise.jl` on my Windows machine. My workflow is as follows. On VSCode I am writing my Julia module. I also have the Julia REPL open separately.  
I’ve run the following code in my REPL

```julia
include("path/to/module")
using Revise
using .PackageName
a = foo() # foo() defined in PackageName

```

Now when I edit a function in `PackageName` in VSCode and switch back to the REPL, I was hoping that Revise would “reload” the module with the edited function. But this dosn’t seem to be the case. Am I missing something?

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [December 31, 2018, 1:51am UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/2 "2018-12-31T01:51:31Z")

</div>

I believe you need to use [`Revise.includet`](https://timholy.github.io/Revise.jl/stable/user_reference.html#Revise.includet) in this case. Or you could develop the package in `Pkg.devdir()` (or somewhere else on the `LOAD_PATH`) and Revise will find it automatically.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [December 31, 2018, 2:49am UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/3 "2018-12-31T02:49:27Z")

</div>

Recommended approach:

- ~~check out [this branch of PkgDev](https://github.com/JuliaLang/PkgDev.jl/pull/144)~~
- ~~navigate to where you want your package to live (I typically use `.julia/dev`)~~
- ~~within Julia do `using PkgDev; PkgDev.generate("PackageName", "MIT")` or whatever license you prefer.~~
- ~~`pkg> dev PackageName` to bring it into your environment (or `pkg> dev /path/to/PackageName` if you placed it somewhere other than your `.julia/dev` directory)~~
- As suggested below by @zygmuntszpak, create the package (here called `PackageName`) with [PkgTemplates](https://github.com/invenia/PkgTemplates.jl)
- `using PackageName`

Revise will work automatically. Your package is also ready to push up to GitHub, run Travis tests, etc.

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [December 31, 2018, 7:58am UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/4 "2018-12-31T07:58:50Z")

</div>

It is probably not relevant but I wonder if all this package creation process could not be even more standardized inside Julia in the future (avoiding “Recommend” and “I typically use”). If so, the IDE (atom, vscode,…) job for package creation would be easy and essentially reduced to a one click process (and you can switch between IDEs).

In C++, this kind of work is handled by IDEs like qtcreator or visual studio that generate a CMake project or equivalent setups. It is not convenient because it is not standard. I love to develop softs and libs but I always found configuration/environment/build/config management tool/ Testing tools/doc tools) so painful and boring to learn. Usually I consider the corresponding related “languages”/configuration file syntax (git, doxygen, cvs, travis, cmake,…) to be ugly.

Julia Pkg/doc/test approach is indeed a great improvement but I wonder if it could be even more standardized to the point where there is no more question about it 😉

---

<div class="post-metadata">

**Author:** ![zygmuntszpak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zygmuntszpak/32/2591_2.png) [@zygmuntszpak](https://discourse.julialang.org/u/zygmuntszpak)\
**Post date:** [December 31, 2018, 12:43pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/5 "2018-12-31T12:43:34Z")

</div>

You might want to check out: [GitHub - invenia/PkgTemplates.jl: Create new Julia packages, the easy way](https://github.com/invenia/PkgTemplates.jl)  
I found it makes the package creation process much easier and faster.

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 1, 2019, 3:51pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/6 "2019-01-01T15:51:45Z")

</div>

Thank you very much !  
Now the standardization question remains.

---

<div class="post-metadata">

**Author:** ![Zranz](https://avatars.discourse-cdn.com/v4/letter/z/90ced4/32.png) [@Zranz](https://discourse.julialang.org/u/Zranz)\
**Post date:** [September 5, 2019, 3:18pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/7 "2019-09-05T15:18:16Z")

</div>

I have a similar problem to the original question about tracking local modules, but I am not sure if the suggested approach (using PkgTemplates) applies to my case. I already created a package. Within that package I created a local module and I want to include that module and use it (and track it with revise). So creating a package within a package does not make sense, I guess.

What would be the recommended workflow in this case? Not have local modules within a package and directly include a script full of functions? Or is there a way to track the local module with Revise?

Thanks.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [September 5, 2019, 3:30pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/8 "2019-09-05T15:30:18Z")

</div>

It should Just Work; Revise has tests [for this very case](https://github.com/timholy/Revise.jl/blob/0426c895c6e1777e501709aa22ff0969141b37f2/test/runtests.jl#L492-L525).

---

<div class="post-metadata">

**Author:** ![Zranz](https://avatars.discourse-cdn.com/v4/letter/z/90ced4/32.png) [@Zranz](https://discourse.julialang.org/u/Zranz)\
**Post date:** [September 5, 2019, 3:57pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/9 "2019-09-05T15:57:01Z")

</div>

OK, I described my setup wrongly. Let me give a MWE. I have a project, not a package, and a script and a module inside the project. Let’s say the script is `MyProject.jl` and the module `Subroutines.jl`.

Contents of `MyProject.jl`:

```julia
include(joinpath(@ __DIR__ , "Subroutines.jl"))
using .Subroutines

greet() = print("Hello World!")

foo()

```

Contents of `Subroutines.jl`

```julia
module Subroutines
export foo
foo() = "foo"
end

```

If I change in `Subroutines.jl` `foo()="goo"`, Revise does not track the change, i.e., calling `foo()` does not return `"goo"`.

Thanks for your response!

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [September 5, 2019, 4:09pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/10 "2019-09-05T16:09:17Z")

</div>

Revise deliberately does _not_ track files loaded by `include`; otherwise it might, e.g., re-run all your tests every time you change a single line in one of your test scripts.

Revise _does_ track things loaded by `using/import` or `includet`. As the help for `includet` specifies, it is deliberately non-recursive.

Is there any reason not to load your method definitions with something like `using MyProject`? That is, turn `MyProject` into an actual “package”?

---

<div class="post-metadata">

**Author:** ![Zranz](https://avatars.discourse-cdn.com/v4/letter/z/90ced4/32.png) [@Zranz](https://discourse.julialang.org/u/Zranz)\
**Post date:** [September 5, 2019, 4:31pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/11 "2019-09-05T16:31:35Z")

</div>

Well, the project is not intended to be used as a package anywhere else, because it’s a folder where I process results, and does not export functions. I have several scripts to process results, and a single module that exports common subroutines to all scripts.

If I convert `MyProject` into a package then changes in `Subroutines.jl` are still not tracked. I change `MyProject.jl` into:

```julia
module MyProject

include(joinpath(@ __DIR__ , "Subroutines.jl"))
using .Subroutines

greet() = print("Hello World!")

foo()

end

```

I also add a `Project.toml` file and `dev` the package. If I later run the snippets of `MyProject.jl` with Juno, still changes in `Subroutines.jl` do not get tracked.

When I develop, I run snippets of code in Juno within the project/package, and I use local modules inside the project/package by first including them. Should I `includet` before using? Or is it that I cannot track changes of a module used inside a script? Does a module always need to be `dev`’ed and converted to a package in order to be tracked?

Thanks a lot for your continuous help.

---

<div class="post-metadata">

**Author:** ![Zranz](https://avatars.discourse-cdn.com/v4/letter/z/90ced4/32.png) [@Zranz](https://discourse.julialang.org/u/Zranz)\
**Post date:** [September 5, 2019, 5:56pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/12 "2019-09-05T17:56:05Z")

</div>

The way to get this workflow working would be to say `using MyProject` in the REPL, and then I can edit both `MyProject.jl` and `Subroutines.jl` and run statements within Juno (using shift+enter) in the main package file, and changes are tracked.

I think it would be nice though to be able to track local modules that explicitly have been called with `using`, regardless of them being `dev`’ed because they would need to be packages.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [September 5, 2019, 6:20pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/13 "2019-09-05T18:20:52Z")

</div>

> [@Zranz](#):
>
> I think it would be nice though to be able to track local modules that explicitly have been called with `using` , regardless of them being `dev` 'ed because they would need to be packages.

First, pull requests are always welcome 😄. I haven’t played with this workflow myself, but my concern is that if you say

```julia
include("file_that_defines_MyModule_and_maybe_some_other_stuff.jl")
using .MyModule

```

how do you get the list of files that `MyModule` depends on? Conversely there are well-established mechanisms if you say `using MyModule`.

---

<div class="post-metadata">

**Author:** ![Zranz](https://avatars.discourse-cdn.com/v4/letter/z/90ced4/32.png) [@Zranz](https://discourse.julialang.org/u/Zranz)\
**Post date:** [September 5, 2019, 6:31pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/14 "2019-09-05T18:31:10Z")

</div>

Mmmm, I don’t know. I started wrapping every file with functions I had in modules because I thought that was the recommended way to reuse code, both in packages and projects.

I can always remove the module call, and use `includet` within projects.

By mechanisms for getting list of files a package depends on, you refer to the `Project.toml` and `Manifest.toml` files?

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [September 5, 2019, 7:26pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/15 "2019-09-05T19:26:45Z")

</div>

Also the precompile header for compiled modules, and `Base.loaded_modules`.

---

<div class="post-metadata">

**Author:** ![akriegman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/akriegman/32/30573_2.png) [@akriegman](https://discourse.julialang.org/u/akriegman)\
**Post date:** [November 10, 2021, 10:36pm UTC](https://discourse.julialang.org/t/basic-revise-jl-usage-when-developing-a-module/19140/16 "2021-11-10T22:36:56Z")

</div>

Hey, I’m a bit late to this but I just want to share my solution. To use Revise with a module without having to wrap that module in a package, you can just add the folder to your `LOAD_PATH`:

```julia
push!(LOAD_PATH, pwd()) # or replace pwd() with whatever folder your module is in
using MyModule

```

I kind of wish the current working directory was in your `LOAD_PATH` by default. It seems like it’s discouraged to have a module that isn’t in a package, but I find there’s a real use case for this. For example when I need more structure than a single script can provide, but a package provides more structure than I need and I want to stay in my global package environment.
