I am writing a package for Julia and within the package I would like to be able to print the my package current version number. I can of course do that manually but I was looking for a way to read it directly from the module. the version number is written in the Project.toml file, but I have not been able to find a way to read it from the code. Any ideas?
You could use something like
julia> using Pkg
julia> loadedversion(m::Module) = VersionNumber(Pkg.TOML.parsefile(joinpath(string(first(methods(m.eval)).file), "..", "..", "Project.toml"))["version"])
loadedversion (generic function with 1 method)
julia> loadedversion(Atom)
v"0.12.8"
Some error handling would be prudent, of course, but that will give you the version of a package that's actually loaded (instead of the one specified in the current environment).
Possibly -
using Pkg
Pkg.TOML.parse(read("Project.toml", String))["version"]
-> "0.0.1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With