-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Crawl registry (→ to rm restriction "Only works for pkgs in active pr…
…oject") Close #5 finally! 🍾🥂 missing: more proper testing, code cleanup (there's some non dry in proj toml parsing and keys "deps")
- Loading branch information
Showing
14 changed files
with
185 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ Internals | |
|
||
```@docs | ||
depgraph | ||
packages_in_active_manifest | ||
is_jll | ||
is_in_stdlib | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
|
||
using TOML | ||
using Base: active_project | ||
|
||
is_in_project(pkg, proj = active_project()) = | ||
isfile(proj) && (name(proj) == pkg || pkg in keys(all_deps(proj))) | ||
|
||
name(proj_path) = name(dict(proj_path)) | ||
dict(proj_path) = TOML.parsefile(proj_path) | ||
name(toml::Dict) = get(toml, "name", nothing) | ||
|
||
all_deps(project) = begin | ||
mani = manifest(project) | ||
if !isfile(mani) | ||
return Dict() | ||
end | ||
@static if VERSION ≥ v"1.7" | ||
deps = TOML.parsefile(mani)["deps"] | ||
else | ||
deps = TOML.parsefile(mani) | ||
end | ||
end | ||
manifest(project) = replace(project, "Project.toml" => "Manifest.toml") | ||
|
||
direct_deps_from_project(proj = active_project()) = begin | ||
proj_dict = dict(proj) | ||
proj_name = name(proj_dict) | ||
all_deps_ = all_deps(proj) | ||
direct_deps(pkgname) = | ||
if pkgname == proj_name | ||
get(proj_dict, "deps", []) |> keys | ||
else | ||
deps_with_name = all_deps_[pkgname] | ||
check_only(deps_with_name) | ||
dep_dict = only(deps_with_name) | ||
get(dep_dict, "deps", []) | ||
end | ||
direct_deps | ||
end | ||
check_only(packages_with_same_name) = @assert( | ||
length(packages_with_same_name) == 1, | ||
""" | ||
Different packages with same name not supported | ||
(The offending packages:) | ||
$packages_with_same_name | ||
""" | ||
) | ||
|
||
# The above is poop: we want dep tree of entire thing, also if no top specified | ||
# no name. then there's multiple roots, sure (or take as name, the directory) | ||
# | ||
|
||
|
||
""" | ||
packages_in_active_manifest() | ||
Read and parse the `Manifest.toml` of the given project, and return its | ||
'deps' table (as a dictionary indexed by package names). | ||
Every entry in this dictionary is a list. This is for when multiple | ||
packages would share the same name. | ||
## Example: | ||
```jldoctest; filter = r" => .*\$"m | ||
julia> using PkgGraph.Internals | ||
julia> packages = packages_in_active_manifest(); | ||
julia> only(packages["PkgGraph"]) | ||
Dict{String, Any} with 4 entries: | ||
"deps" => ["DefaultApplication", "TOML", "URIs"] | ||
"uuid" => "f9c1b9e4-72e8-4a14-ade5-14f45fc35f11" | ||
"version" => "0.1.0" | ||
"path" => "C:\\Users\\tfiers\\.julia\\dev\\PkgGraph" | ||
``` | ||
""" | ||
packages_in_active_manifest() = all_deps(active_project()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Pkg.Registry: reachable_registries, | ||
uuids_from_name, | ||
init_package_info!, | ||
initialize_uncompressed!, | ||
JULIA_UUID | ||
|
||
|
||
const reg = first(reachable_registries()) | ||
@assert reg.name == "General" | ||
|
||
name(uuid::UUID) = | ||
if uuid in STDLIB_UUIDS | ||
STDLIB[uuid] | ||
elseif uuid in keys(reg.pkgs) | ||
reg.pkgs[uuid].name | ||
else | ||
error() | ||
end | ||
|
||
uuid(name::AbstractString) = | ||
if name in STDLIB_NAMES | ||
findfirst(==(name), STDLIB) | ||
else | ||
uuids = uuids_from_name(reg, name) | ||
if isempty(uuids) | ||
error("Package `$name` not found") | ||
elseif length(uuids) > 1 | ||
error("Multiple packages with the same name (`$name`) not supported") | ||
else | ||
return only(uuids) | ||
end | ||
end | ||
|
||
direct_deps_from_registry(pkg) = begin | ||
if pkg in STDLIB_NAMES | ||
return direct_deps_of_stdlib_pkg(pkg) | ||
end | ||
pkgentry = reg.pkgs[uuid(pkg)] | ||
p = init_package_info!(pkgentry) | ||
versions = keys(p.version_info) | ||
v = maximum(versions) | ||
initialize_uncompressed!(p, [v]) | ||
vinfo = p.version_info[v] | ||
compat_info = vinfo.uncompressed_compat | ||
# ↪ All direct deps will be here, even if author didn't them | ||
# [compat] (their versionspec will just be "*"). | ||
direct_dep_uuids = collect(keys(compat_info)) | ||
filter!(!=(JULIA_UUID), direct_dep_uuids) | ||
return name.(direct_dep_uuids) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using UUIDs | ||
using TOML | ||
|
||
stdlib() = begin | ||
packages = Dict{UUID,String}() | ||
for path in readdir(Sys.STDLIB; join = true) | ||
# ↪ `join` gets us complete paths | ||
if isdir(path) | ||
toml = proj_dict(path) | ||
push!(packages, UUID(toml["uuid"]) => toml["name"]) | ||
end | ||
end | ||
packages | ||
end | ||
proj_dict(pkgdir) = TOML.parsefile(proj_file(pkgdir)) | ||
proj_file(pkgdir) = joinpath(pkgdir, "Project.toml") | ||
|
||
const STDLIB = stdlib() | ||
const STDLIB_UUIDS = keys(STDLIB) | ||
const STDLIB_NAMES = values(STDLIB) | ||
|
||
direct_deps_of_stdlib_pkg(name) = begin | ||
pkgdir = joinpath(Sys.STDLIB, name) | ||
d = proj_dict(pkgdir) | ||
keys(get(d, "deps", [])) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters