I have startup.jl file that I’m mostly happy with. Any time Julia is updated and I start an interactive session without explicitly activating some environment, startup.jl adds a few key packages to the base environment. A few of these packages are auto-imported via using in every interactive session. I use a let block to avoid polluting the Main module namespace with any variables used to accomplish these tasks. However, I need to import Pkg to obtain its functionality for these same tasks, and therefore every interactive session has the Pkg module imported. Is there a way to avoid this? Listing of startup.jl follows…
if isinteractive()
# If not already present, add selected packages to base (@v1.x) package environment.
# Automatically use some of these in every REPL session.
let # Avoid polluting global namespace
import Pkg
auto_used_packages = [:Revise, :PkgOnlineHelp, :OhMyREPL]
manually_used_packages = [:Plots, :BenchmarkTools]
vstr = string(VERSION)
dots = findall('.', vstr)
vstr = "v" * vstr[begin:dots[2]-1]
baseenvpath = joinpath(first(DEPOT_PATH), "environments", vstr, "Project.toml")
if Pkg.project().path == baseenvpath
for package in union(auto_used_packages, manually_used_packages)
(String(package) in keys(Pkg.project().dependencies)) || Pkg.add(String(package))
end
end
for package in auto_used_packages
@eval using $package
end
end
end
For me having Pkg available is actually a feature but if you don’t want it then simply wrap the bits that use Pkg into a module so the import doesn’t leak.
This seemed quite awkward to me, but I was a bit surprised to find there isn’t a lot of convenience functions for working with version numbers. Is there anything better than
Technically yes, but you can choose some other name to avoid any practical issues e.g.
module var"##super-secret-setup-space"
import Pkg
# rest of setup...
end
This won’t show up in any auto-complete and so is for practical purposes invisible I’d say.
Just checked: names(Main) and varinfo(Main) also do not show it.