licensee 9.7.0 → 9.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/licensee/content_helper.rb +9 -1
- data/lib/licensee/matchers.rb +1 -0
- data/lib/licensee/matchers/cargo.rb +16 -0
- data/lib/licensee/project_files/package_manager_file.rb +9 -6
- data/lib/licensee/project_files/readme_file.rb +20 -11
- data/lib/licensee/version.rb +1 -1
- data/spec/licensee/content_helper_spec.rb +31 -6
- data/spec/licensee/matchers/cargo_matcher_spec.rb +48 -0
- data/spec/licensee/project_files/package_info_spec.rb +2 -0
- data/spec/licensee/project_files/{readme_spec.rb → readme_file_spec.rb} +17 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6da17475ba74d0aea6d92013e6d141cc88f0d400af3aa9d0be99947c551f3ad6
|
4
|
+
data.tar.gz: 654876f0d889688a13752497759d2856be48a8714667a167e9781f80b9f1eef1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 208fea169fb835f863d85ec6ac2bbcb87878c10e312938380fd262cfc3b3b7fe0e55b65d74cdd166a1c361d47d071ec5bfc785e4a7854031aa0855fc96105c54
|
7
|
+
data.tar.gz: 1c23cf247b226d85326ac7c9d388b22e228f07a13388d0e21cac091f6ca8fefd1c4b726448c13e44c429e83c828ef99b56cfaea5c39ae30ef22fc13655027d29
|
@@ -16,7 +16,7 @@ module Licensee
|
|
16
16
|
# A set of each word in the license, without duplicates
|
17
17
|
def wordset
|
18
18
|
@wordset ||= if content_normalized
|
19
|
-
content_normalized.scan(/
|
19
|
+
content_normalized.scan(/(?:\w(?:'s|(?<=s)')?)+/).to_set
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -79,6 +79,7 @@ module Licensee
|
|
79
79
|
string = strip_all_rights_reserved(string)
|
80
80
|
string, _partition, _instructions = string.partition(END_OF_TERMS_REGEX)
|
81
81
|
string = strip_markup(string)
|
82
|
+
string = normalize_quotes(string)
|
82
83
|
strip_whitespace(string)
|
83
84
|
end
|
84
85
|
|
@@ -164,5 +165,12 @@ module Licensee
|
|
164
165
|
def strip(string, regex)
|
165
166
|
string.gsub(regex, ' ').squeeze(' ').strip
|
166
167
|
end
|
168
|
+
|
169
|
+
# Replace all single quotes with double quotes
|
170
|
+
# Single versus double quotes don't alter the meaning, and it's easier to
|
171
|
+
# strip double quotes if we still want to allow possessives
|
172
|
+
def normalize_quotes(string)
|
173
|
+
string.gsub(/\s'([\w -]*?\w)'/, ' "\1"')
|
174
|
+
end
|
167
175
|
end
|
168
176
|
end
|
data/lib/licensee/matchers.rb
CHANGED
@@ -2,6 +2,7 @@ module Licensee
|
|
2
2
|
module Matchers
|
3
3
|
autoload :Matcher, 'licensee/matchers/matcher'
|
4
4
|
autoload :Cabal, 'licensee/matchers/cabal'
|
5
|
+
autoload :Cargo, 'licensee/matchers/cargo'
|
5
6
|
autoload :Copyright, 'licensee/matchers/copyright'
|
6
7
|
autoload :Cran, 'licensee/matchers/cran'
|
7
8
|
autoload :Dice, 'licensee/matchers/dice'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Licensee
|
2
|
+
module Matchers
|
3
|
+
class Cargo < Licensee::Matchers::Package
|
4
|
+
LICENSE_REGEX = %r{
|
5
|
+
^\s*[\'\"]?license[\'\"]?\s*=\s*[\'\"]([a-z\-0-9\. +()\/]+)[\'\"]\s*
|
6
|
+
}ix
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def license_property
|
11
|
+
match = @file.content.match LICENSE_REGEX
|
12
|
+
match[1].downcase if match && match[1]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -12,15 +12,18 @@ module Licensee
|
|
12
12
|
FILENAMES_EXTENSIONS = {
|
13
13
|
'DESCRIPTION' => [Matchers::Cran],
|
14
14
|
'dist.ini' => [Matchers::DistZilla],
|
15
|
-
'LICENSE.spdx' => [Matchers::Spdx]
|
15
|
+
'LICENSE.spdx' => [Matchers::Spdx],
|
16
|
+
'Cargo.toml' => [Matchers::Cargo]
|
16
17
|
}.freeze
|
17
18
|
|
18
19
|
FILENAMES_SCORES = {
|
19
|
-
'package.json'
|
20
|
-
'LICENSE.spdx'
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
20
|
+
'package.json' => 1.0,
|
21
|
+
'LICENSE.spdx' => 1.0,
|
22
|
+
'Cargo.toml' => 1.0,
|
23
|
+
'DESCRIPTION' => 0.9,
|
24
|
+
'dist.ini' => 0.8,
|
25
|
+
'bower.json' => 0.75,
|
26
|
+
'elm-package.json' => 0.7
|
24
27
|
}.freeze
|
25
28
|
|
26
29
|
def possible_matchers
|
@@ -1,21 +1,30 @@
|
|
1
1
|
module Licensee
|
2
2
|
module ProjectFiles
|
3
3
|
class ReadmeFile < Licensee::ProjectFiles::LicenseFile
|
4
|
+
EXTENSIONS = %w[md markdown mdown txt rdoc].freeze
|
4
5
|
SCORES = {
|
5
|
-
/\AREADME\z/i
|
6
|
-
/\AREADME\.(
|
6
|
+
/\AREADME\z/i => 1.0,
|
7
|
+
/\AREADME\.(#{Regexp.union(EXTENSIONS).source})\z/i => 0.9
|
7
8
|
}.freeze
|
8
9
|
|
10
|
+
TITLE_REGEX = /licen[sc]e:?/i
|
11
|
+
UNDERLINE_REGEX = /\n[-=]+/m
|
9
12
|
CONTENT_REGEX = /^
|
10
|
-
(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
(?: # Header lookbehind
|
14
|
+
[\#=]+\s#{TITLE_REGEX} # Start of hashes or rdoc header
|
15
|
+
|
|
16
|
+
#{TITLE_REGEX}#{UNDERLINE_REGEX} # Start of underlined header
|
17
|
+
)$
|
18
|
+
(.*?) # License content
|
19
|
+
(?=^ # Header or end of file lookahead
|
20
|
+
(?:
|
21
|
+
[\#=]+ # Next hash or rdoc header
|
22
|
+
|
|
23
|
+
[^\n]+#{UNDERLINE_REGEX} # Next of underlined header
|
24
|
+
)
|
25
|
+
|
|
26
|
+
\z # End of file
|
27
|
+
)
|
19
28
|
/mix
|
20
29
|
|
21
30
|
def possible_matchers
|
data/lib/licensee/version.rb
CHANGED
@@ -21,6 +21,9 @@ RSpec.describe Licensee::ContentHelper do
|
|
21
21
|
The made
|
22
22
|
* * * *
|
23
23
|
up license.
|
24
|
+
|
25
|
+
This license provided 'as is'. Please respect the contributors' wishes when
|
26
|
+
implementing the license's "software".
|
24
27
|
-----------
|
25
28
|
LICENSE
|
26
29
|
end
|
@@ -28,11 +31,17 @@ LICENSE
|
|
28
31
|
let(:mit) { Licensee::License.find('mit') }
|
29
32
|
|
30
33
|
it 'creates the wordset' do
|
31
|
-
|
34
|
+
wordset = Set.new(
|
35
|
+
%w[
|
36
|
+
the made up license this provided as is please respect
|
37
|
+
contributors' wishes when implementing license's software
|
38
|
+
]
|
39
|
+
)
|
40
|
+
expect(subject.wordset).to eql(wordset)
|
32
41
|
end
|
33
42
|
|
34
43
|
it 'knows the length' do
|
35
|
-
expect(subject.length).to eql(
|
44
|
+
expect(subject.length).to eql(135)
|
36
45
|
end
|
37
46
|
|
38
47
|
context 'a very long license' do
|
@@ -44,17 +53,17 @@ LICENSE
|
|
44
53
|
end
|
45
54
|
|
46
55
|
it 'knows the length delta' do
|
47
|
-
expect(subject.length_delta(mit)).to eql(
|
56
|
+
expect(subject.length_delta(mit)).to eql(884)
|
48
57
|
expect(subject.length_delta(subject)).to eql(0)
|
49
58
|
end
|
50
59
|
|
51
60
|
it 'knows the similarity' do
|
52
|
-
expect(subject.similarity(mit)).to be_within(1).of(
|
61
|
+
expect(subject.similarity(mit)).to be_within(1).of(11)
|
53
62
|
expect(subject.similarity(subject)).to eql(100.0)
|
54
63
|
end
|
55
64
|
|
56
65
|
it 'calculates the hash' do
|
57
|
-
content_hash = '
|
66
|
+
content_hash = '916b978940ecf8070c96bd3aca9321768e7f4901'
|
58
67
|
expect(subject.content_hash).to eql(content_hash)
|
59
68
|
end
|
60
69
|
|
@@ -120,6 +129,19 @@ LICENSE
|
|
120
129
|
expect(normalized_content).to_not match(/[*=_-]+/)
|
121
130
|
end
|
122
131
|
|
132
|
+
it 'normalizes quotes' do
|
133
|
+
expect(normalized_content).to_not match("'as is'")
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'preserves possessives' do
|
137
|
+
expect(normalized_content).to match("contributors'")
|
138
|
+
expect(normalized_content).to match("license's")
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'preserves double quotes' do
|
142
|
+
expect(normalized_content).to match('"software"')
|
143
|
+
end
|
144
|
+
|
123
145
|
Licensee::License.all(hidden: true).each do |license|
|
124
146
|
context license.name do
|
125
147
|
let(:stripped_content) { subject.content_without_title_and_version }
|
@@ -158,7 +180,10 @@ LICENSE
|
|
158
180
|
end
|
159
181
|
|
160
182
|
it 'normalize the content' do
|
161
|
-
|
183
|
+
expected = 'the made up license. this license provided "as is". '
|
184
|
+
expected << "please respect the contributors' wishes when implementing "
|
185
|
+
expected << "the license's \"software\"."
|
186
|
+
expect(normalized_content).to eql(expected)
|
162
187
|
end
|
163
188
|
|
164
189
|
context 'a title in parenthesis' do
|
@@ -0,0 +1,48 @@
|
|
1
|
+
RSpec.describe Licensee::Matchers::Cargo do
|
2
|
+
let(:mit) { Licensee::License.find('mit') }
|
3
|
+
let(:content) { 'license = "MIT"' }
|
4
|
+
let(:file) { Licensee::ProjectFiles::LicenseFile.new(content, 'Cargo.toml') }
|
5
|
+
subject { described_class.new(file) }
|
6
|
+
|
7
|
+
it 'stores the file' do
|
8
|
+
expect(subject.file).to eql(file)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'has confidence' do
|
12
|
+
expect(subject.confidence).to eql(90)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'matches' do
|
16
|
+
expect(subject.match).to eql(mit)
|
17
|
+
end
|
18
|
+
|
19
|
+
{
|
20
|
+
'spdx name' => ['license = "MIT"', 'mit'],
|
21
|
+
'single quotes' => ["license = 'mit'", 'mit'],
|
22
|
+
'quoted key' => ["'license' = 'mit'", 'mit'],
|
23
|
+
'double quoted key' => ['"license"="mit"', 'mit'],
|
24
|
+
'no whitespace' => ["license='mit'", 'mit'],
|
25
|
+
'leading whitespace' => [" license = 'mit'", 'mit'],
|
26
|
+
'other license' => ['license = "Foo"', 'other'],
|
27
|
+
'multiple licenses /' => ['license = "Apache-2.0/MIT"', 'other'],
|
28
|
+
'multiple licenses OR' => ['license = "Apache-2.0 OR MIT"', 'other'],
|
29
|
+
'multiple licenses parens' => ['license = "(Apache-2.0 OR MIT)"', 'other']
|
30
|
+
}.each do |description, license_declaration_and_key|
|
31
|
+
context "with a #{description}" do
|
32
|
+
let(:content) { license_declaration_and_key[0] }
|
33
|
+
let(:license) { Licensee::License.find(license_declaration_and_key[1]) }
|
34
|
+
|
35
|
+
it 'matches' do
|
36
|
+
expect(subject.match).to eql(license)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'no license field' do
|
42
|
+
let(:content) { 'foo = "bar"' }
|
43
|
+
|
44
|
+
it 'returns nil' do
|
45
|
+
expect(subject.match).to be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -8,9 +8,11 @@ RSpec.describe Licensee::ProjectFiles::PackageManagerFile do
|
|
8
8
|
'licensee.gemspec' => 1.0,
|
9
9
|
'test.cabal' => 1.0,
|
10
10
|
'package.json' => 1.0,
|
11
|
+
'Cargo.toml' => 1.0,
|
11
12
|
'DESCRIPTION' => 0.9,
|
12
13
|
'dist.ini' => 0.8,
|
13
14
|
'bower.json' => 0.75,
|
15
|
+
'elm-package.json' => 0.70,
|
14
16
|
'README.md' => 0.0
|
15
17
|
}.each do |filename, expected_score|
|
16
18
|
context "a file named #{filename}" do
|
@@ -11,6 +11,7 @@ RSpec.describe Licensee::ProjectFiles::ReadmeFile do
|
|
11
11
|
'README.md' => 0.9,
|
12
12
|
'readme.txt' => 0.9,
|
13
13
|
'readme.mdown' => 0.9,
|
14
|
+
'readme.rdoc' => 0.9,
|
14
15
|
'LICENSE' => 0.0
|
15
16
|
}.each do |filename, expected_score|
|
16
17
|
context "with a file named #{filename}" do
|
@@ -97,6 +98,22 @@ RSpec.describe Licensee::ProjectFiles::ReadmeFile do
|
|
97
98
|
expect(license).to eql('hello world')
|
98
99
|
end
|
99
100
|
end
|
101
|
+
|
102
|
+
context 'With a trailing colon' do
|
103
|
+
let(:content) { "## License:\n\nhello world" }
|
104
|
+
|
105
|
+
it 'returns the license' do
|
106
|
+
expect(license).to eql('hello world')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'Rdoc' do
|
111
|
+
let(:content) { "== License:\n\nhello world" }
|
112
|
+
|
113
|
+
it 'returns the license' do
|
114
|
+
expect(license).to eql('hello world')
|
115
|
+
end
|
116
|
+
end
|
100
117
|
end
|
101
118
|
|
102
119
|
context 'a license reference' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: licensee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.
|
4
|
+
version: 9.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octokit
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- lib/licensee/license_rules.rb
|
162
162
|
- lib/licensee/matchers.rb
|
163
163
|
- lib/licensee/matchers/cabal.rb
|
164
|
+
- lib/licensee/matchers/cargo.rb
|
164
165
|
- lib/licensee/matchers/copyright.rb
|
165
166
|
- lib/licensee/matchers/cran.rb
|
166
167
|
- lib/licensee/matchers/dice.rb
|
@@ -227,6 +228,7 @@ files:
|
|
227
228
|
- spec/licensee/license_rules_spec.rb
|
228
229
|
- spec/licensee/license_spec.rb
|
229
230
|
- spec/licensee/matchers/cabal_matcher_spec.rb
|
231
|
+
- spec/licensee/matchers/cargo_matcher_spec.rb
|
230
232
|
- spec/licensee/matchers/copyright_matcher_spec.rb
|
231
233
|
- spec/licensee/matchers/cran_matcher_spec.rb
|
232
234
|
- spec/licensee/matchers/dice_matcher_spec.rb
|
@@ -240,7 +242,7 @@ files:
|
|
240
242
|
- spec/licensee/project_files/license_file_spec.rb
|
241
243
|
- spec/licensee/project_files/package_info_spec.rb
|
242
244
|
- spec/licensee/project_files/project_file_spec.rb
|
243
|
-
- spec/licensee/project_files/
|
245
|
+
- spec/licensee/project_files/readme_file_spec.rb
|
244
246
|
- spec/licensee/project_spec.rb
|
245
247
|
- spec/licensee/projects/github_project_spec.rb
|
246
248
|
- spec/licensee/rule_spec.rb
|