Look up UUID of package by name in the General registry

julia> import TOML

julia> function lookup(name)
           # Look up Registry.toml files in depots
           tomlfiles = String[]
           for d in DEPOT_PATH
               regs = joinpath(d, "registries")
               if isdir(regs)
                   for r in readdir(regs)
                       toml = joinpath(regs, r, "Registry.toml")
                       if isfile(toml)
                           push!(tomlfiles, toml)
                       end
                   end
               end
           end
           
           # Look up uuids in toml files
           uuids = Base.UUID[]
           for f in tomlfiles
               toml = TOML.parsefile(f)
               if haskey(toml, "packages")
                   for (k, v) in toml["packages"]
                       if v["name"] == name
                           push!(uuids, Base.UUID(k))
                       end
                   end
               end
           end
           return uuids
       end
lookup (generic function with 1 method)

julia> lookup("Literate")
1-element Vector{Base.UUID}:
 UUID("98b081ad-f1c9-55d3-8b20-4c87d4299306")
2 Likes