How to find out the version of a package from its module

The only way to get the version of the currently loaded package (as opposed to what’s in the active environment) is something like

julia> pkgversion(m::Module) = Pkg.TOML.parsefile(joinpath(dirname(string(first(methods(m.eval)).file)), "..", "Project.toml"))["version"]
pkgversion (generic function with 1 method)

julia> pkgversion(Atom)
"0.12.10"

Needs some error handling, of course. Also hits the file system, but I don’t think there’s a way around that anyways.

8 Likes