licensee 9.10.0 → 9.10.1

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
  SHA256:
3
- metadata.gz: fa1cf2d146414880f019c339c2803443db7d63eb2568f7807079aac27a7aec98
4
- data.tar.gz: a6243b9cc4b9068090023c70c89a5ea0253580575b534da0c00deaa799441bb5
3
+ metadata.gz: 354a3c318aa962a9c184c71850ba04574618b17f28582f92660a69e5405218ee
4
+ data.tar.gz: 1a96874eaaff65c949ca73261aced972cf20ab53d67da7b42d887ac360810eaf
5
5
  SHA512:
6
- metadata.gz: cff2872a3d87b3c708ac2585dc41b64dd665008064303ec66a3501ec5160dbc87b5e78a4128921d5a95e3e7eb160ecc625d3d12f0fad36b05b59fa577088581b
7
- data.tar.gz: 96466e4da40eb17a01625110f236c40cc90cb99b2e39c7057f2867721c77c565ba16cf08d4c4b02c799d1675a11c765e0dd313c761e273354b19fa8cb0fa1528
6
+ metadata.gz: 227b37abb076fd1d76d9fb296056bdf16b5a24b00ef2e95a0c8a883c7be6dee011bbea1df834b20d6ffe331815cc22f4726c94c1894400d04ae32944f01622dd
7
+ data.tar.gz: 41582f813fd9e57fa3c497c7edfd11fc447a131e7414ba7a1c3c25266239ec2efb6b867b84adffac704a5ba96e992b72d3f87215222e0aca32f40305e285cc2d
@@ -40,8 +40,10 @@ class LicenseeCLI < Thor
40
40
 
41
41
  MATCHED_FILE_METHODS.each do |method|
42
42
  next unless matched_file.respond_to? method
43
+
43
44
  value = matched_file.public_send method
44
45
  next if value.nil?
46
+
45
47
  rows << [humanize(method, :method), humanize(value, method)]
46
48
  end
47
49
  print_table rows, indent: 2
@@ -51,6 +53,7 @@ class LicenseeCLI < Thor
51
53
 
52
54
  licenses = licenses_by_similarity(matched_file)
53
55
  next if licenses.empty?
56
+
54
57
  say ' Closest non-matching licenses:'
55
58
  rows = licenses[0...3].map do |license, similarity|
56
59
  spdx_id = license.meta['spdx-id']
@@ -26,6 +26,7 @@ module Licensee
26
26
  # Number of characteres in the normalized content
27
27
  def length
28
28
  return 0 unless content_normalized
29
+
29
30
  content_normalized.length
30
31
  end
31
32
 
@@ -74,6 +75,7 @@ module Licensee
74
75
  # Returns a string
75
76
  def content_normalized(wrap: nil)
76
77
  return unless content
78
+
77
79
  @content_normalized ||= begin
78
80
  string = content_without_title_and_version.downcase
79
81
  while string =~ Matchers::Copyright::REGEX
@@ -99,6 +101,7 @@ module Licensee
99
101
  # Wrap text to the given line length
100
102
  def self.wrap(text, line_width = 80)
101
103
  return if text.nil?
104
+
102
105
  text = text.clone
103
106
  text.gsub!(/([^\n])\n([^\n])/, '\1 \2')
104
107
 
@@ -125,6 +128,7 @@ module Licensee
125
128
  # families, but for sake of normalization, we can be less strict
126
129
  without_versions = licenses.map do |license|
127
130
  next if license.title == license.name_without_version
131
+
128
132
  Regexp.new Regexp.escape(license.name_without_version), 'i'
129
133
  end
130
134
  titles.concat(without_versions.compact)
@@ -16,11 +16,15 @@ module Licensee
16
16
  # Returns an Array of License objects.
17
17
  def all(options = {})
18
18
  @all[options] ||= begin
19
+ # TODO: Remove in next major version to avoid breaking change
20
+ options[:pseudo] ||= options[:psuedo] unless options[:psuedo].nil?
21
+
19
22
  options = DEFAULT_OPTIONS.merge(options)
20
23
  output = licenses.dup
21
24
  output.reject!(&:hidden?) unless options[:hidden]
22
- output.reject!(&:pseudo_license?) unless options[:psuedo]
25
+ output.reject!(&:pseudo_license?) unless options[:pseudo]
23
26
  return output if options[:featured].nil?
27
+
24
28
  output.select { |l| l.featured? == options[:featured] }
25
29
  end
26
30
  end
@@ -40,7 +44,7 @@ module Licensee
40
44
 
41
45
  # Given a license title or nickname, fuzzy match the license
42
46
  def find_by_title(title)
43
- License.all(hidden: true, psuedo: false).find do |license|
47
+ License.all(hidden: true, pseudo: false).find do |license|
44
48
  title =~ /\A(the )?#{license.title_regex}( license)?\z/i
