Sha256: a6e48a3077af9d8f6bd15be7b13c723b24bbc6a44667b1e83b93fc8f1dd414bf

Contents?: true

Size: 917 Bytes

Versions: 16

Compression:

Stored size: 917 Bytes

Contents

# frozen_string_literal: true

require 'set'

module LicenseFinder
  class PipPackage < Package
    LICENSE_FORMAT = /^License.*::\s*(.*)$/.freeze
    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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
license_finder-6.3.0 lib/license_finder/packages/pip_package.rb
license_finder-6.2.0 lib/license_finder/packages/pip_package.rb
license_finder-6.1.2 lib/license_finder/packages/pip_package.rb
license_finder-6.1.0 lib/license_finder/packages/pip_package.rb
license_finder-6.0.0 lib/license_finder/packages/pip_package.rb
license_finder-5.11.1 lib/license_finder/packages/pip_package.rb
license_finder-5.11.0 lib/license_finder/packages/pip_package.rb
license_finder-5.10.2 lib/license_finder/packages/pip_package.rb
license_finder-5.10.1 lib/license_finder/packages/pip_package.rb
license_finder-5.10.0 lib/license_finder/packages/pip_package.rb
license_finder-5.9.2 lib/license_finder/packages/pip_package.rb
license_finder-5.9.1 lib/license_finder/packages/pip_package.rb
license_finder-5.9.0 lib/license_finder/packages/pip_package.rb
license_finder-5.8.0 lib/license_finder/packages/pip_package.rb
license_finder-5.7.1 lib/license_finder/packages/pip_package.rb
license_finder-5.7.0 lib/license_finder/packages/pip_package.rb