bibliothecary 7.3.2 → 7.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/bibliothecary/analyser.rb +24 -1
- data/lib/bibliothecary/parsers/generic.rb +39 -0
- data/lib/bibliothecary/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb1338bc28ebb3dde8a6bdb5037f000176b9d759aa391319e74cbc85a35bd0ad
|
4
|
+
data.tar.gz: 8acc8a5acddd673c79680cefe8f0af6e325fd21905eb82da8751a01df81dac2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b078d0d7b486f79911d2f4426c431fc61353d6f326e173faaa7b3a6154cbb8dd77f1d0e0e0ceca50e78ed646cded4490e22a2dc7f324d8d041276b41e430952d
|
7
|
+
data.tar.gz: e6bb42ee137c6e9a5eeeee0f375c2a6362e822af1011ad6f92d101d7f1b4d7c9ea8dee04925846e5efd3ea553d0e57f6fde4c1e678d7cb8aaa07eab458d00fed
|
data/.gitignore
CHANGED
@@ -25,6 +25,10 @@ module Bibliothecary
|
|
25
25
|
base.extend(ClassMethods)
|
26
26
|
end
|
27
27
|
module ClassMethods
|
28
|
+
def generic?
|
29
|
+
platform_name == "generic"
|
30
|
+
end
|
31
|
+
|
28
32
|
def mapping_entry_match?(matcher, details, info)
|
29
33
|
if matcher.call(info.relative_path)
|
30
34
|
# we only want to load contents if we don't have them already
|
@@ -119,13 +123,32 @@ module Bibliothecary
|
|
119
123
|
end
|
120
124
|
alias analyze_contents analyse_contents
|
121
125
|
|
126
|
+
def dependencies_to_analysis(info, kind, dependencies)
|
127
|
+
dependencies = dependencies || [] # work around any legacy parsers that return nil
|
128
|
+
if generic?
|
129
|
+
analyses = []
|
130
|
+
grouped = dependencies.group_by { |dep| dep[:platform] }
|
131
|
+
all_analyses = grouped.keys.map do |platform|
|
132
|
+
deplatformed_dependencies = grouped[platform].map { |d| d.delete(:platform); d }
|
133
|
+
Bibliothecary::Analyser::create_analysis(platform, info.relative_path, kind, deplatformed_dependencies)
|
134
|
+
end
|
135
|
+
# this is to avoid a larger refactor for the time being. The larger refactor
|
136
|
+
# needs to make analyse_contents return multiple analysis, or add another
|
137
|
+
# method that can return multiple and deprecate analyse_contents, perhaps.
|
138
|
+
raise "File contains zero or multiple platforms, currently must have exactly one" if all_analyses.length != 1
|
139
|
+
all_analyses.first
|
140
|
+
else
|
141
|
+
Bibliothecary::Analyser::create_analysis(platform_name, info.relative_path, kind, dependencies)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
122
145
|
def analyse_contents_from_info(info)
|
123
146
|
# If your Parser needs to return multiple responses for one file, please override this method
|
124
147
|
# For example see conda.rb
|
125
148
|
kind = determine_kind_from_info(info)
|
126
149
|
dependencies = parse_file(info.relative_path, info.contents)
|
127
150
|
|
128
|
-
|
151
|
+
dependencies_to_analysis(info, kind, dependencies)
|
129
152
|
rescue Bibliothecary::FileParsingError => e
|
130
153
|
Bibliothecary::Analyser::create_error_analysis(platform_name, info.relative_path, kind, e.message)
|
131
154
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Bibliothecary
|
4
|
+
module Parsers
|
5
|
+
class Generic
|
6
|
+
include Bibliothecary::Analyser
|
7
|
+
|
8
|
+
def self.mapping
|
9
|
+
{
|
10
|
+
match_filename("dependencies.csv") => {
|
11
|
+
kind: 'lockfile',
|
12
|
+
parser: :parse_lockfile
|
13
|
+
}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.parse_lockfile(file_contents)
|
18
|
+
table = CSV.parse(file_contents, headers: true)
|
19
|
+
|
20
|
+
required_headers = ["platform", "name", "requirement"]
|
21
|
+
missing_headers = required_headers - table.headers
|
22
|
+
raise "Missing headers #{missing_headers} in CSV" unless missing_headers.empty?
|
23
|
+
|
24
|
+
table.map.with_index do |row, idx|
|
25
|
+
line = idx + 1
|
26
|
+
required_headers.each do |h|
|
27
|
+
raise "missing field '#{h}' on line #{line}" if row[h].empty?
|
28
|
+
end
|
29
|
+
{
|
30
|
+
platform: row['platform'],
|
31
|
+
name: row['name'],
|
32
|
+
requirement: row['requirement'],
|
33
|
+
type: row.fetch('type', 'runtime'),
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
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.3.
|
4
|
+
version: 7.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Nesbitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tomlrb
|
@@ -251,6 +251,7 @@ files:
|
|
251
251
|
- lib/bibliothecary/parsers/cran.rb
|
252
252
|
- lib/bibliothecary/parsers/dub.rb
|
253
253
|
- lib/bibliothecary/parsers/elm.rb
|
254
|
+
- lib/bibliothecary/parsers/generic.rb
|
254
255
|
- lib/bibliothecary/parsers/go.rb
|
255
256
|
- lib/bibliothecary/parsers/hackage.rb
|
256
257
|
- lib/bibliothecary/parsers/haxelib.rb
|