Revise.jl icon indicating copy to clipboard operation
Revise.jl copied to clipboard

[feature request] recursive includet

Open AtsushiSakai opened this issue 3 years ago • 7 comments

First of all, thank you so much for great package!!. The includet looks like just watching specified script even if the script includes other scripts. If it is possible, it would be great that includet can watch scripts recursively (watching both the top script and included scripts by the top script).

AtsushiSakai avatar Jul 30 '20 12:07 AtsushiSakai

Hello, as stated in the documentation for includet, this way of tracking files is dedicated to individual scripts, as opposed to packages containing several files. As such, and quoting the doc:

includet is deliberately non-recursive, so if filename loads any other files, they will not be automatically tracked. (See Revise.track to set it up manually.)

However, as stated in this comment, it is possible to manually track included files. One way to do that could look like the following. Assuming that foo.jl includes bar.jl:

julia> using Revise

# No file has been included anywhere yet
julia> Revise.included_files
Tuple{Module,String}[]

# Track foo.jl; since includet is not recursive, bar.jl is not tracked
julia> includet("/tmp/foo.jl")

# ...but it is listed in the included files
julia> Revise.included_files
1-element Array{Tuple{Module,String},1}:
 (Main, "/tmp/bar.jl")

# manually track it
julia> for (mod, file) in Revise.included_files
           Revise.track(mod, file)
       end

# Now both foo.jl and bar.jl are tracked
julia> Revise.watched_files
Dict{String,Revise.WatchList} with 5 entries:
  "/tmp"                                                        => WatchList(1.59618e9, Dict{String,Base.PkgId}("foo.jl"=>Main [top-level],"bar.jl"=>Main [top-level]))
  "/home/francois/.julia/packages/OrderedCollections/P6ntV/src" => WatchList(1.59618e9, Dict{String,Base.PkgId}("dict_sorting.jl"=>OrderedCollections [bac558e1-5e72-5ebc-8fee-abe8a469f55d…
  "/home/francois/.julia/packages/LoweredCodeUtils/ynJHb/src"   => WatchList(1.59618e9, Dict{String,Base.PkgId}("LoweredCodeUtils.jl"=>LoweredCodeUtils [6f1432cf-f94c-5a45-995e-cdbf5db27b…
  "/home/francois/.julia/packages/CodeTracking/q52fp/src"       => WatchList(1.59618e9, Dict{String,Base.PkgId}("utils.jl"=>CodeTracking [da1fd8a2-8d9e-5ec2-8556-3022fb5608a2],"pkgfiles.j…
  "/home/francois/.julia/packages/JuliaInterpreter/fh7AN/src"   => WatchList(1.59618e9, Dict{String,Base.PkgId}("utils.jl"=>JuliaInterpreter [aa1ae85d-cabe-5617-a682-6adf51b2e16a],"types.…

ffevotte avatar Jul 31 '20 06:07 ffevotte

Oh. great. I created a new function based on your comment, that is what I want!!. Thank you so much!!

using Revise
function recursive_includet(filename)
    includet(filename)
    for (mod, file) in Revise.included_files
        Revise.track(mod, file)
    end
end

So, my feature request would be includet with recursive option like: includet(filename, recursive=true) This will work as same as the upper function.

AtsushiSakai avatar Jul 31 '20 11:07 AtsushiSakai

Please be aware that a new element gets pushed to Revise.included_files each time a file is included (whatever the reason). The semantics you want is more likely something like:

using Revise
function recursive_includet(filename)
    already_included = copy(Revise.included_files)
    includet(filename)
    newly_included = setdiff(Revise.included_files, already_included)
    for (mod, file) in newly_included
        Revise.track(mod, file)
    end
end

So, my feature request would be includet with recursive option like: includet(filename, recursive=true) This will work as same as the upper function.

@timholy What would you think about such an API change?

ffevotte avatar Jul 31 '20 12:07 ffevotte

includet is still pretty hacky; Revise works much better for packages than scripts. I definitely don't want to extend includet before #497 lands (which should allow includet to become less hacky).

timholy avatar Aug 06 '20 10:08 timholy

@timholy Thank you for your comment, I understood.

AtsushiSakai avatar Aug 06 '20 11:08 AtsushiSakai

Let's leave this open, so we can reconsider it once we get experience with includet for the new Revise.

timholy avatar Aug 06 '20 11:08 timholy

Is extending includet now a possibility, following #497 merge?

nrontsis avatar Oct 19 '22 12:10 nrontsis