5

Is it possible to use @infiltrate from Infiltrator.jl to inspect a function in a package without adding Infiltrator to the Project.toml file? I have Infiltrator installed in my 1.7 environment, so I was hoping that stacked environments would come into play, but apparently not:

julia> using PackageFoo
[ Info: Precompiling PackageFoo [b7d5e62f-924e-4906-b2b5-430ba4531d91]
ERROR: LoadError: UndefVarError: @infiltrate not defined
1

3 Answers 3

3

The current working solution is to do

Main.@infiltrate

from within your package.

I keep

using Infiltrator

in my startup.jl so that it's always pulled from the 1.7 environment regardless of which package or other environment I'm using.

Note that you need to first load your package without that line, then rely on Revise to notice when you add the Main.@infiltrate line to your package.

Sign up to request clarification or add additional context in comments.

Comments

1

One possibility would be to use a system image. In the following code I use PackageCompiler.jl to create a system image that includes Infiltrator.jl, that way Main, the top-level module, will always include Infiltrator as a submodule:

julia> using PackageCompiler

julia> create_sysimage(["Infiltrator"]; sysimage_path="debug_image.so")

I save the new system image to debug_image.so and then start julia with this image instead of the default one, the NoInfil project does not have Infiltrator in its deps:

$ julia --project=NoInfil -Jdebug_image.so                                                                                                                                                                                                                                 [21:52:23]
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.1 (2021-12-22)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using NoInfil

julia> NoInfil.greet()
Infiltrating greet() at NoInfil.jl:3:

infil>

This is what NoInfil/src/NoInfil.jl looks like:

module NoInfil

greet() = (Main.Infiltrator.@infiltrate; print("Hello World!"))

end # module

1 Comment

This is a useful answer, but I don't think I will mark it as the accepted answer. I guess the straightforward answer is "No, there is no easy way to use Infiltrator on package code without adding Infiltrator to the Project.toml file."
0

Probably https://stackoverflow.com/a/73252860/500314 is the way to go.

Another option is described in the Infiltrator readme. Instead of calling Main.@infiltrate directly, one can use the more verbose:

if isdefined(Main, :Infiltrator)
    Main.infiltrate(@__MODULE__, Base.@locals, @__FILE__, @__LINE__)
end

This runtime check avoids errors during package precompilation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.