bibliothecary 0.5.0 → 0.6.0

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
  SHA1:
3
- metadata.gz: 4ff29254b4b1268e9918db8491344bf0711d7e91
4
- data.tar.gz: 94432e857d325e1027090256a4c7a1c988f34249
3
+ metadata.gz: a67d57b472bf02d8d8fb27c80919830b1649dee5
4
+ data.tar.gz: 98a22efc4e031347042480c722c199d113c98877
5
5
  SHA512:
6
- metadata.gz: 063ebc1e296edddf39c00b451186deabf69594f9430e8a80e0d49a00b47ebdbdf302c14e0f1ec953b17580575dbf265c456ef0979cd9c0105e5b21eedc5995fe
7
- data.tar.gz: b23f49b418ed67fd59e49cf83875e8fad372891272825b7e04f3d1a74ce38af5c315da30d7e40387d319b4cd12961852e3bdf41ef0b9eff62bbdb73742676460
6
+ metadata.gz: 797c3527fa27674d2e8a2b3813a874a2213e65896cb241f6f0b3430d90944142525a1c83e2134d963a1b27e3a749200ad7d83c8fee69ece0e09c5449c44384bf
7
+ data.tar.gz: f05ce01865885c86fb7592c9bfffe1a5b300705c6170853354c48634e616cc20a11fa5a281caaa297edf4c6133a70812e3968e9cd81ee5c8bc53cc5d66b6b4cb
@@ -1,5 +1,85 @@
1
- # setup.py
2
- # req*.txt
3
- # req*.pip
4
- # requirements/*.txt
5
- # requirements/*.pip
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
@@ -1,3 +1,3 @@
1
1
  module Bibliothecary
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibliothecary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt