licensee 8.4.0 → 8.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ea7d783ce6fc8e59946877a34fc32d84b01f449
4
- data.tar.gz: 65142dc4101a66360d080b7eede89977d5ca10c6
3
+ metadata.gz: '09da33c25905df581cb047d1eed3c138ede5f440'
4
+ data.tar.gz: c0d34f622f3f6dde90f32c859b221b6b4af02bce
5
5
  SHA512:
6
- metadata.gz: 9b93a5da892c334a4e3bce03be2ef7342ffda08ae64b6db412216f691af53ee9d8a7d54596c9aadaff6cd6d02038c04da21f4d4e98af222283788fdb77a340cc
7
- data.tar.gz: d066ee5ed370b2c840cd5282f19fccf525f26cde2469a6205039ab886b5b1f2ca5e63e9ac88fc2888fa1c4657cda2b50d2f57f4da79632ac22ad4f96779bc33a
6
+ metadata.gz: 0c253e00b53aa258a70e80fad5a94454ff9ae080d9911f20e999e09eba9db14b306052dbf04b0e66de8ae2256ee87d81b4d458e4fa5317bd84e129bfe5ef2084
7
+ data.tar.gz: 7d0e97bbc08a7d687b6011690e8d346d76f97a6c1d9ac5ee2cede3400771c480c05950e904f5f632d01ff0bed0e699233cb3961f8e79f75ed4a91b7265fbac2c
data/bin/licensee CHANGED
@@ -4,23 +4,33 @@ require_relative '../lib/licensee'
4
4
 
5
5
  path = ARGV[0] || Dir.pwd
6
6
 
7
- def print_file(license_file)
8
- if license_file
9
- puts "License file: #{license_file.filename}"
10
- puts "Attribution: #{license_file.attribution}" if license_file.attribution
11
- end
7
+ def format_percent(float)
8
+ "#{format('%.2f', float)}%"
12
9
  end
13
10
 
14
- def print_evaluation(file)
15
- if file
16
- puts "License: #{file.license ? file.license.meta['title'] : 'no license'}"
17
- puts "Confidence: #{format('%.2f', file.confidence)}%" if file.confidence
18
- puts "Method: #{file.matcher.class}" if file.matcher
11
+ project = Licensee.project(path, detect_packages: true, detect_readme: true)
12
+ license_file = project.license_file
13
+ matched_file = project.matched_file
14
+
15
+ if license_file
16
+ puts "License file: #{license_file.filename}"
17
+ puts "Attribution: #{license_file.attribution}" if license_file.attribution
18
+ end
19
+
20
+ if matched_file
21
+ if matched_file.license
22
+ puts "License: #{matched_file.license.meta['title']}"
23
+ puts "Confidence: #{format_percent(matched_file.confidence)}" if matched_file.confidence
24
+ puts "Method: #{matched_file.matcher.class}" if matched_file.matcher
19
25
  else
20
- puts 'Unknown'
26
+ puts 'License: Not detected'
27
+ puts
28
+ puts "Here's the closest licenses:"
29
+ matcher = Licensee::Matchers::Dice.new(matched_file)
30
+ matcher.licenses_by_similiarity[0...3].each do |license, similarity|
31
+ puts "* #{license.meta['spdx-id']} similarity: #{format_percent(similarity)}"
32
+ end
21
33
  end
34
+ else
35
+ puts 'Unknown'
22
36
  end
23
-
24
- project = Licensee.project(path, detect_packages: true, detect_readme: true)
25
- print_file(project.license_file)
26
- print_evaluation(project.matched_file)
@@ -48,6 +48,7 @@ module Licensee
48
48
  @content_normalized ||= begin
49
49
  content_normalized = content.downcase.strip
