Reading versions of a package from unpacked registry tarball

With the old-style git clone registry, I could find the latest version of a package by reading the Versions.toml file in the unpacked registry directory structure:

function latest_version(pkgname::AbstractString)
    path = joinpath(DEPOT_PATH[1], "registries", "General", first(pkgname,1), pkgname, "Versions.toml")
    return maximum(VersionNumber.(keys(Pkg.TOML.parse(read(path, String)))))
end

How would I extract the latest version of a package from a tarball registry?
Is there an existing function for this? Do I need to unpack the registry first or can I read the tarball directly?

1 Like

If you’re fine with depending on Pkg internals, this should do it:

using Pkg

function latest_version(pkgname::AbstractString)
    registry = only(filter(r -> r.name == "General", Pkg.Registry.reachable_registries()))
    pkg = only(filter(pkg -> pkg.name == pkgname, collect(values(registry.pkgs))))
    return maximum(keys(Pkg.Registry.registry_info(pkg).version_info))
end
2 Likes

Thanks Gunnar!