Revise.jl
Revise.jl copied to clipboard
[feature request] recursive includet
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).
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. (SeeRevise.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.…
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.
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?
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 Thank you for your comment, I understood.
Let's leave this open, so we can reconsider it once we get experience with includet
for the new Revise.
Is extending includet
now a possibility, following #497 merge?