bibliothecary 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bibliothecary/parsers/pypi.rb +85 -5
- data/lib/bibliothecary/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a67d57b472bf02d8d8fb27c80919830b1649dee5
|
4
|
+
data.tar.gz: 98a22efc4e031347042480c722c199d113c98877
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 797c3527fa27674d2e8a2b3813a874a2213e65896cb241f6f0b3430d90944142525a1c83e2134d963a1b27e3a749200ad7d83c8fee69ece0e09c5449c44384bf
|
7
|
+
data.tar.gz: f05ce01865885c86fb7592c9bfffe1a5b300705c6170853354c48634e616cc20a11fa5a281caaa297edf4c6133a70812e3968e9cd81ee5c8bc53cc5d66b6b4cb
|
@@ -1,5 +1,85 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Bibliothecary
|
2
|
+
module Parsers
|
3
|
+
class Pypi
|
4
|
+
PLATFORM_NAME = 'pypi'
|
5
|
+
INSTALL_REGEXP = /install_requires\s*=\s*\[([\s\S]*?)\]/
|
6
|
+
REQUIRE_REGEXP = /([a-zA-Z0-9]+[a-zA-Z0-9-_\.]+)([><=\d\.,]+)?/
|
7
|
+
REQUIREMENTS_REGEXP = /^#{REQUIRE_REGEXP}/
|
8
|
+
|
9
|
+
def self.parse(filename, file_contents)
|
10
|
+
if filename.match(/require.*\.(txt|pip)$/) && !filename.match(/^node_modules/)
|
11
|
+
parse_requirements_txt(file_contents)
|
12
|
+
elsif filename.match(/^setup\.py$/)
|
13
|
+
parse_setup_py(file_contents)
|
14
|
+
else
|
15
|
+
[]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.analyse(folder_path, file_list)
|
20
|
+
[analyse_requirements_txt(folder_path, file_list),
|
21
|
+
analyse_setup_py(folder_path, file_list)]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.analyse_requirements_txt(folder_path, file_list)
|
25
|
+
path = file_list.find do |path|
|
26
|
+
p = path.gsub(folder_path, '').gsub(/^\//, '')
|
27
|
+
p.match(/require.*\.(txt|pip)$/) && !path.match(/^node_modules/)
|
28
|
+
end
|
29
|
+
return unless path
|
30
|
+
|
31
|
+
manifest = File.open(path).read
|
32
|
+
|
33
|
+
{
|
34
|
+
platform: PLATFORM_NAME,
|
35
|
+
path: path,
|
36
|
+
dependencies: parse_requirements_txt(manifest)
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.analyse_setup_py(folder_path, file_list)
|
41
|
+
path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^setup\.py$/) }
|
42
|
+
return unless path
|
43
|
+
|
44
|
+
manifest = File.open(path).read
|
45
|
+
|
46
|
+
{
|
47
|
+
platform: PLATFORM_NAME,
|
48
|
+
path: path,
|
49
|
+
dependencies: parse_setup_py(manifest)
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.parse_setup_py(manifest)
|
54
|
+
match = manifest.match(INSTALL_REGEXP)
|
55
|
+
return [] unless match
|
56
|
+
deps = []
|
57
|
+
match[1].gsub(/',(\s)?'/, "\n").split("\n").each do |line|
|
58
|
+
next if line.match(/^#/)
|
59
|
+
match = line.match(REQUIRE_REGEXP)
|
60
|
+
next unless match
|
61
|
+
deps << {
|
62
|
+
name: match[1],
|
63
|
+
requirement: match[2] || '*',
|
64
|
+
type: 'runtime'
|
65
|
+
}
|
66
|
+
end
|
67
|
+
deps
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.parse_requirements_txt(manifest)
|
71
|
+
deps = []
|
72
|
+
manifest.split("\n").each do |line|
|
73
|
+
match = line.match(REQUIREMENTS_REGEXP)
|
74
|
+
next unless match
|
75
|
+
deps << {
|
76
|
+
name: match[1],
|
77
|
+
requirement: match[2] || '*',
|
78
|
+
type: 'runtime'
|
79
|
+
}
|
80
|
+
end
|
81
|
+
deps
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|