Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] recursive includet #518

Open
AtsushiSakai opened this issue Jul 30, 2020 · 8 comments
Open

[feature request] recursive includet #518

AtsushiSakai opened this issue Jul 30, 2020 · 8 comments
Labels
wishlist Feature requests

Comments

@AtsushiSakai
Copy link

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).

@ffevotte
Copy link
Collaborator

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.

@AtsushiSakai
Copy link
Author

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.

@ffevotte
Copy link
Collaborator

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?

@timholy
Copy link
Owner

timholy commented Aug 6, 2020

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).

@AtsushiSakai
Copy link
Author

@timholy Thank you for your comment, I understood.

@timholy
Copy link
Owner

timholy commented Aug 6, 2020

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

@timholy timholy reopened this Aug 6, 2020
@timholy timholy added the wishlist Feature requests label Sep 17, 2020
@nrontsis
Copy link

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

@tecosaur
Copy link

tecosaur commented Feb 4, 2025

2c from me: I think it would be nice if includet also mapped include calls to includet in the loaded AST. If it can be done non-hackily (like the mapexpr argument of include), it seems like the behavior one would expect at a glance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wishlist Feature requests
Projects
None yet
Development

No branches or pull requests

5 participants