-
Notifications
You must be signed in to change notification settings - Fork 35
/
conda.rb
59 lines (53 loc) · 1.95 KB
/
conda.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require "json"
module Bibliothecary
module Parsers
class Conda
include Bibliothecary::Analyser
def self.mapping
{
match_filename("environment.yml") => {
parser: :parse_conda,
kind: "manifest",
},
match_filename("environment.yaml") => {
parser: :parse_conda,
kind: "manifest",
},
match_filename("environment.yml.lock") => {
parser: :parse_conda_lockfile,
kind: "lockfile",
},
match_filename("environment.yaml.lock") => {
parser: :parse_conda_lockfile,
kind: "lockfile",
},
}
end
def self.parse_conda(info)
dependencies = call_conda_parser_web(info, :manifest)[:manifest]
dependencies.map { |dep| dep.merge(type: "runtime") }
end
def self.parse_conda_lockfile(info)
dependencies = call_conda_parser_web(info, :lockfile)[:lockfile]
dependencies.map { |dep| dep.merge(type: "runtime") }
end
private_class_method def self.call_conda_parser_web(file_contents, kind)
host = Bibliothecary.configuration.conda_parser_host
response = Typhoeus.post(
"#{host}/parse",
headers: {
ContentType: "multipart/form-data",
},
body: {
file: file_contents,
# Sending the filename with .lock if this is a lockfile, request, and just .yml if it is a manifest.
# This allows us to not have to create a .lock file anywhere, except in this post as the filename parameter
filename: kind == "manifest" ? "environment.yml" : "environment.yml.lock",
}
)
raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{host}/parse", response.response_code) unless response.success?
JSON.parse(response.body, symbolize_names: true)
end
end
end
end