Pkg.jl
Pkg.jl copied to clipboard
API request: installable versions from package name
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):
- autocomplete all available packages when typing
using Plo<TAB> - show that a package name is not found in the registry
- show which version will be installed (though this also requires https://github.com/JuliaLang/Pkg.jl/issues/11)
- show whether a package has a more recent version than the one installed
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.
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.
Are any changes in the past year useful here? This is still a big future-proof-problem for Pluto
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?
Yes perfect! Do you think we can make reachable_registries, uuids_from_name and registry_info public API?
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.