45
49
  end
46
50
  end
@@ -82,7 +86,7 @@ module Licensee
82
86
  DEFAULT_OPTIONS = {
83
87
  hidden: false,
84
88
  featured: nil,
85
- psuedo: true
89
+ pseudo: true
86
90
  }.freeze
87
91
 
88
92
  ALT_TITLE_REGEX = {
@@ -125,6 +129,8 @@ module Licensee
125
129
 
126
130
  # Returns the human-readable license name
127
131
  def name
132
+ return key.tr('-', ' ').capitalize if pseudo_license?
133
+
128
134
  title || spdx_id
129
135
  end
130
136
 
@@ -242,11 +248,13 @@ module Licensee
242
248
  unless File.exist?(path)
243
249
  raise Licensee::InvalidLicense, "'#{key}' is not a valid license key"
244
250
  end
251
+
245
252
  @raw_content ||= File.read(path, encoding: 'utf-8')
246
253
  end
247
254
 
248
255
  def parts
249
256
  return unless raw_content
257
+
250
258
  @parts ||= raw_content.match(/\A(---\n.*\n---\n+)?(.*)/m).to_a
251
259
  end
252
260
 
@@ -39,6 +39,7 @@ module Licensee
39
39
  # Given a license body, returns an array of included LicneseFields
40
40
  def from_content(content)
41
41
  return [] unless content
42
+
42
43
  LicenseField.from_array content.scan(FIELD_REGEX).flatten
43
44
  end
44
45
  end
@@ -23,6 +23,7 @@ module Licensee
23
23
  # returns a LicenseMeta with defaults set
24
24
  def from_yaml(yaml)
25
25
  return from_hash({}) if yaml.nil? || yaml.to_s.empty?
26
+
26
27
  from_hash YAML.safe_load(yaml)
27
28
  end
28
29
 
@@ -15,6 +15,7 @@ module Licensee
15
15
  # or `nil` if no license field is found
16
16
  def license_field
17
17
  return @license_field if defined? @license_field
18
+
18
19
  match = @file.content.match LICENSE_FIELD_REGEX
19
20
  @license_field = match ? match[1].downcase : nil
20
21
  end
@@ -30,6 +31,7 @@ module Licensee
30
31
  # Rerurns `nil` if no license is found
31
32
  def license_property
32
33
  return unless license_field
34
+
33
35
  # Remove The common + file LICENSE text
34
36
  license_key = license_field.sub(PLUS_FILE_LICENSE_REGEX, '')
35
37
  gpl_version(license_key) || license_key
@@ -3,6 +3,7 @@ module Licensee
3
3
  class Exact < Licensee::Matchers::Matcher
4
4
  def match
5
5
  return @match if defined? @match
6
+
6
7
  @match = potential_matches.find do |potential_match|
7
8
  potential_match.wordset == file.wordset
8
9
  end
@@ -34,6 +34,7 @@ module Licensee
34
34
 
35
35
  # use 'other' if array contains multiple licenses
36
36
  return 'other' unless licenses.size == 1
37
+
37
38
  licenses[0]
38
39
  end
39
40
 
@@ -4,6 +4,7 @@ module Licensee
4
4
  def match
5
5
  return @match if defined? @match
6
6
  return if license_property.nil? || license_property.to_s.empty?
7
+
7
8
  @match = Licensee.licenses(hidden: true).find do |license|
8
9
  license.key == license_property
9
10
  end
@@ -55,6 +55,7 @@ module Licensee
55
55
  def attribution
56
56
  @attribution ||= begin
57
57
  return unless copyright? || license.content =~ /\[fullname\]/
58
+
58
59
  matches = Matchers::Copyright::REGEX
59
60
  .match(content_without_title_and_version)
60
61
  matches[0] if matches
@@ -32,6 +32,7 @@ module Licensee
32
32
 
33
33
  def self.name_score(filename)
34
34
  return 1.0 if ['.gemspec', '.cabal'].include?(File.extname(filename))
35
+
35
36
  FILENAMES_SCORES[filename] || 0.0
36
37
  end
37
38
 
@@ -88,6 +88,7 @@ module Licensee
88
88
  def copyright?
89
89
  return false unless is_a?(LicenseFile)
90
90
  return false unless matcher.is_a?(Matchers::Copyright)
91
+
91
92
  filename =~ /\Acopyright(?:#{LicenseFile::OTHER_EXT_REGEX})?\z/i
92
93
  end
93
94
 
@@ -36,6 +36,7 @@ module Licensee
36
36
  relative_dir = Pathname.new(dir).relative_path_from(dir_path).to_s
37
37
  Dir.glob(::File.join(dir, @pattern).tr('\\', '/')).map do |file|
38
38
  next unless ::File.file?(file)
39
+
39
40
  { name: ::File.basename(file), dir: relative_dir }
40
41
  end.compact
41
42
  end
@@ -20,6 +20,7 @@ module Licensee
20
20
  def initialize(github_url, **args)
21
21
  @repo = github_url[GITHUB_REPO_PATTERN, 1]
22
22
  raise ArgumentError, "Not a github URL: #{github_url}" unless @repo
23
+
23
24
  super(**args)
24
25
  end
25
26
 
@@ -29,8 +30,10 @@ module Licensee
29
30
 
30
31
  def files
31
32
  return @files if defined? @files_from_tree
33
+
32
34
  @files = dir_files
33
35
  return @files unless @files.empty?
36
+
34
37
  msg = "Could not load GitHub repo #{repo}, it may be private or deleted"
35
38
  raise RepoNotFound, msg
36
39
  end
@@ -21,6 +21,7 @@ module Licensee
21
21
  # Returns the matching License instance if a license can be detected
22
22
  def license
23
23
  return @license if defined? @license
24
+
24
25
  @license = if licenses_without_copyright.count == 1 || lgpl?
25
26
  licenses_without_copyright.first
26
27
  elsif licenses_without_copyright.count > 1
@@ -53,6 +54,7 @@ module Licensee
53
54
  def license_files
54
55
  @license_files ||= begin
55
56
  return [] if files.empty? || files.nil?
57
+
56
58
  files = find_files do |n|
57
59
  Licensee::ProjectFiles::LicenseFile.name_score(n)
58
60
  end
@@ -67,6 +69,7 @@ module Licensee
67
69
  def readme_file
68
70
  return unless detect_readme?
69
71
  return @readme if defined? @readme
72
+
70
73
  @readme = begin
71
74
  content, file = find_file do |n|
72
75
  Licensee::ProjectFiles::ReadmeFile.name_score(n)
@@ -74,6 +77,7 @@ module Licensee
74
77
  content = Licensee::ProjectFiles::ReadmeFile.license_content(content)
75
78
 
76
79
  return unless content && file
80
+
77
81
  Licensee::ProjectFiles::ReadmeFile.new(content, file)
78
82
  end
79
83
  end
@@ -82,12 +86,14 @@ module Licensee
82
86
  def package_file
83
87
  return unless detect_packages?
84
88
  return @package_file if defined? @package_file
89
+
85
90
  @package_file = begin
86
91
  content, file = find_file do |n|
87
92
  Licensee::ProjectFiles::PackageManagerFile.name_score(n)
88
93
  end
89
94
 
90
95
  return unless content && file
96
+
91
97
  Licensee::ProjectFiles::PackageManagerFile.new(content, file)
92
98
  end
93
99
  end
@@ -96,6 +102,7 @@ module Licensee
96
102
 
97
103
  def lgpl?
98
104
  return false unless licenses.count == 2 && license_files.count == 2
105
+
99
106
  license_files[0].lgpl? && license_files[1].gpl?
100
107
  end
101
108
 
@@ -104,6 +111,7 @@ module Licensee
104
111
  # sorted by file score descending
105
112
  def find_files
106
113
  return [] if files.empty? || files.nil?
114
+
107
115
  found = files.map { |file| file.merge(score: yield(file[:name])) }
108
116
  found.select! { |file| file[:score] > 0 }
109
117
  found.sort { |a, b| b[:score] <=> a[:score] }
@@ -114,6 +122,7 @@ module Licensee
114
122
  # or nil, if no file scored > 0
115
123
  def find_file(&block)
116
124
  return if files.empty? || files.nil?
125
+
117
126
  file = find_files(&block).first
118
127
  [load_file(file), file] if file
119
128
  end
@@ -1,3 +1,3 @@
1
1
  module Licensee
2
- VERSION = '9.10.0'.freeze
2
+ VERSION = '9.10.1'.freeze
3
3
  end
@@ -44,6 +44,7 @@ RSpec.describe Licensee::License do
44
44
  it 'includes featured licenses' do
45
45
  expect(licenses).to include(mit)
46
46
  expect(licenses).to_not include(cc_by)
47
+ expect(licenses).to_not include(other)
47
48
  end
48
49
  end
49
50
 
@@ -63,6 +64,7 @@ RSpec.describe Licensee::License do
63
64
  it 'includes only featured licenses' do
64
65
  expect(licenses).to include(mit)
65
66
  expect(licenses).to_not include(cc_by)
67
+ expect(licenses).to_not include(other)
66
68
  expect(licenses.count).to eql(featured_license_count)
67
69
  end
68
70
  end
@@ -73,6 +75,7 @@ RSpec.describe Licensee::License do
73
75
  it 'includes only non-featured licenses' do
74
76
  expect(licenses).to include(unlicense)
75
77
  expect(licenses).to_not include(mit)
78
+ expect(licenses).to_not include(other)
76
79
  expect(licenses.count).to eql(non_featured_license_count)
77
80
  end
78
81
 
@@ -88,13 +91,13 @@ RSpec.describe Licensee::License do
88
91
  end
89
92
  end
90
93
 
91
- context 'psudo licenses' do
94
+ context 'pseudo licenses' do
92
95
  let(:other) { Licensee::License.find('other') }
93
96
 
94
97
  context 'by default' do
95
98
  let(:arguments) { {} }
96
99
 
97
- it "doesn't include psudo licenses" do
100
+ it "doesn't include pseudo licenses" do
98
101
  expect(licenses).to_not include(other)
99
102
  end
100
103
  end
@@ -102,13 +105,13 @@ RSpec.describe Licensee::License do
102
105
  context 'with hidden licenses' do
103
106
  let(:arguments) { { hidden: true } }
104
107
 
105
- it 'includes psudo licenses' do
108
+ it 'includes pseudo licenses' do
106
109
  expect(licenses).to include(other)
107
110
  end
108
111
  end
109
112
 
110
113
  context 'when explicitly asked' do
111
- let(:arguments) { { hidden: true, psuedo: true } }
114
+ let(:arguments) { { hidden: true, pseudo: true } }
112
115
 
113
116
  it 'includes psudo licenses' do
114
117
  expect(licenses).to include(other)
@@ -116,12 +119,30 @@ RSpec.describe Licensee::License do
116
119
  end
117
120
 
118
121
  context 'when explicitly excluded' do
119
- let(:arguments) { { hidden: true, psuedo: false } }
122
+ let(:arguments) { { hidden: true, pseudo: false } }
120
123
 
121
124
  it "doesn'tincludes psudo licenses" do
122
125
  expect(licenses).to_not include(other)
123
126
  end
124
127
  end
128
+
129
+ context 'mispelled' do
130
+ context 'when explicitly asked' do
131
+ let(:arguments) { { hidden: true, psuedo: true } }
132
+
133
+ it 'includes psudo licenses' do
134
+ expect(licenses).to include(other)
135
+ end
136
+ end
137
+
138
+ context 'when explicitly excluded' do
139
+ let(:arguments) { { hidden: true, psuedo: false } }
140
+
141
+ it "doesn'tincludes psudo licenses" do
142
+ expect(licenses).to_not include(other)
143
+ end
144
+ end
145
+ end
125
146
  end
126
147
  end
127
148
 
@@ -201,7 +222,8 @@ RSpec.describe Licensee::License do
201
222
  end
202
223
 
203
224
  it 'uses the default name when none exists' do
204
- expect(other.name).to eql('NOASSERTION')
225
+ expect(other.name).to eql('Other')
226
+ expect(no_license.name).to eql('No license')
205
227
  end
206
228
 
207
229
  it 'expoeses the nickname' do
@@ -341,7 +363,7 @@ RSpec.describe Licensee::License do
341
363
  end
342
364
 
343
365
  context 'License.title_regex' do
344
- Licensee::License.all(hidden: true, psuedo: false).each do |license|
366
+ Licensee::License.all(hidden: true, pseudo: false).each do |license|
345
367
  context "the #{license.title} license" do
346
368
  %i[title nickname key].each do |variation|
347
369
  next if license.send(variation).nil?
@@ -451,7 +473,7 @@ RSpec.describe Licensee::License do
451
473
  end
452
474
 
453
475
  context 'source regex' do
454
- Licensee::License.all(hidden: true, psuedo: false).each do |license|
476
+ Licensee::License.all(hidden: true, pseudo: false).each do |license|
455
477
  context "the #{license.title} license" do
456
478
  let(:source) { URI.parse(license.source) }
457
479
 
@@ -469,6 +491,7 @@ RSpec.describe Licensee::License do
469
491
  context "with '#{suffix}' after the path" do
470
492
  before do
471
493
  next if license.key == 'wtfpl'
494
+
472
495
  regex = /#{Licensee::License::SOURCE_SUFFIX}\z/
473
496
  source.path = source.path.sub(regex, '')
474
497
  source.path = "#{source.path}#{suffix}"
@@ -109,6 +109,7 @@ RSpec::Matchers.define :be_detected_as do |expected|
109
109
  license_file = Licensee::ProjectFiles::LicenseFile.new(actual, 'LICENSE')
110
110
  @actual = license_file.content_normalized(wrap: 80)
111
111
  return false unless license_file.license
112
+
112
113
  values_match? expected, license_file.license
113
114
  end
114
115
 
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.10.0
4
+ version: 9.10.1
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-09-17 00:00:00.000000000 Z
11
+ date: 2018-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv