# Is there a way to know if \`Revise\` is enabled?

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-know-if-revise-is-enabled/110379>\
**Category:** General Usage\
**Tags:** question, revise\
**Created:** [February 18, 2024, 5:59pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-know-if-revise-is-enabled/110379 "2024-02-18T17:59:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tortar](https://avatars.discourse-cdn.com/v4/letter/t/6bbea6/32.png) [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Post date:** [February 18, 2024, 5:59pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-know-if-revise-is-enabled/110379/1 "2024-02-18T17:59:00Z")

</div>

Is it possible to know if when I’m executing some code it is being tracked by Revise.jl?

For example say I have a function where I want to do something different based on this condition e.g. in pseudocode:

```julia
function foo()
    if revise_enabled()
        do_1()
    else
        do_2()
    end
end

```

if this is possible it will probably rely on some internal detail I think though

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [February 18, 2024, 6:49pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-know-if-revise-is-enabled/110379/2 "2024-02-18T18:49:23Z")

</div>

To try to answer your question directly, I will need more information about what context you are trying to check for `Revise`.

If you are in a script or the REPL, you might might try check if the `Revise` `isdefined`.

```julia-repl
julia> isdefined(Main, :Revise)
false

julia> using Revise

julia> isdefined(Main, :Revise)
true

```

In the more general case, you could replace `Main` with `@ __MODULE__ `.

```julia-repl
julia> module Foo
           println(isdefined(@ __MODULE__ , :Revise))
       end
false
Main.Foo

julia> module Foo
           using Revise
           println(isdefined(@ __MODULE__ , :Revise))
       end
WARNING: replacing module Foo.
true
Main.Foo

julia> isdefined(Main, :Revise)
false

```

Checking if `Revise` is enabled is just the first step though. Do you want to refer to some `Revise` function within that `if` statement?

More likely than not, what you actually want is a [package extension](https://pkgdocs.julialang.org/v1/creating-packages/#Conditional-loading-of-code-in-packages-(Extensions)). This will load some code if `Revise` and your package is detected.

Depending on what you want to do, we may need Revise.jl’s UUID: `"295af30f-e4ad-537b-8983-00126c2a3abe"`.

> <https://github.com/timholy/Revise.jl/blob/dbbeb3594a4ea3eebd861e8ceea8fc746efc0f82/Project.toml#L2>

```julia-repl
julia> const revise_uuid = Base.UUID("295af30f-e4ad-537b-8983-00126c2a3abe")
UUID("295af30f-e4ad-537b-8983-00126c2a3abe")

julia> const revise_pkgid = Base.PkgId(revise_uuid, "Revise")
Revise [295af30f-e4ad-537b-8983-00126c2a3abe]

julia> Base.loaded_modules[revise_pkgid]
Revise

```

---

<div class="post-metadata">

**Author:** ![Tortar](https://avatars.discourse-cdn.com/v4/letter/t/6bbea6/32.png) [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Post date:** [February 18, 2024, 6:56pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-know-if-revise-is-enabled/110379/3 "2024-02-18T18:56:38Z")

</div>

thanks, this is helpful, let’s say we are in the package scenario, is there a way to know if `Revise` is tracking that package and not just if it was loaded (but maybe it is tracking something else)?

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [February 18, 2024, 7:06pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-know-if-revise-is-enabled/110379/4 "2024-02-18T19:06:49Z")

</div>

We may need to get into Pkg.jl’s internals:

> **[Developer reference · Revise.jl](https://timholy.github.io/Revise.jl/stable/dev_reference/#Internal-state-management)**
>
> Documentation for Revise.jl.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [February 18, 2024, 7:51pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-know-if-revise-is-enabled/110379/5 "2024-02-18T19:51:48Z")

</div>

Thank you, specifically it appears to be the [watched\_files](https://timholy.github.io/Revise.jl/stable/dev_reference/#Revise.watched_files) global.

Just one question: On my Mac, it is `Dict{String, Revise.WatchList}`, with keys being directories. According to Revise docs,

> FreeBSD and NFS-mounted systems should watch files, otherwise we prefer to watch directories.

So where the watched files list goes on those systems?

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [February 18, 2024, 9:51pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-know-if-revise-is-enabled/110379/6 "2024-02-18T21:51:07Z")

</div>

The following can check if the module runs “under Revise” - except I don’t know if it would work under FreeBSD and the like.

```julia
module Inrev

const revise_uuid = Base.UUID("295af30f-e4ad-537b-8983-00126c2a3abe")
const revise_pkgid = Base.PkgId(revise_uuid, "Revise")

function checkrev()
    revise_pkgid in keys(Base.loaded_modules) || return false 
    d = @ __DIR__ 
    f = splitpath(@ __FILE__ )[end]

    watched_files = getproperty(Main.Revise, :watched_files)
    d in keys(watched_files) || return false

    trackedfiles = watched_files[d].trackedfiles
    return f in keys(trackedfiles)
end

macro inrev(args...)
    println(checkrev())
end
export @inrev

end 

```
