Pkg.jl icon indicating copy to clipboard operation
Pkg.jl copied to clipboard

API request: installable versions from package name

Open fonsp opened this issue 4 years ago • 5 comments

I could not find a way to do the following, without using internal API:

Which versions (if any?) of a package (by name) can be installed from a reachable registry?

Use cases in https://github.com/fonsp/Pluto.jl/pull/844 include (screenshots attached):

Current implementation

I use internal API to find all registries, then internal Pkg.Types.read_registry to parse it, and then internal API to iterate and query the entries matching a package name.

Difference with https://github.com/JuliaLang/Pkg.jl/issues/11

Issue #11 should respect compatibility bounds of a given environment, which is one step further than this issue.

fonsp avatar Jun 09 '21 11:06 fonsp

The API (while still internal) should be better in 1.7. It would be something like:

using UUIDs

registry = Pkg.Registry.RegistryInstance("/home/kc/.julia/registries/General")

uuids_with_name = Pkg.Registry.uuids_from_name(registry, "Pluto")

d = Dict{UUID, Set{VersionNumber}}()
for uuid in uuids_with_name
   pkg_info = Pkg.Registry.registry_info(registry[uuid])
   d[uuid] = keys(pkg_info.version_info)
end

which here gives you a dictionary mapping each package with the name "Pluto" (remember, a registry can have multiple packages with the same name) to its set of versions.

https://github.com/JuliaLang/Pkg.jl/blob/89746e96bd0b239a2b729788e6873529657bbcb2/src/Registry/registry_instance.jl#L42-L56

is useful to look at.

KristofferC avatar Jun 09 '21 11:06 KristofferC

Are any changes in the past year useful here? This is still a big future-proof-problem for Pluto

fonsp avatar May 10 '22 12:05 fonsp

Does

using UUIDs, Pkg

registries = Pkg.Registry.reachable_registries()

d = Dict{UUID, Set{VersionNumber}}()

for registry in registries
    uuids_with_name = Pkg.Registry.uuids_from_name(registry, "Pluto")
    for uuid in uuids_with_name
        pkg_info = Pkg.Registry.registry_info(registry[uuid])
        d[uuid] = keys(pkg_info.version_info)
    end
end

work for you?

KristofferC avatar May 10 '22 14:05 KristofferC

Yes perfect! Do you think we can make reachable_registries, uuids_from_name and registry_info public API?

fonsp avatar May 10 '22 14:05 fonsp

Not really, but you can use the https://github.com/GunnarFarneback/RegistryInstances.jl package:

The whole purpose of RegistryInstances is to provide the RegistryInstance abstraction without relying on Pkg internals.

KristofferC avatar May 10 '22 14:05 KristofferC