xiaodai
xiaodai

Reputation: 16004

Julia: Is there a way to find the latest possible version number of a package?

It is common for my install packages to be not at the latest version due to dependency restrictions. However, I would like a way to determine if I have the latest possible version of a package e.g. by looking into the General registry. Is there a programmatic way to achieve that in Julia?

Upvotes: 2

Views: 221

Answers (1)

Bogumił Kamiński
Bogumił Kamiński

Reputation: 69879

You can try this under Julia 1.4.2:

julia> using Pkg

julia> function max_ver_number(pkgname::AbstractString)
           path = joinpath(DEPOT_PATH[1], "registries", "General",
                           first(pkgname, 1), pkgname, "Versions.toml")
           maximum(VersionNumber.(keys(Pkg.TOML.parse(read(path, String)))))
       end
max_ver_number (generic function with 1 method)

julia> max_ver_number("DataFrames")
v"0.21.4"

julia> max_ver_number("CSV")
v"0.7.1"

This code assumes that before running this you updated the local copy of general registry.

Note that here I assume that only DEPOT_PATH[1] is checked (so it is not fully general). For example this will fail for stdlib, e.g.:

julia> max_ver_number("Statistics")
ERROR: SystemError: opening file "/home/bkamins/.julia/registries/General/S/Statistics/Versions.toml": No such file or directory

However, I assume that for typical use cases what is proposed should be enough.

Upvotes: 1

Related Questions