Can a package detect whether it was imported in the REPL vs inside another package?

Continuing the discussion from [ANN] UseAll.jl – Temporarily Demodularize Julia Code:

Even outside of the specific context of what makes sense for that UseAll package, that seems like an interesting question by itself.

Not really, no.

module MyPackage
function __init__()
    if !isinteractive()
        error("MyPackage is intended for interactive REPL use only.")
    end
end
end

This won’t prevent OtherPackage from accidentally making MyPackage a dependency, but at least would break OtherPackage’s CI, thus also preventing it’s registration.

1 Like