Skip to content
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: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PkgDependents"
uuid = "ae191fcf-7ec6-40a6-95c9-dedb80b28f91"
version = "0.1.2"
authors = ["ITensor developers <support@itensor.org> and contributors"]
version = "0.1.1"

[deps]
RegistryInstances = "2792f1a3-b283-48e8-9a74-f99dce5104f3"
Expand Down
22 changes: 11 additions & 11 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using PkgDependents: PkgDependents
using Documenter: Documenter, DocMeta, deploydocs, makedocs

DocMeta.setdocmeta!(PkgDependents, :DocTestSetup, :(using PkgDependents); recursive=true)
DocMeta.setdocmeta!(PkgDependents, :DocTestSetup, :(using PkgDependents); recursive = true)

include("make_index.jl")

makedocs(;
modules=[PkgDependents],
authors="ITensor developers <support@itensor.org> and contributors",
sitename="PkgDependents.jl",
format=Documenter.HTML(;
canonical="https://itensor.github.io/PkgDependents.jl",
edit_link="main",
assets=["assets/favicon.ico", "assets/extras.css"],
),
pages=["Home" => "index.md", "Reference" => "reference.md"],
modules = [PkgDependents],
authors = "ITensor developers <support@itensor.org> and contributors",
sitename = "PkgDependents.jl",
format = Documenter.HTML(;
canonical = "https://itensor.github.io/PkgDependents.jl",
edit_link = "main",
assets = ["assets/favicon.ico", "assets/extras.css"],
),
pages = ["Home" => "index.md", "Reference" => "reference.md"],
)

deploydocs(;
repo="github.com/ITensor/PkgDependents.jl", devbranch="main", push_preview=true
repo = "github.com/ITensor/PkgDependents.jl", devbranch = "main", push_preview = true
)
16 changes: 8 additions & 8 deletions docs/make_index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using Literate: Literate
using PkgDependents: PkgDependents

function ccq_logo(content)
include_ccq_logo = """
include_ccq_logo = """
```@raw html
<img class="display-light-only" src="assets/CCQ.png" width="20%" alt="Flatiron Center for Computational Quantum Physics logo."/>
<img class="display-dark-only" src="assets/CCQ-dark.png" width="20%" alt="Flatiron Center for Computational Quantum Physics logo."/>
```
"""
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
end

Literate.markdown(
joinpath(pkgdir(PkgDependents), "examples", "README.jl"),
joinpath(pkgdir(PkgDependents), "docs", "src");
flavor=Literate.DocumenterFlavor(),
name="index",
postprocess=ccq_logo,
joinpath(pkgdir(PkgDependents), "examples", "README.jl"),
joinpath(pkgdir(PkgDependents), "docs", "src");
flavor = Literate.DocumenterFlavor(),
name = "index",
postprocess = ccq_logo,
)
16 changes: 8 additions & 8 deletions docs/make_readme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using Literate: Literate
using PkgDependents: PkgDependents

function ccq_logo(content)
include_ccq_logo = """
include_ccq_logo = """
<picture>
<source media="(prefers-color-scheme: dark)" width="20%" srcset="docs/src/assets/CCQ-dark.png">
<img alt="Flatiron Center for Computational Quantum Physics logo." width="20%" src="docs/src/assets/CCQ.png">
</picture>
"""
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
end

Literate.markdown(
joinpath(pkgdir(PkgDependents), "examples", "README.jl"),
joinpath(pkgdir(PkgDependents));
flavor=Literate.CommonMarkFlavor(),
name="README",
postprocess=ccq_logo,
joinpath(pkgdir(PkgDependents), "examples", "README.jl"),
joinpath(pkgdir(PkgDependents));
flavor = Literate.CommonMarkFlavor(),
name = "README",
postprocess = ccq_logo,
)
2 changes: 1 addition & 1 deletion examples/README.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# # PkgDependents.jl
#
#
# [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://itensor.github.io/PkgDependents.jl/stable/)
# [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://itensor.github.io/PkgDependents.jl/dev/)
# [![Build Status](https://github.com/ITensor/PkgDependents.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/PkgDependents.jl/actions/workflows/Tests.yml?query=branch%3Amain)
Expand Down
144 changes: 72 additions & 72 deletions src/PkgDependents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,98 +3,98 @@ module PkgDependents
using RegistryInstances: RegistryInstances

