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
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
JuliaSyntax = "70703baa-626e-46a2-a12c-08ffd08c73b4"
Legolas = "741b9549-f6ed-4911-9fbf-4a1c0c97f0cd"
LicenseCheck = "726dbf0d-6eb6-41af-b36c-cd770e0f00cc"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
RegistryInstances = "2792f1a3-b283-48e8-9a74-f99dce5104f3"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
Expand All @@ -26,10 +28,12 @@ AbstractTrees = "0.4"
CodecZlib = "0.7"
Git = "1.2.1"
GitHub = "5.4"
Legolas = "0.5"
JSON3 = "1.5.1"
JuliaSyntax = "0.4"
Legolas = "0.5"
LicenseCheck = "0.2"
OrderedCollections = "1"
PrecompileTools = "1.2"
RegistryInstances = "0.1"
julia = "1.6"

Expand Down
14 changes: 14 additions & 0 deletions src/PackageAnalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ using JuliaSyntax
using JuliaSyntax: @K_str
using Legolas
using Legolas: @schema, @version
using OrderedCollections
using PrecompileTools

# We wrap `registry_info` for thread-safety, so we don't want to pull into the namespace here
using RegistryInstances: RegistryInstances, reachable_registries, PkgEntry
Expand All @@ -24,6 +26,7 @@ using RegistryInstances: RegistryInstances, reachable_registries, PkgEntry
export find_package, find_packages, find_packages_in_manifest
# Ways to analyze them
export analyze, analyze_manifest, analyze_packages, LineCategories
export PackageCollection

##
# Borrowed from
Expand Down Expand Up @@ -163,6 +166,10 @@ function PackageV1(name, uuid, repo;
end

function Base.show(io::IO, p::PackageV1)
compact = get(io, :compact, false)::Bool
if compact
return print(io, PackageV1, "(\"", p.name, "\", …)")
end
body = """
PackageV1 $(p.name):
* repo: $(p.repo)
Expand Down Expand Up @@ -355,6 +362,8 @@ function Base.show(io::IO, d::Trunk)
print(io, ")")
end

include("package_collection.jl")

# Provides methods to obtain a `PkgSource`
include("find_packages.jl")

Expand All @@ -380,5 +389,10 @@ include("count_loc.jl")

include("deprecated_schemas.jl")

@compile_workload begin
p = analyze(PackageAnalyzer)
sprint(show, MIME"text/plain"(), p)
nothing
end

end # module
69 changes: 69 additions & 0 deletions src/package_collection.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
struct PackageCollection <: AbstractVector{PackageV1}
pkgs::Vector{PackageV1}
end

Base.getindex(p::PackageCollection, i::Int) = p.pkgs[i]
Base.size(p::PackageCollection) = size(p.pkgs)

function _to_underscore(n::Integer)
x = Iterators.partition(digits(n), 3)
return join(reverse(join.(reverse.(x))), '_')
end


function Base.show(io::IO, ::MIME"text/plain", c::PackageCollection)
n = length(c)
summary(io, c)
println(io)
l_src = l_ext = l_test = l_docs = l_readme = l_src_docstring = 0

for p in c
l_src += sum_julia_loc(p, "src")
l_ext += sum_julia_loc(p, "ext")
l_test += sum_julia_loc(p, "test")
l_docs += sum_doc_lines(p)
l_readme += sum_readme_lines(p)
l_src_docstring += sum_docstrings(p, "src")
end

p_ext = @sprintf("%.1f", 100 * l_ext / (l_test + l_src + l_ext))
p_test = @sprintf("%.1f", 100 * l_test / (l_test + l_src + l_ext))
p_docs = @sprintf("%.1f", 100 * l_docs / (l_docs + l_src + l_ext))

p_ext = @sprintf("%.1f", 100 * l_ext / (l_test + l_src + l_ext))
p_test = @sprintf("%.1f", 100 * l_test / (l_test + l_src + l_ext))
p_docs = @sprintf("%.1f", 100 * l_docs / (l_docs + l_src + l_ext))

body = """
* Source code
* Total Julia source code: $(_to_underscore(l_src)) lines
* Total Julia extension code: $(_to_underscore(l_ext)) lines ($(p_ext)% of `test` + `src` + `ext`)
* Julia code test code: $(_to_underscore(l_test)) lines ($(p_test)% of `test` + `src` + `ext`)
* Lines of documentation: $(_to_underscore(l_docs)) lines ($(p_docs)% of `docs` + `src` + `ext`)
"""

n = l_src_docstring + l_readme
p_docstrings = @sprintf("%.1f", 100 * n / (n + l_src))
body *= """
* Total lines of documentation in README & docstrings: $(n) lines ($(p_docstrings)% of README + `src`)
"""
print(io, strip(body))

licenses = OrderedDict{String, Vector{String}}()
for p in c
for lic in p.license_files
for license in lic.licenses_found
v = get!(Vector{String}, licenses, license)
push!(v, p.name)
end
end
end
sort!(licenses; by=((k,v),) -> length(v))
println(io, "\n* Licenses")
for (k, v) in licenses
sort!(unique!(v))
print(io, " * $k ($(length(v))): ")
join(io, v, ", ")
println(io)
end
end
6 changes: 3 additions & 3 deletions src/parallel.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
analyze_packages(pkg_entries; auth::GitHub.Authorization=github_auth(), sleep=0, root=mktempdir()) -> Vector{PackageV1}
analyze_packages(pkg_entries; auth::GitHub.Authorization=github_auth(), sleep=0, root=mktempdir()) -> PackageCollection


Analyze all packages in the iterable `pkg_entries`, using threads, storing their code in `root`
if it needs to be downloaded. Returns a `Vector{PackageV1}`.
if it needs to be downloaded. Returns a [`PackageCollection`](@ref), which can be used like a `Vector{PackageV1}`.

Each element of `pkg_entries` should be a valid input to [`analyze`](@ref).

Expand All @@ -24,5 +24,5 @@ function analyze_packages(pkg_entries; auth::GitHub.Authorization=github_auth(),
put!(outputs, (i, analyze(pkg; auth, sleep, root)))
end
close(outputs)
return last.(sort!(collect(outputs); by=first))
return PackageCollection(last.(sort!(collect(outputs); by=first)))
end