class Bibliothecary::Parsers::Conda

Public Class Methods

call_conda_parser_web(file_contents, kind) click to toggle source
# File lib/bibliothecary/parsers/conda.rb, line 46
                     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
mapping() click to toggle source
# File lib/bibliothecary/parsers/conda.rb, line 8
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
parse_conda(file_contents, options: {}) click to toggle source
# File lib/bibliothecary/parsers/conda.rb, line 33
def self.parse_conda(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument
  parse_conda_with_kind(file_contents, "manifest")
end
parse_conda_lockfile(file_contents, options: {}) click to toggle source
# File lib/bibliothecary/parsers/conda.rb, line 37
def self.parse_conda_lockfile(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument
  parse_conda_with_kind(file_contents, "lockfile")
end
parse_conda_with_kind(info, kind) click to toggle source
# File lib/bibliothecary/parsers/conda.rb, line 41
def self.parse_conda_with_kind(info, kind)
  dependencies = call_conda_parser_web(info, kind)[kind.to_sym]
  dependencies.map { |dep_kv| Dependency.new(**dep_kv.merge(type: "runtime")) }
end