From acaa72970e2dab23fa4145e800300cc1d842f61c Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Fri, 26 Feb 2021 00:44:13 +0100 Subject: [PATCH 1/2] wip `healthcheck` --- src/AnalyzeRegistry.jl | 71 +++++++++++++++++++++++++++++++++++------- src/count_loc.jl | 7 +++-- 2 files changed, 64 insertions(+), 14 deletions(-) diff --git a/src/AnalyzeRegistry.jl b/src/AnalyzeRegistry.jl index b5e0dcc..5594971 100644 --- a/src/AnalyzeRegistry.jl +++ b/src/AnalyzeRegistry.jl @@ -12,6 +12,7 @@ using Tokei_jll # count lines of code export general_registry, find_package, find_packages export analyze, analyze_from_registry, analyze_from_registry! +export healthcheck include("count_loc.jl") const LicenseTableEltype=@NamedTuple{license_filename::String, licenses_found::Vector{String}, license_file_percent_covered::Float64} @@ -106,19 +107,10 @@ function Base.show(io::IO, p::Package) * has documentation: $(p.docs) * has tests: $(p.runtests) """ - ci_services = (p.github_actions => "GitHub Actions", - p.travis => "Travis", - p.appveyor => "AppVeyor", - p.cirrus => "Cirrus", - p.circle => "Circle", - p.drone => "Drone CI", - p.buildkite => "Buildkite", - p.azure_pipelines => "Azure Pipelines", - p.gitlab_pipeline => "GitLab Pipeline", - ) - if any(first.(ci_services)) + ci = ci_services(p) + if any(first.(ci)) body *= " * has continuous integration: true\n" - for (k, v) in ci_services + for (k, v) in ci if k body *= " * $(v)\n" end @@ -130,6 +122,61 @@ function Base.show(io::IO, p::Package) print(io, strip(body)) end +function ci_services(p) + return (p.github_actions => "GitHub Actions", + p.travis => "Travis", + p.appveyor => "AppVeyor", + p.cirrus => "Cirrus", + p.circle => "Circle", + p.drone => "Drone CI", + p.buildkite => "Buildkite", + p.azure_pipelines => "Azure Pipelines", + p.gitlab_pipeline => "GitLab Pipeline") +end + +emojify(b::Bool) = b ? "☑" : "◻" + +function print_check(io, check, name, parens) + print(io, emojify(check), " ", name) + if check && !isempty(parens) + println(io, " (", parens, ")") + else + println(io) + end +end + +function healthcheck(p::Package) + body = sprint() do io + jl_test = count_loc(p.lines_of_code, "test", :Julia) + jl_src = count_loc(p.lines_of_code, "src", :Julia) + jl_doc = count_docs(p.lines_of_code) + println(io, p.name, ".jl") + print_check(io, jl_src > 5, "Has code", "$(jl_src) lines") + print_check(io, p.docs, "Has docs", "$(jl_doc) lines") + print_check(io, p.runtests && jl_test > 5, "Has tests", "$(jl_test) lines") + licenses = String[] + append!(licenses, p.licenses_in_project) + for lic in p.license_files + append!(licenses, lic.licenses_found) + end + print_check(io, !isempty(licenses) && any(is_osi_approved, licenses), "Has license(s)", "") + for lic in licenses + check = is_osi_approved(lic) + print(io, " $lic (") + if check + print(io, "✔ OSI-approved)") + else + print(io, "⨉ Not OSI-approved)") + end + println(io) + # print_check(io, check, "OSI: $lic", "") + end + services = [v for (k,v) in ci_services(p) if k] + print_check(io, !isempty(services), "Has CI", join(services, ", ")) + end + print(body) +end + """ general_registry() -> String diff --git a/src/count_loc.jl b/src/count_loc.jl index 67f50c4..e5c32ab 100644 --- a/src/count_loc.jl +++ b/src/count_loc.jl @@ -1,4 +1,4 @@ -function count_loc(dir) +function count_loc(dir::AbstractString) # we `cd` so that we get relative paths in the `tokei` output. # This makes it easy to process later, since we have uniform filepaths json = cd(dir) do @@ -54,4 +54,7 @@ function loc_update!(d, key, new) d[key] = (; files = prev.files + 1, code = prev.code + new.code, comments = prev.comments + new.comments, blanks = prev.blanks + new.blanks ) end -count_julia_loc(table, dir) = sum(row.code for row in table if row.directory == dir && row.language == :Julia; init=0) +count_julia_loc(table, dir) = count_loc(table, dir, :Julia) +count_loc(table, dir::AbstractString, language::Symbol) = sum(row.code for row in table if row.directory == dir && row.language == language; init=0) +count_loc(table, dir::AbstractString) = sum(row.code for row in table if row.directory == dir; init=0) +count_docs(table) = sum(row.code + row.comments for row in table if row.directory in ("docs", "doc"); init=0) From 2918d1dea4cb98449dddbf04dab6d3f7d5713411 Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Fri, 26 Feb 2021 00:52:59 +0100 Subject: [PATCH 2/2] tweak --- src/AnalyzeRegistry.jl | 54 ++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/AnalyzeRegistry.jl b/src/AnalyzeRegistry.jl index 5594971..52837e0 100644 --- a/src/AnalyzeRegistry.jl +++ b/src/AnalyzeRegistry.jl @@ -145,36 +145,34 @@ function print_check(io, check, name, parens) end end -function healthcheck(p::Package) - body = sprint() do io - jl_test = count_loc(p.lines_of_code, "test", :Julia) - jl_src = count_loc(p.lines_of_code, "src", :Julia) - jl_doc = count_docs(p.lines_of_code) - println(io, p.name, ".jl") - print_check(io, jl_src > 5, "Has code", "$(jl_src) lines") - print_check(io, p.docs, "Has docs", "$(jl_doc) lines") - print_check(io, p.runtests && jl_test > 5, "Has tests", "$(jl_test) lines") - licenses = String[] - append!(licenses, p.licenses_in_project) - for lic in p.license_files - append!(licenses, lic.licenses_found) - end - print_check(io, !isempty(licenses) && any(is_osi_approved, licenses), "Has license(s)", "") - for lic in licenses - check = is_osi_approved(lic) - print(io, " $lic (") - if check - print(io, "✔ OSI-approved)") - else - print(io, "⨉ Not OSI-approved)") - end - println(io) - # print_check(io, check, "OSI: $lic", "") +healthcheck(p::Package) = healthcheck(stdout, p) + +function healthcheck(io::IO, p::Package) + jl_test = count_loc(p.lines_of_code, "test", :Julia) + jl_src = count_loc(p.lines_of_code, "src", :Julia) + jl_doc = count_docs(p.lines_of_code) + println(io, p.name, ".jl") + print_check(io, jl_src > 5, "Has code", "$(jl_src) lines") + print_check(io, p.docs, "Has docs", "$(jl_doc) lines") + print_check(io, p.runtests && jl_test > 5, "Has tests", "$(jl_test) lines") + licenses = String[] + append!(licenses, p.licenses_in_project) + for lic in p.license_files + append!(licenses, lic.licenses_found) + end + print_check(io, !isempty(licenses) && any(is_osi_approved, licenses), "Has license(s)", "") + for lic in licenses + check = is_osi_approved(lic) + print(io, " $lic (") + if check + print(io, "✔ OSI-approved)") + else + print(io, "⨉ not OSI-approved)") end - services = [v for (k,v) in ci_services(p) if k] - print_check(io, !isempty(services), "Has CI", join(services, ", ")) + println(io) end - print(body) + services = [v for (k,v) in ci_services(p) if k] + print_check(io, !isempty(services), "Has CI", join(services, ", ")) end """