Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia - getting the version number of my module

Tags:

package

julia

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?

like image 517
dpac Avatar asked Mar 08 '20 11:03

dpac


2 Answers

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).

like image 80
pfitzseb Avatar answered Oct 13 '22 01:10

pfitzseb


Possibly -

using Pkg
Pkg.TOML.parse(read("Project.toml", String))["version"]

-> "0.0.1"

like image 44
daycaster Avatar answered Oct 13 '22 01:10

daycaster