bibliothecary 7.1.1 → 7.1.5

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: e99bd64be33f917579aeca0ce4d27a1290328020516f2bf2328f3bc82273da99
4
- data.tar.gz: 3c431e57230c9d20ba3e66e4e5e9b72def9ba81ad8707f47166be5d9e993a751
3
+ metadata.gz: c9b98a74ca8714750a835ebe600e5a031edcad43bfffa82b475f47aaf1356d2b
4
+ data.tar.gz: a8a74dbbfdac38ad7da70258e080c9f61aad16c4f19002b8d1d53290873ba6d0
5
5
  SHA512:
6
- metadata.gz: 722b6cad2fa9b84111fa97a5f925e6fb3967489bac80747e11ab1c6ac22cfec6a4fdeefa6e17ad9e926860e429322e1e1f182bfc88ea69a4778cfc0717d9de70
7
- data.tar.gz: 0e92b678afe3f81ad3593f6feaa7e4357a4bda19e1ec4720a8f513c69261b87eb2916950b556ab645913432496b1153f8db7a44f3945baaa6e2154a0109fdd01
6
+ metadata.gz: 25f3208793295ee459d4a9995f38a877d48132fa31469091695e60597c09547f345a0f554539a4bfe065b8a307ba17a8e9fecc3d30d08cce22ef35cf7e5430e0
7
+ data.tar.gz: 8b38ae3f49162807dcf04f3e07c81d69501b1aa041b4e1239bc8bf477067e485266b15ad99a090f649dd826cf2f055a24ef3bf39e8fbcda071f2d087f0dea2a2
@@ -4,12 +4,23 @@ module Bibliothecary
4
4
  include Bibliothecary::Analyser
5
5
 
6
6
  INSTALL_REGEXP = /install_requires\s*=\s*\[([\s\S]*?)\]/
7
- REQUIRE_REGEXP = /([a-zA-Z0-9]+[a-zA-Z0-9\-_\.]+)([><=\w\.,]+)?/
7
+
8
+ # Capture Group 1 is package.
9
+ # Optional Group 2 is [extras].
10
+ # Capture Group 3 is Version
11
+ REQUIRE_REGEXP = /([a-zA-Z0-9]+[a-zA-Z0-9\-_\.]+)(?:\[.*?\])*([><=\w\.,]+)?/
12
+
8
13
  REQUIREMENTS_REGEXP = /^#{REQUIRE_REGEXP}/
9
- MANIFEST_REGEXP = /.*require[^\/]*(\/)?[^\/]*\.(txt|pip)$/
14
+ MANIFEST_REGEXP = /.*require[^\/]*(\/)?[^\/]*\.(txt|pip|in)$/
15
+ PIP_COMPILE_REGEXP = /.*require.*$/
10
16
 
11
17
  def self.mapping
12
18
  {
19
+ lambda { |p| PIP_COMPILE_REGEXP.match(p) } => {
20
+ content_matcher: :pip_compile?,
21
+ kind: 'lockfile',
22
+ parser: :parse_requirements_txt
23
+ },
13
24
  lambda { |p| MANIFEST_REGEXP.match(p) } => {
14
25
  kind: 'manifest',
15
26
  parser: :parse_requirements_txt,
@@ -154,7 +165,7 @@ module Bibliothecary
154
165
  next unless match
155
166
  deps << {
156
167
  name: match[1],
157
- requirement: match[2] || '*',
168
+ requirement: match[-1] || '*',
158
169
  type: 'runtime'
159
170
  }
160
171
  end
@@ -168,12 +179,21 @@ module Bibliothecary
168
179
  next unless match
169
180
  deps << {
170
181
  name: match[1],
171
- requirement: match[2] || '*',
182
+ requirement: match[-1] || '*',
172
183
  type: 'runtime'
173
184
  }
174
185
  end
175
186
  deps
176
187
  end
188
+
189
+ def self.pip_compile?(file_contents)
190
+ return file_contents.include?("This file is autogenerated by pip-compile")
191
+ rescue Exception # rubocop:disable Lint/RescueException
192
+ # We rescue exception here since native libs can throw a non-StandardError
193
+ # We don't want to throw errors during the matching phase, only during
194
+ # parsing after we match.
195
+ false
196
+ end
177
197
  end
178
198
  end
179
199
  end
@@ -42,6 +42,22 @@ module Bibliothecary
42
42
  Bibliothecary::Parsers.constants.map{|c| Bibliothecary::Parsers.const_get(c) }.sort_by{|c| c.to_s.downcase }
43
43
  end
44
44
 
45
+ def load_file_info_list_from_contents(file_path_contents_hash)
46
+ # Parses an array of format [{file_path: "", contents: ""},] to match
47
+ # on both filename matches, and one content_match patterns.
48
+ file_list = []
49
+
50
+ file_path_contents_hash.each do |file|
51
+ info = FileInfo.new(nil, file[:file_path], file[:contents])
52
+
53
+ next if ignored_files.include?(info.relative_path)
54
+
55
+ add_files_to_list(file_list, info)
56
+ end
57
+
58
+ file_list
59
+ end
60
+
45
61
  def load_file_info_list_from_paths(paths)
46
62
  file_list = []
47
63
 
@@ -50,12 +66,7 @@ module Bibliothecary
50
66
 
51
67
  next if ignored_files.include?(info.relative_path)
52
68
 
53
- applicable_package_managers(info).each do |package_manager|
54
- file = info.dup
55
- file.package_manager = package_manager
56
-
57
- file_list.push(file)
58
- end
69
+ add_files_to_list(file_list, info)
59
70
  end
60
71
 
61
72
  file_list
@@ -71,12 +82,7 @@ module Bibliothecary
71
82
  next unless FileTest.file?(subpath)
72
83
  next if ignored_files.include?(info.relative_path)
73
84
 
74
- applicable_package_managers(info).each do |package_manager|
75
- file = info.dup
76
- file.package_manager = package_manager
77
-
78
- file_list.push(file)
79
- end
85
+ add_files_to_list(file_list, info)
80
86
  end
81
87
 
82
88
  file_list
@@ -90,6 +96,10 @@ module Bibliothecary
90
96
  RelatedFilesInfo.create_from_file_infos(load_file_info_list_from_paths(paths).reject { |info| info.package_manager.nil? })
91
97
  end
92
98
 
99
+ def find_manifests_from_contents(file_path_contents_hash)
100
+ RelatedFilesInfo.create_from_file_infos(load_file_info_list_from_contents(file_path_contents_hash).reject { |info| info.package_manager.nil? })
101
+ end
102
+
93
103
  def analyse_file(file_path, contents)
94
104
  package_managers.select { |pm| pm.match?(file_path, contents) }.map do |pm|
95
105
  pm.analyse_contents(file_path, contents)
@@ -124,5 +134,16 @@ module Bibliothecary
124
134
  def ignored_files
125
135
  @configuration.ignored_files
126
136
  end
137
+
138
+ private
139
+
140
+ def add_files_to_list(file_list, info)
141
+ applicable_package_managers(info).each do |package_manager|
142
+ file = info.dup
143
+ file.package_manager = package_manager
144
+
145
+ file_list.push(file)
146
+ end
147
+ end
127
148
  end
128
149
  end
@@ -1,3 +1,3 @@
1
1
  module Bibliothecary
2
- VERSION = "7.1.1"
2
+ VERSION = "7.1.5"
3
3
  end
data/lib/bibliothecary.rb CHANGED
@@ -34,6 +34,10 @@ module Bibliothecary
34
34
  runner.load_file_info_list_from_paths(paths)
35
35
  end
36
36
 
37
+ def self.load_file_info_list_from_contents(file_path_contents_hash)
38
+ runner.load_file_info_list_from_contents(file_path_contents_hash)
39
+ end
40
+
37
41
  def self.analyse_file(file_path, contents)
38
42
  runner.analyse_file(file_path, contents)
39
43
  end
@@ -54,6 +58,10 @@ module Bibliothecary
54
58
  runner.find_manifests_from_paths(paths)
55
59
  end
56
60
 
61
+ def self.find_manifests_from_contents(file_path_contents_hash)
62
+ runner.find_manifests_from_contents(file_path_contents_hash)
63
+ end
64
+
57
65
  def self.ignored_dirs
58
66
  configuration.ignored_dirs
59
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibliothecary
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.1
4
+ version: 7.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-31 00:00:00.000000000 Z
11
+ date: 2021-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tomlrb
@@ -206,7 +206,7 @@ dependencies:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
- description:
209
+ description:
210
210
  email:
211
211
  - andrewnez@gmail.com
212
212
  executables:
@@ -274,7 +274,7 @@ homepage: https://github.com/librariesio/bibliothecary
274
274
  licenses:
275
275
  - AGPL-3.0
276
276
  metadata: {}
277
- post_install_message:
277
+ post_install_message:
278
278
  rdoc_options: []
279
279
  require_paths:
280
280
  - lib
@@ -290,7 +290,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
290
  version: '0'
291
291
  requirements: []
292
292
  rubygems_version: 3.1.2
293
- signing_key:
293
+ signing_key:
294
294
  specification_version: 4
295
295
  summary: Find and parse manifests
296
296
  test_files: []