Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the RegistryInstances package #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ version = "0.6.2"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
RegistryInstances = "2792f1a3-b283-48e8-9a74-f99dce5104f3"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Compat = "3.26.0"
TOML = "1.0"
julia = "1.5"
RegistryInstances = "0.1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
31 changes: 9 additions & 22 deletions src/PkgDeps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ using REPL
using TOML: parsefile
using UUIDs
using Compat
using RegistryInstances: RegistryInstances, PkgEntry, RegistryInstance

export PkgEntry, RegistryInstance
export NoUUIDMatch, PackageNotInRegistry
export users, reachable_registries
export direct_dependencies, dependencies

include("pkg_entry.jl")
include("registry_instance.jl")
include("exceptions.jl")
include("utilities.jl")

Expand Down Expand Up @@ -45,27 +44,15 @@ function reachable_registries(
depots::Union{String, Vector{String}}=Base.DEPOT_PATH,
kwargs...
)
registries = RegistryInstance[]
registries = RegistryInstances.reachable_registries(; depots)

if depots isa String
depots = [depots]
end

for d in depots
isdir(d) || continue
reg_dir = joinpath(d, "registries")
isdir(reg_dir) || continue

for name in readdir(reg_dir)
if isempty(registry_names) || name in registry_names
file = joinpath(reg_dir, name, "Registry.toml")
isfile(file) || continue
push!(registries, RegistryInstance(joinpath(reg_dir, name)))
end
if isempty(registry_names)
registries
else
filter(registries) do r
r.name in registry_names
end
end

return registries
end
reachable_registries(registry_name::String; depots::Union{String, Vector{String}}=Base.DEPOT_PATH, kwargs...) = reachable_registries([registry_name]; depots=depots, kwargs...)
reachable_registries(; depots::Union{String, Vector{String}}=Base.DEPOT_PATH, kwargs...) = reachable_registries([]; depots=depots, kwargs...)
Expand Down Expand Up @@ -97,10 +84,10 @@ function users(
downstream_dependencies = String[]

for rego in registries
for (pkg, pkg_entry) in rego.pkgs
for pkg_entry in values(rego.pkgs)
deps = direct_dependencies(pkg_entry)
if any(isequal(uuid), values(deps))
push!(downstream_dependencies, pkg)
push!(downstream_dependencies, pkg_entry.name)
end
end
end
Expand Down
7 changes: 0 additions & 7 deletions src/pkg_entry.jl

This file was deleted.

36 changes: 0 additions & 36 deletions src/registry_instance.jl

This file was deleted.

30 changes: 16 additions & 14 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function _find_latest_pkg_entry(pkg_name::Union{AbstractString, Missing}, pkg_uu
entries = PkgEntry[]

for rego in registries
for (name, entry) in rego.pkgs
for entry in values(rego.pkgs)
if !ismissing(pkg_name)
pkg_name == name || continue
pkg_name == entry.name || continue
end
if !ismissing(pkg_uuid)
pkg_uuid == entry.uuid || continue
Expand Down Expand Up @@ -74,9 +74,9 @@ Get the package name from a UUID
"""
function _get_pkg_name(uuid::UUID, registries)
for rego in registries
for (pkg_name, pkg_entry) in rego.pkgs
for pkg_entry in values(rego.pkgs)
if pkg_entry.uuid == uuid
return pkg_name
return pkg_entry.name
end
end
end
Expand All @@ -103,18 +103,20 @@ function _get_pkg_uuid(
end

function _get_pkg_uuid(pkg_name::String, registry::RegistryInstance)
if haskey(registry.pkgs, pkg_name)
return registry.pkgs[pkg_name].uuid
else
alt_packages = _find_alternative_packages(pkg_name, collect(keys(registry.pkgs)))
for pkg_entry in values(registry.pkgs)
if pkg_entry.name == pkg_name
return pkg_entry.uuid
end
end

warning = "The package $(pkg_name) was not found in the $(registry.name) registry."
alt_packages = _find_alternative_packages(pkg_name, [entry.name for entry in values(registry.pkgs)])

if !isempty(alt_packages)
warning *= "\nPerhaps you meant: $(string(alt_packages))"
end
warning = "The package $(pkg_name) was not found in the $(registry.name) registry."

warning *= "\nOr you can search in another registry using `users(\"$(pkg_name)\", \"OtherRegistry\")`"
throw(PackageNotInRegistry(warning))
if !isempty(alt_packages)
warning *= "\nPerhaps you meant: $(string(alt_packages))"
end

warning *= "\nOr you can search in another registry using `users(\"$(pkg_name)\", \"OtherRegistry\")`"
throw(PackageNotInRegistry(warning))
end
5 changes: 3 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using PkgDeps
using Test
using UUIDs
using RegistryInstances: registry_info

const DEPOT = joinpath(@__DIR__, "resources")
const GENERAL_REGISTRY = only(reachable_registries("General"; depots=DEPOT))
Expand Down Expand Up @@ -67,12 +68,12 @@ all_registries = reachable_registries(; depots=DEPOT)
entry = PkgDeps._find_latest_pkg_entry("ClashPkg"; registries=all_registries)
# General has a later version of `ClashPkg`
@test entry.uuid == clashpkg_general_uuid
@test entry.repo == "https://path.to.repo/"
@test registry_info(entry).repo == "https://path.to.repo/"

# No conflict here, so it should just find the right one
entry = PkgDeps._find_latest_pkg_entry("Case4"; registries=all_registries)
@test entry.uuid == UUID("172f9e6e-38ba-42e1-abf1-05c2c32c0454")
@test entry.repo == "https://path.to.repo/"
@test registry_info(entry).repo == "https://path.to.repo/"

entry = PkgDeps._find_latest_pkg_entry(missing, UUID("172f9e6e-38ba-42e1-abf1-05c2c32c0454"); registries=all_registries)
@test entry.name == "Case4"
Expand Down