Skip to content

Commit

Permalink
Merge pull request #1 from ericphanson/eph/osi
Browse files Browse the repository at this point in the history
add `is_osi_approved`
  • Loading branch information
ericphanson authored Feb 11, 2021
2 parents 7c2f16f + 23ce74b commit 0b8d6a4
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 7 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
[![Build Status](https://github.com/ericphanson/LicenseCheck.jl/workflows/CI/badge.svg)](https://github.com/ericphanson/LicenseCheck.jl/actions)
[![Coverage](https://codecov.io/gh/ericphanson/LicenseCheck.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/ericphanson/LicenseCheck.jl)

Exports a single Julia function `licensecheck` which wraps some of the functionality of the Go library [licensecheck](https://github.com/google/licensecheck) which takes a single string argument `text` and returns a vector of the names of licenses (in fact, the "license ID"s) matched in `text` and the percent of the text covered by these matches. See the docstring of `licensecheck` for more details.
This package exposes some simple license-checking capabilities in Julia.

* Exports a Julia function `licensecheck` which wraps some of the functionality of the Go library [licensecheck](https://github.com/google/licensecheck). This function takes a single string argument `text` and returns a vector of the names of licenses (in fact, the SPDX identifiers of the licenses) matched in `text` and the percent of the text covered by these matches.
* Also exports `is_osi_approved`, which given an [SDPX 3.10 identifier](https://spdx.dev/ids/), checks if the corresponding license is [OSI approved](https://opensource.org/licenses).

See the docstrings for more details.

Note that the licensecheck library is available under a BSD-3-Clause license (<https://github.com/google/licensecheck/blob/v0.3.1/LICENSE>), while the wrapping code here is MIT licensed.

Expand All @@ -14,6 +19,9 @@ julia> using LicenseCheck

julia> text = read(joinpath(pkgdir(LicenseCheck), "LICENSE"), String);

julia> licensecheck(text)
julia> results = licensecheck(text)
(licenses = ["MIT"], percent_covered = 98.82352941176471)

julia> all(is_osi_approved, results.licenses)
true
```
101 changes: 101 additions & 0 deletions generate_osi_list/Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# This file is machine-generated - editing it directly is not advised

[[Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[HTTP]]
deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets", "URIs"]
git-tree-sha1 = "942c1a9c750bbe79912b7bd060a420932afd35b8"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "0.9.3"

[[IniFile]]
deps = ["Test"]
git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8"
uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f"
version = "0.5.0"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[JSON3]]
deps = ["Dates", "Mmap", "Parsers", "StructTypes", "UUIDs"]
git-tree-sha1 = "961ef1c3e5c8a595d5bec270a9007429ef12ed10"
uuid = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
version = "1.5.1"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[MbedTLS]]
deps = ["Dates", "MbedTLS_jll", "Random", "Sockets"]
git-tree-sha1 = "1c38e51c3d08ef2278062ebceade0e46cefc96fe"
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
version = "1.0.3"

[[MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[Parsers]]
deps = ["Dates"]
git-tree-sha1 = "50c9a9ed8c714945e01cd53a21007ed3865ed714"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.0.15"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[StructTypes]]
deps = ["Dates", "UUIDs"]
git-tree-sha1 = "65a43f5218197bc7091b76bc273a5e323a1d7b0d"
uuid = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
version = "1.2.3"

[[Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[URIs]]
git-tree-sha1 = "7855809b88d7b16e9b029afd17880930626f54a2"
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
version = "1.2.0"

[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
3 changes: 3 additions & 0 deletions generate_osi_list/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
7 changes: 7 additions & 0 deletions generate_osi_list/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# README

The code in [`generate.jl`](./generate.jl) generates the file `src/OSI_LICENSES.jl` by
parsing the SDPX 3.10 list of OSI approved licenses, which itself is available under a
Creative Commons Attribution 3.0 (SPDX License ID CC-BY-3.0) license.

This code was run on Julia 1.6-rc1 (and so the Manifest is valid for that version of Julia).
25 changes: 25 additions & 0 deletions generate_osi_list/generate.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using JSON3, HTTP

url = "https://raw.githubusercontent.com/spdx/license-list-data/v3.10/json/licenses.json"
r = HTTP.request("GET", url)
spdx = JSON3.read(String(r.body))

@assert spdx.licenseListVersion == "3.10"

osi_licenses = sort!([lic.licenseId
for lic in spdx.licenses
if lic.isOsiApproved && !lic.isDeprecatedLicenseId])

open(joinpath(@__DIR__, "..", "src", "OSI_LICENSES.jl"); write=true) do io
header = """
# THIS FILE IS MACHINE-GENERATED
# See `../generate_osi_list` for more information."""
start = "const OSI_LICENSES = Set(["
spaces = " "^textwidth(start)
println(io, header)
println(io, start, "\"", osi_licenses[1], "\",")
for id in osi_licenses[2:(end - 1)]
println(io, spaces, "\"", id, "\",")
end
return println(io, spaces, "\"", osi_licenses[end], "\"])")
end
32 changes: 28 additions & 4 deletions src/LicenseCheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ module LicenseCheck

using licensecheck_jll: licensecheck_jll

export licensecheck
export licensecheck, is_osi_approved

include("OSI_LICENSES.jl")

"""
licensecheck(text::String) -> @NamedTuple{licenses::Vector{String}, percent_covered::Float64}
Returns a vector of the names of licenses (in fact, the "license ID"s) matched in `text` and the percent of the text covered by these matches.
Returns a vector of the names of licenses (more specifically, the SPDX 3.10 license identifiers) matched in `text` and the percent of the text covered by these matches.
The full list of license IDs is located at <https://github.com/google/licensecheck/blob/v0.3.1/licenses/README.md>, and includes the SDPX 3.10 licenses, <https://github.com/spdx/license-list-data/tree/v3.10/text>.
The full list of license IDs is located at [https://github.com/google/licensecheck/blob/v0.3.1/licenses/README.md](https://github.com/google/licensecheck/blob/v0.3.1/licenses/README.md), and includes the SDPX 3.10 licenses, [https://github.com/spdx/license-list-data/tree/v3.10/text](https://github.com/spdx/license-list-data/tree/v3.10/text).
This provides some of the functionality of `licensecheck.Scan` in the original Go library (<https://github.com/google/licensecheck>).
This provides some of the functionality of `licensecheck.Scan` in the original Go library ([https://github.com/google/licensecheck](https://github.com/google/licensecheck)).
## Example
Expand All @@ -32,4 +34,26 @@ function licensecheck(text::String)
percent_covered=percent_covered)
end

"""
is_osi_approved(spdx_identifier::String) -> Bool
Checks if a [SDPX 3.10 identifier](https://spdx.dev/ids/) is
[OSI approved](https://opensource.org/licenses) by checking against an autogenerated list.
!!! warning
Note that [`licensecheck`](@ref) understands a larger number of licenses than
SDPX 3.10, and can output results which are not SDPX 3.10 identifiers.
Such licenses will yield `is_osi_approved(name) == false` regardless of
their OSI standing.
## Example
```julia
julia> is_osi_approved("MIT")
true
```
"""
is_osi_approved(spdx_identifier::String) = spdx_identifier OSI_LICENSES

end
120 changes: 120 additions & 0 deletions src/OSI_LICENSES.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# THIS FILE IS MACHINE-GENERATED
# See `../generate_osi_list` for more information.
const OSI_LICENSES = Set(["0BSD",
"AAL",
"AFL-1.1",
"AFL-1.2",
"AFL-2.0",
"AFL-2.1",
"AFL-3.0",
"AGPL-3.0-only",
"AGPL-3.0-or-later",
"APL-1.0",
"APSL-1.0",
"APSL-1.1",
"APSL-1.2",
"APSL-2.0",
"Apache-1.1",
"Apache-2.0",
"Artistic-1.0",
"Artistic-1.0-Perl",
"Artistic-1.0-cl8",
"Artistic-2.0",
"BSD-1-Clause",
"BSD-2-Clause",
"BSD-2-Clause-Patent",
"BSD-3-Clause",
"BSD-3-Clause-LBNL",
"BSL-1.0",
"CAL-1.0",
"CAL-1.0-Combined-Work-Exception",
"CATOSL-1.1",
"CDDL-1.0",
"CECILL-2.1",
"CNRI-Python",
"CPAL-1.0",
"CPL-1.0",
"CUA-OPL-1.0",
"ECL-1.0",
"ECL-2.0",
"EFL-1.0",
"EFL-2.0",
"EPL-1.0",
"EPL-2.0",
"EUDatagrid",
"EUPL-1.1",
"EUPL-1.2",
"Entessa",
"Fair",
"Frameworx-1.0",
"GPL-2.0-only",
"GPL-2.0-or-later",
"GPL-3.0-only",
"GPL-3.0-or-later",
"HPND",
"IPA",
"IPL-1.0",
"ISC",
"Intel",
"LGPL-2.0-only",
"LGPL-2.0-or-later",
"LGPL-2.1-only",
"LGPL-2.1-or-later",
"LGPL-3.0-only",
"LGPL-3.0-or-later",
"LPL-1.0",
"LPL-1.02",
"LPPL-1.3c",
"LiLiQ-P-1.1",
"LiLiQ-R-1.1",
"LiLiQ-Rplus-1.1",
"MIT",
"MPL-1.0",
"MPL-1.1",
"MPL-2.0",
"MPL-2.0-no-copyleft-exception",
"MS-PL",
"MS-RL",
"MirOS",
"Motosoto",
"MulanPSL-2.0",
"Multics",
"NASA-1.3",
"NCSA",
"NGPL",
"NPOSL-3.0",
"NTP",
"Naumen",
"Nokia",
"OCLC-2.0",
"OFL-1.1",
"OFL-1.1-RFN",
"OFL-1.1-no-RFN",
"OGTSL",
"OSET-PL-2.1",
"OSL-1.0",
"OSL-2.0",
"OSL-2.1",
"OSL-3.0",
"PHP-3.0",
"PHP-3.01",
"PostgreSQL",
"Python-2.0",
"QPL-1.0",
"RPL-1.1",
"RPL-1.5",
"RPSL-1.0",
"RSCPL",
"SISSL",
"SPL-1.0",
"SimPL-2.0",
"Sleepycat",
"UCL-1.0",
"UPL-1.0",
"Unlicense",
"VSL-1.0",
"W3C",
"Watcom-1.0",
"Xnet",
"ZPL-2.0",
"Zlib"])
7 changes: 6 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dorian_gray = """
There is no such thing as a moral or an immoral book. Books are well
written, or badly written. That is all."""

@testset "LicenseCheck.jl" begin
@testset "`licensecheck`" begin
result = licensecheck(MIT)
@test result.licenses == ["MIT"]
@test result.percent_covered 100.0 atol = 2
Expand All @@ -77,3 +77,8 @@ dorian_gray = """
100 * (length(MIT) + length(Latex2e)) /
(length(dorian_gray) + length(MIT) + length(Latex2e)) atol = 5
end

@testset "`is_osi_approved`" begin
@test is_osi_approved("MIT") == true
@test is_osi_approved("ABC") == false
end

2 comments on commit 0b8d6a4

@ericphanson
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/29846

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" 0b8d6a4f6d2518d08c90f600adc5081e3280ceb9
git push origin v0.1.0

Please sign in to comment.