50
50
  content_normalized.gsub!(/^#{Matchers::Copyright::REGEX}$/i, '')
51
+ content_normalized.gsub!(/[=-]{4,}/, '') # Strip HRs from MPL
51
52
  content_normalized.tr("\n", ' ').squeeze(' ').strip
52
53
  end
53
54
  end
@@ -140,11 +140,10 @@ module Licensee
140
140
  # Raw content of license file, including YAML front matter
141
141
  def raw_content
142
142
  return if pseudo_license?
143
- @raw_content ||= if File.exist?(path)
144
- File.read(path, encoding: 'utf-8')
145
- else
143
+ unless File.exist?(path)
146
144
  raise Licensee::InvalidLicense, "'#{key}' is not a valid license key"
147
145
  end
146
+ @raw_content ||= File.read(path, encoding: 'utf-8')
148
147
  end
149
148
 
150
149
  def parts
@@ -10,16 +10,10 @@ module Licensee
10
10
  # Return the first potential license that is more similar
11
11
  # than the confidence threshold
12
12
  def match
13
- return @match if defined? @match
14
- matches = potential_licenses.map do |license|
15
- similarity = license.similarity(file)
16
- [license, similarity] if similarity >= Licensee.confidence_threshold
17
- end
18
- matches.compact!
19
- @match = if matches.empty?
13
+ @match ||= if matches.empty?
20
14
  nil
21
15
  else
22
- matches.max_by { |_l, sim| sim }.first
16
+ matches.first[0]
23
17
  end
24
18
  end
25
19
 
@@ -34,6 +28,19 @@ module Licensee
34
28
  end
35
29
  end
36
30
 
31
+ def licenses_by_similiarity
32
+ @licenses_by_similiarity ||= begin
33
+ licenses = potential_licenses.map { |l| [l, l.similarity(file)] }
34
+ licenses.sort_by { |_, similarity| similarity }.reverse
35
+ end
36
+ end
37
+
38
+ def matches
39
+ @matches ||= licenses_by_similiarity.select do |_, similarity|
40
+ similarity >= Licensee.confidence_threshold
41
+ end
42
+ end
43
+
37
44
  # Confidence that the matched license is a match
38
45
  def confidence
39
46
  @confidence ||= match ? file.similarity(match) : 0
@@ -1,3 +1,3 @@
1
1
  module Licensee
2
- VERSION = '8.4.0'.freeze
2
+ VERSION = '8.5.0'.freeze
3
3
  end
@@ -0,0 +1 @@
1
+ ref: refs/heads/master
@@ -0,0 +1,5 @@
1
+ [core]
2
+ repositoryformatversion = 0
3
+ filemode = true
4
+ bare = true
5
+ ignorecase = true
@@ -0,0 +1 @@
1
+ baf5649b61fac4ed64ec2949fe5cd616b85a8298
@@ -4,6 +4,9 @@ class TestLicenseeDiceMatchers < Minitest::Test
4
4
  def setup
5
5
  text = license_from_path(Licensee::License.find('mit').path)
6
6
  @mit = Licensee::Project::LicenseFile.new(text)
7
+
8
+ text = license_from_path(Licensee::License.find('gpl-2.0').path)
9
+ @gpl = Licensee::Project::LicenseFile.new(text)
7
10
  end
8
11
 
9
12
  def concat_licenses(*args)
@@ -25,6 +28,33 @@ class TestLicenseeDiceMatchers < Minitest::Test
25
28
  text = concat_licenses('mit', 'gpl-2.0')
26
29
  license = Licensee::Project::LicenseFile.new(text)
27
30
  matcher = Licensee::Matchers::Dice.new(license)
28
- refute matcher.match
31
+ if matcher.match
32
+ msg = "Expected no-license, got #{matcher.match.key}"
33
+ msg << " (#{matcher.match.similarity(license).round(2)}% similar)"
34
+ end
35
+ refute matcher.match, msg
36
+ end
37
+
38
+ should 'build the list of licenses by similarity' do
39
+ matcher = Licensee::Matchers::Dice.new(@gpl)
40
+
41
+ match = matcher.licenses_by_similiarity.first
42
+ assert_equal Licensee::License, match[0].class
43
+ assert_equal 'gpl-2.0', match[0].key
44
+ assert_equal 100.0, match[1]
45
+
46
+ match = matcher.licenses_by_similiarity[1]
47
+ assert_equal 'lppl-1.3c', match[0].key
48
+ assert_equal 49.52, match[1].round(2)
49
+ end
50
+
51
+ should 'build the list of matches' do
52
+ matcher = Licensee::Matchers::Dice.new(@gpl)
53
+
54
+ assert_equal 1, matcher.matches.count
55
+ match = matcher.matches.first
56
+ assert_equal Licensee::License, match[0].class
57
+ assert_equal 'gpl-2.0', match[0].key
58
+ assert_equal 100.0, match[1]
29
59
  end
30
60
  end
@@ -8,7 +8,8 @@ class ContentHelperTestHelper
8
8
  Copyright 2016 Ben Balter
9
9
 
10
10
  The made
11
- up license.
11
+ up license.
12
+ -----------
12
13
  EOS
13
14
 
14
15
  def initialize(content = nil)
@@ -21,8 +22,32 @@ class TestLicenseeContentHelper < Minitest::Test
21
22
  @helper = ContentHelperTestHelper.new
22
23
  end
23
24
 
24
- should 'normalize the content' do
25
- assert_equal 'the made up license.', @helper.content_normalized
25
+ context 'normalizing' do
26
+ should 'strips copyright' do
27
+ refute_match('Copyright', @helper.content_normalized)
28
+ refute_match('Ben Balter', @helper.content_normalized)
29
+ end
30
+
31
+ should 'downcases' do
32
+ refute_match('The', @helper.content_normalized)
33
+ assert_match('the', @helper.content_normalized)
34
+ end
35
+
36
+ should 'strips HRs' do
37
+ refute_match('---', @helper.content_normalized)
38
+ end
39
+
40
+ should 'squeeze whitespace' do
41
+ refute_match(' ', @helper.content_normalized)
42
+ end
43
+
44
+ should 'strips whitespace' do
45
+ refute_match(/\n/i, @helper.content_normalized)
46
+ end
47
+
48
+ should 'normalize the content' do
49
+ assert_equal 'the made up license.', @helper.content_normalized
50
+ end
26
51
  end
27
52
 
28
53
  should 'generate the hash' do
@@ -77,6 +77,11 @@ class TestLicenseeProject < Minitest::Test
77
77
  project = make_project 'lgpl.git'
78
78
  assert_equal 'lgpl-3.0', project.license.key
79
79
  end
80
+
81
+ should 'detect the MPL even with HRs removed' do
82
+ project = make_project 'mpl-without-hrs.git'
83
+ assert_equal 'mpl-2.0', project.license.key
84
+ end
80
85
  end
81
86
  end
82
87
 
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: 8.4.0
4
+ version: 8.5.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: 2016-09-15 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -173,6 +173,12 @@ files:
173
173
  - test/fixtures/mit-with-redundant-title/mit.txt
174
174
  - test/fixtures/mit-without-title-rewrapped/mit.txt
175
175
  - test/fixtures/mit-without-title/mit.txt
176
+ - test/fixtures/mpl-without-hrs.git/HEAD
177
+ - test/fixtures/mpl-without-hrs.git/config
178
+ - test/fixtures/mpl-without-hrs.git/objects/45/26aa2d1d78ea20fb0faf59f2360a68fa897774
179
+ - test/fixtures/mpl-without-hrs.git/objects/ba/f5649b61fac4ed64ec2949fe5cd616b85a8298
180
+ - test/fixtures/mpl-without-hrs.git/objects/be/2cc4dfb609fb6c38f6365ec345bded3350dd63
181
+ - test/fixtures/mpl-without-hrs.git/refs/heads/master
176
182
  - test/fixtures/named-license-file-prefix.git/HEAD
177
183
  - test/fixtures/named-license-file-prefix.git/config
178
184
  - test/fixtures/named-license-file-prefix.git/objects/64/3983d3f82ecc2a7d8e4227946220ebffd477d2