Sha256: 26feb6e02e729ceb9fb0e837bf0079c45c2c1032e44351c34e3e40b4d42f5017

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Spandx
  module Parsers
    class PipfileLock < Base
      def self.matches?(filename)
        filename.match?(/Pipfile.*\.lock/)
      end

      def parse(lockfile)
        report = Report.new
        dependencies_from(lockfile) do |x|
          report.add(
            name: x[:name],
            version: x[:version],
            licenses: x[:licenses]
          )
        end
        report
      end

      private

      def dependencies_from(lockfile)
        json = JSON.parse(IO.read(lockfile))
        each_dependency(pypi_for(json), json) do |name, version, definition|
          yield({ name: name, version: version, licenses: [catalogue[definition['license']]] })
        end
      end

      def each_dependency(pypi, json, groups: %w[default develop])
        groups.each do |group|
          json[group].each do |name, value|
            version = canonicalize(value['version'])
            yield name, version, pypi.definition_for(name, version)
          end
        end
      end

      def canonicalize(version)
        version.gsub(/==/, '')
      end

      def pypi_for(json)
        Gateways::PyPI.new(
          sources: Gateways::PyPI::Source.sources_from(json)
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spandx-0.1.3 lib/spandx/parsers/pipfile_lock.rb
spandx-0.1.2 lib/spandx/parsers/pipfile_lock.rb