# frozen_string_literal: true

module LicenseFinder
  class PipPackage < Package
    LICENSE_FORMAT = /^License.*::\s*(.*)$/
    INVALID_LICENSES = ['', 'UNKNOWN'].to_set

    def self.license_names_from_spec(spec)
      license = spec['license'].to_s.strip

      return [license] unless INVALID_LICENSES.include?(license)

      spec
        .fetch('classifiers', [])
        .select { |c| c =~ LICENSE_FORMAT }
        .map { |c| c.gsub(LICENSE_FORMAT, '\1') }
    end

    def initialize(name, version, spec, options = {})
      super(
        name,
        version,
        options.merge(
          authors: spec['author'],
          summary: spec['summary'],
          description: spec['description'],
          homepage: spec['home_page'],
          spec_licenses: self.class.license_names_from_spec(spec)
        )
      )
    end

    def package_manager
      'Pip'
    end
  end
end

# frozen_string_literal: true

require 'set'

module LicenseFinder
  class PipPackage < Package
    LICENSE_FORMAT = /^License.*::\s*(.*)$/
    INVALID_LICENSES = ['', 'UNKNOWN'].to_set

    def self.license_names_from_spec(spec)
      license = spec['license'].to_s.strip

      return [license] unless INVALID_LICENSES.include?(license)

      spec
        .fetch('classifiers', [])
        .select { |c| c =~ LICENSE_FORMAT }
        .map { |c| c.gsub(LICENSE_FORMAT, '\1') }
    end

    def initialize(name, version, spec, options = {})
      super(
        name,
        version,
        options.merge(
          authors: spec['author'],
          summary: spec['summary'],
          description: spec['description'],
          homepage: spec['home_page'],
          spec_licenses: self.class.license_names_from_spec(spec)
        )
      )
    end

    def package_manager
      'Pip'
    end
  end
end

Add missing require for pip package
Add missing require for pip package

[#161131803]

Signed-off-by: Shane Lattanzio <8d464e6324483c505e61a33227a5372ac7f64bc0@pivotal.io>
