Sha256: d1775ac1f62c6b5a43006bbe87c9c1070528b7711f820774874fd1e9c9a0ff81
Contents?: true
Size: 1.85 KB
Versions: 21
Compression:
Stored size: 1.85 KB
Contents
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, # Unfortunately we do not get the filename in the mapping parsers, so hardcoding the file name depending on the kind 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
Version data entries
21 entries across 21 versions & 1 rubygems