function uuid_from_pkgname(
pkgname::String; registries=RegistryInstances.reachable_registries()
)
uuid_to_registrynames = Dict{Base.UUID,Vector{String}}()
for registry in registries
registry_uuids = RegistryInstances.uuids_from_name(registry, pkgname)
if !isempty(registry_uuids)
# There should only be one package with a given UUID in a given
# registry.
registry_uuid = only(registry_uuids)
if !haskey(uuid_to_registrynames, registry_uuid)
uuid_to_registrynames[registry_uuid] = [registry.name]
else
push!(uuid_to_registrynames[registry_uuid], registry.name)
end
pkgname::String; registries = RegistryInstances.reachable_registries()
)
uuid_to_registrynames = Dict{Base.UUID, Vector{String}}()
for registry in registries
registry_uuids = RegistryInstances.uuids_from_name(registry, pkgname)
if !isempty(registry_uuids)
# There should only be one package with a given UUID in a given
# registry.
registry_uuid = only(registry_uuids)
if !haskey(uuid_to_registrynames, registry_uuid)
uuid_to_registrynames[registry_uuid] = [registry.name]
else
push!(uuid_to_registrynames[registry_uuid], registry.name)
end
end
end
end
if !isone(length(uuid_to_registrynames))
# Multiple UUIDs exist across different registries.
# Prefer the version in the general registry.
for (uuid, registrynames) in pairs(uuid_to_registrynames)
if "General" ∈ registrynames
return uuid
end
if !isone(length(uuid_to_registrynames))
# Multiple UUIDs exist across different registries.
# Prefer the version in the general registry.
for (uuid, registrynames) in pairs(uuid_to_registrynames)
if "General" ∈ registrynames
return uuid
end
end
end
end
return only(keys(uuid_to_registrynames))
return only(keys(uuid_to_registrynames))
end

function registryinstance_from_pkgname(
pkgname::String; registries=RegistryInstances.reachable_registries()
)
# Make sure the UUID is the same across registries.
# If multiple registries contain the package, select
# the one from General.
uuid = uuid_from_pkgname(pkgname; registries)
# Find the registries that have packages with this UUID.
registries′ = filter(registries) do registry
haskey(registry, uuid)
end
# Choose the registry with the largest registered version of
# this package.
return argmax(registries′) do registry
# Get the maximum version number registered in this registry.
return maximum(keys(RegistryInstances.registry_info(registry[uuid]).version_info))
end
pkgname::String; registries = RegistryInstances.reachable_registries()
)
# Make sure the UUID is the same across registries.
# If multiple registries contain the package, select
# the one from General.
uuid = uuid_from_pkgname(pkgname; registries)
# Find the registries that have packages with this UUID.
registries′ = filter(registries) do registry
haskey(registry, uuid)
end
# Choose the registry with the largest registered version of
# this package.
return argmax(registries′) do registry
# Get the maximum version number registered in this registry.
return maximum(keys(RegistryInstances.registry_info(registry[uuid]).version_info))
end
end

function registryinstance_from_registryname(
registryname::String; registries=RegistryInstances.reachable_registries()
)
which_registries = findall(registries) do registry
return registry.name == registryname
end
return registries[only(which_registries)]
registryname::String; registries = RegistryInstances.reachable_registries()
)
which_registries = findall(registries) do registry
return registry.name == registryname
end
return registries[only(which_registries)]
end

# Get the dependencies and weak dependencies of a package.
function dependencies(
pkgname::String; weakdeps=true, registries=RegistryInstances.reachable_registries()
)
uuid = uuid_from_pkgname(pkgname; registries)
registry = registryinstance_from_pkgname(pkgname; registries)
pkginfo = RegistryInstances.registry_info(registry[uuid])
latest_version = maximum(keys(pkginfo.version_info))
# Use pkginfo.compat since it generally includes Deps and WeakDeps,
# pkginfo.deps doesn't include WeakDeps.
deps = String[]
for (k, v) in pairs(pkginfo.compat)
if latest_version ∈ k
append!(deps, collect(keys(v)))
pkgname::String; weakdeps = true, registries = RegistryInstances.reachable_registries()
)
uuid = uuid_from_pkgname(pkgname; registries)
registry = registryinstance_from_pkgname(pkgname; registries)
pkginfo = RegistryInstances.registry_info(registry[uuid])
latest_version = maximum(keys(pkginfo.version_info))
# Use pkginfo.compat since it generally includes Deps and WeakDeps,
# pkginfo.deps doesn't include WeakDeps.
deps = String[]
for (k, v) in pairs(pkginfo.compat)
if latest_version ∈ k
append!(deps, collect(keys(v)))
end
end
end
return deps
return deps
end

to_registry(registry::RegistryInstances.RegistryInstance) = registry
to_registry(registryname::String) = registryinstance_from_registryname(registryname)

function dependents(
pkgname::String; registries=RegistryInstances.reachable_registries(), weakdeps=true
)
registries = to_registry.(registries)
deps = String[]
for registry in registries
for (_, pkgentry′) in registry
pkgname′ = pkgentry′.name
if pkgname ∈ dependencies(pkgname′; weakdeps, registries)
push!(deps, pkgname′)
end
pkgname::String; registries = RegistryInstances.reachable_registries(), weakdeps = true
)
registries = to_registry.(registries)
deps = String[]
for registry in registries
for (_, pkgentry′) in registry
pkgname′ = pkgentry′.name
if pkgname ∈ dependencies(pkgname′; weakdeps, registries)
push!(deps, pkgname′)
end
end
end
end
return deps
return deps
end

end
80 changes: 41 additions & 39 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,62 @@ using Suppressor: Suppressor
const pat = r"(?:--group=)(\w+)"
arg_id = findfirst(contains(pat), ARGS)
const GROUP = uppercase(
if isnothing(arg_id)
get(ENV, "GROUP", "ALL")
else
only(match(pat, ARGS[arg_id]).captures)
end,
if isnothing(arg_id)
get(ENV, "GROUP", "ALL")
else
only(match(pat, ARGS[arg_id]).captures)
end,
)

"match files of the form `test_*.jl`, but exclude `*setup*.jl`"
function istestfile(fn)
return endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup")
return endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup")
end
"match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl`"
function isexamplefile(fn)
return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup")
return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup")
end

@time begin
# tests in groups based on folder structure
for testgroup in filter(isdir, readdir(@__DIR__))
if GROUP == "ALL" || GROUP == uppercase(testgroup)
groupdir = joinpath(@__DIR__, testgroup)
for file in filter(istestfile, readdir(groupdir))
filename = joinpath(groupdir, file)
@eval @safetestset $file begin
include($filename)
# tests in groups based on folder structure
for testgroup in filter(isdir, readdir(@__DIR__))
if GROUP == "ALL" || GROUP == uppercase(testgroup)
groupdir = joinpath(@__DIR__, testgroup)
for file in filter(istestfile, readdir(groupdir))
filename = joinpath(groupdir, file)
@eval @safetestset $file begin
include($filename)
end
end
end
end
end
end

# single files in top folder
for file in filter(istestfile, readdir(@__DIR__))
(file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion
@eval @safetestset $file begin
include($file)
# single files in top folder
for file in filter(istestfile, readdir(@__DIR__))
(file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion
@eval @safetestset $file begin
include($file)
end
end
end

# test examples
examplepath = joinpath(@__DIR__, "..", "examples")
for (root, _, files) in walkdir(examplepath)
contains(chopprefix(root, @__DIR__), "setup") && continue
for file in filter(isexamplefile, files)
filename = joinpath(root, file)
@eval begin
@safetestset $file begin
$(Expr(
:macrocall,
GlobalRef(Suppressor, Symbol("@suppress")),
LineNumberNode(@__LINE__, @__FILE__),
:(include($filename)),
))
# test examples
examplepath = joinpath(@__DIR__, "..", "examples")
for (root, _, files) in walkdir(examplepath)
contains(chopprefix(root, @__DIR__), "setup") && continue
for file in filter(isexamplefile, files)
filename = joinpath(root, file)
@eval begin
@safetestset $file begin
$(
Expr(
:macrocall,
GlobalRef(Suppressor, Symbol("@suppress")),
LineNumberNode(@__LINE__, @__FILE__),
:(include($filename)),
)
)
end
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion test/test_aqua.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ using Aqua: Aqua
using Test: @testset

@testset "Code quality (Aqua.jl)" begin
Aqua.test_all(PkgDependents)
Aqua.test_all(PkgDependents)
end
4 changes: 2 additions & 2 deletions test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ using PkgDependents: dependencies, dependents
using Test: @test, @testset

@testset "PkgDependents" begin
@test "ZygoteRules" ∈ dependencies("Zygote")
@test "Flux" ∈ dependents("Zygote")
@test "ZygoteRules" ∈ dependencies("Zygote")
@test "Flux" ∈ dependents("Zygote")
end