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

Clarification on adding infilitrate to startup.jl #112

Closed
TorkelE opened this issue Mar 22, 2024 · 2 comments
Closed

Clarification on adding infilitrate to startup.jl #112

TorkelE opened this issue Mar 22, 2024 · 2 comments

Comments

@TorkelE
Copy link

TorkelE commented Mar 22, 2024

On the main page there is a recommendation to add

macro autoinfiltrate(cond=true)
    pkgid = Base.PkgId(Base.UUID("5903a43b-9cc3-4c30-8d17-598619ec4e9b"), "Infiltrator")
    if !haskey(Base.loaded_modules, pkgid)
        try
            Base.eval(Main, :(using Infiltrator))
        catch err
            @error "Cannot load Infiltrator.jl. Make sure it is included in your environment stack."
        end
    end
    i = get(Base.loaded_modules, pkgid, nothing)
    lnn = LineNumberNode(__source__.line, __source__.file)

    if i === nothing
        return Expr(
            :macrocall,
            Symbol("@warn"),
            lnn,
            "Could not load Infiltrator.")
    end

    return Expr(
        :macrocall,
        Expr(:., i, QuoteNode(Symbol("@infiltrate"))),
        lnn,
        esc(cond)
    )
end

to your startup page. If I understand right, what this does is that I can just run @autoinfiltrate whenever I would run @infilitrate, with the same effect, and just that I would not have to run using Infiltrate, and then in my code @infilitrate. Is the advantage with this that I only run using Infiltrate when I actually need it (i.e., this is an alternative to adding using Infiltrate in startup.jl, and then running infiltrate.

Does this make sense? Sorry, I was a bit uncertain of what the next mean, this is what I think will happen, but wanted to confirm what I do, before I add additional code to startup.jl.

@pfitzseb
Copy link
Member

Yes, that's correct.
The benefits of that solution are somewhat dubious, given that Infiltrator loads in ~3ms and doesn't export a whole bunch of symbols, but it's an option.
I would generally recommend just using Infiltrator in your startup.jl.

@TorkelE
Copy link
Author

TorkelE commented Mar 27, 2024

thanks, that is a really useful clarification! I got a bit confused by all the code what was going on. I am just using using Infiltrator now, that seems to work well. Thansk a lot!

@TorkelE TorkelE closed this as completed Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants