bibliothecary 7.1.0 → 7.1.4

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: 74f493b85e3dec08ab0c8aad09b9beb59eee3b8dc5317d6b9f20c6c5620298eb
4
- data.tar.gz: 1f1dd61989f87a10974e205862e3a01c7808bdad072dcca2f74193d1c731c9ec
3
+ metadata.gz: 139600bf079b4cc07ba891b319f14dd7ec7af7622bcd5b87ef93b70e21191e58
4
+ data.tar.gz: 1b0162957be9078ffb00d6c2f1ff2d2654e7aad74853bb7f06e3c81be50ca950
5
5
  SHA512:
6
- metadata.gz: '02351483c4000b031662de8ed48459c74d8d533b9676ba3968060e01cca50fcf5ede59982d8e6237d6ddf8395fa0b5172c87eb13a7d849e866236c88fec20150'
7
- data.tar.gz: b437fe17ca779bc99a6d78753936726ae102c75ef7e2583ae6544320aa5b65ba53e16e644035c5eaa445cd2bc6fe2fa695856b6e518c5d3fbad389f33c0419ae
6
+ metadata.gz: ef6071d7672fc07be61cac936b10f694675758ca4ed2d9dfdf9cd77c440f1538771cccc528f1b4d2486fe8e6621eff96ae7825c69b97b957140302e3d7fa01f9
7
+ data.tar.gz: 3797470015e7d7f2da4b6603ece7e327083bb10d5b77f4bb2c8adc139f35fe0a5c1e90ef1d8cc36aba83a5ca77144f6433a98d85e8164dee8a3a38dc23fa9450
@@ -26,7 +26,8 @@ module Bibliothecary
26
26
  requirement: dependency["version"],
27
27
  type: "runtime"
28
28
  }.tap do |result|
29
- result[:drupal_requirement] = dependency.dig("source", "reference") if is_drupal_module(dependency)
29
+ # Store Drupal version if Drupal, but include the original manifest version for reference
30
+ result[:original_requirement], result[:requirement] = result[:requirement], dependency.dig("source", "reference") if is_drupal_module(dependency)
30
31
  end
31
32
  end + manifest.fetch('packages-dev',[]).map do |dependency|
32
33
  {
@@ -34,7 +35,8 @@ module Bibliothecary
34
35
  requirement: dependency["version"],
35
36
  type: "development"
36
37
  }.tap do |result|
37
- result[:drupal_requirement] = dependency.dig("source", "reference") if is_drupal_module(dependency)
38
+ # Store Drupal version if Drupal, but include the original manifest version for reference
39
+ result[:original_requirement], result[:requirement] = result[:requirement], dependency.dig("source", "reference") if is_drupal_module(dependency)
38
40
  end
39
41
  end
40
42
  end
@@ -51,7 +53,8 @@ module Bibliothecary
51
53
  # but you may only have composer.lock, so we test if the type is "drupal-*" (e.g. "drupal-module" or "drupal-theme")
52
54
  # The Drupal team also setup its own mapper of Composer semver -> Drupal tool-specfic versions
53
55
  # (https://www.drupal.org/project/project_composer/issues/2622450),
54
- # so we return the Drupal requirement instead of semver requirement if it's here.
56
+ # so we return the Drupal requirement instead of semver requirement if it's here
57
+ # (https://www.drupal.org/docs/develop/using-composer/using-composer-to-install-drupal-and-manage-dependencies#s-about-semantic-versioning)
55
58
  private_class_method def self.is_drupal_module(dependency)
56
59
  dependency["type"] =~ /drupal/ && dependency.dig("source", "reference")
57
60
  end
@@ -6,10 +6,16 @@ module Bibliothecary
6
6
  INSTALL_REGEXP = /install_requires\s*=\s*\[([\s\S]*?)\]/
7
7
  REQUIRE_REGEXP = /([a-zA-Z0-9]+[a-zA-Z0-9\-_\.]+)([><=\w\.,]+)?/
8
8
  REQUIREMENTS_REGEXP = /^#{REQUIRE_REGEXP}/
9
- MANIFEST_REGEXP = /.*require[^\/]*(\/)?[^\/]*\.(txt|pip)$/
9
+ MANIFEST_REGEXP = /.*require[^\/]*(\/)?[^\/]*\.(txt|pip|in)$/
10
+ PIP_COMPILE_REGEXP = /.*require.*$/
10
11
 
11
12
  def self.mapping
12
13
  {
14
+ lambda { |p| PIP_COMPILE_REGEXP.match(p) } => {
15
+ content_matcher: :pip_compile?,
16
+ kind: 'lockfile',
17
+ parser: :parse_requirements_txt
18
+ },
13
19
  lambda { |p| MANIFEST_REGEXP.match(p) } => {
14
20
  kind: 'manifest',
15
21
  parser: :parse_requirements_txt,
@@ -174,6 +180,15 @@ module Bibliothecary
174
180
  end
175
181
  deps
176
182
  end
183
+
184
+ def self.pip_compile?(file_contents)
185
+ return file_contents.include?("This file is autogenerated by pip-compile")
186
+ rescue Exception # rubocop:disable Lint/RescueException
187
+ # We rescue exception here since native libs can throw a non-StandardError
188
+ # We don't want to throw errors during the matching phase, only during
189
+ # parsing after we match.
190
+ false
191
+ end
177
192
  end
178
193
  end
179
194
  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.0"
2
+ VERSION = "7.1.4"
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.0
4
+ version: 7.1.4
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: []