Is there an API for resolving the name of a package (a string) to the UUID of a package (in a specific registry, defaulting to General)? The package is not necessarily installed in the local environment.
[this has been asked earlier, see here and here. I am aware of the possibility of installing the package and then looking in the manifest, or digging the UUID out from Github, looking for a solution within Julia.]
You can certainly retrieve it with non-public Pkg functions, but if you want a stable solution, this is the best I can propose:
using RegistryInstances: reachable_registries
function find_uuid(registry_name, package_name)
registry = only(filter(r -> r.name == registry_name, reachable_registries()))
return only(key for (key, value) in registry.pkgs if value.name == package_name)
end
It covers the second line of my function. Goes to show how well I know my own package.
(To be clear I haven’t written much more than the README. The code is a snapshot of the Pkg code for handling registries, specifically intended to make it publically available without locking Pkg itself to a specific API.)
I may be misremembering something, but isn’t it in general permitted to have the same name multiple times in a registry? Or is the mapping to a UUID guaranteed unique within one registry?
The Pkg and registry design allows multiple packages with the same name in one registry. The current registry tooling does not support it but it can be added when needed. The General registry will most likely never allow it.