Sha256: bbeabfdd2ae73942f0362f2b65df703e72712f17ff11983c7d609175ea1166fb

Contents?: true

Size: 1.45 KB

Versions: 22

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require 'json'
require 'license_finder/package_utils/pypi'

module LicenseFinder
  class Pipenv < PackageManager
    def initialize(options = {})
      super
      @lockfile = Pathname('Pipfile.lock')
    end

    def current_packages
      @current_packages ||=
        begin
          packages = {}
          each_dependency(groups: allowed_groups) do |name, data, group|
            version = canonicalize(data['version'] || 'unknown')
            package = packages.fetch(key_for(name, version)) do |key|
              packages[key] = build_package_for(name, version)
            end
            package.groups << group
          end
          packages.values
        end
    end

    def possible_package_paths
      project_path ? [project_path.join(@lockfile)] : [@lockfile]
    end

    private

    def each_dependency(groups: [])
      dependencies = JSON.parse(IO.read(detected_package_path))
      groups.each do |group|
        dependencies[group].each do |name, data|
          yield name, data, group
        end
      end
    end

    def canonicalize(version)
      version.sub(/^==/, '')
    end

    def build_package_for(name, version)
      PipPackage.new(name, version, PyPI.definition(name, version))
    end

    def key_for(name, version)
      "#{name}-#{version}"
    end

    def allowed_groups
      %w[default develop] - ignored_groups.to_a
    end

    def ignored_groups
      @ignored_groups || []
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
license_finder-7.1.0 lib/license_finder/package_managers/pipenv.rb
license_finder-7.0.1 lib/license_finder/package_managers/pipenv.rb
license_finder-7.0.0 lib/license_finder/package_managers/pipenv.rb
license_finder-6.15.0 lib/license_finder/package_managers/pipenv.rb
gitlab-license_finder-6.14.2.1 lib/license_finder/package_managers/pipenv.rb
license_finder-6.14.2 lib/license_finder/package_managers/pipenv.rb
license_finder-6.14.1 lib/license_finder/package_managers/pipenv.rb
license_finder-6.13.0 lib/license_finder/package_managers/pipenv.rb
license_finder-6.12.2 lib/license_finder/package_managers/pipenv.rb
license_finder-6.12.1 lib/license_finder/package_managers/pipenv.rb
license_finder-6.12.0 lib/license_finder/package_managers/pipenv.rb
license_finder-6.11.0 lib/license_finder/package_managers/pipenv.rb
license_finder-6.10.1 lib/license_finder/package_managers/pipenv.rb
license_finder-6.10.0 lib/license_finder/package_managers/pipenv.rb
license_finder-6.9.0 lib/license_finder/package_managers/pipenv.rb
license_finder-6.8.2 lib/license_finder/package_managers/pipenv.rb
license_finder-6.8.1 lib/license_finder/package_managers/pipenv.rb
license_finder-6.8.0 lib/license_finder/package_managers/pipenv.rb
license_finder-6.7.0 lib/license_finder/package_managers/pipenv.rb
license_finder-6.6.2 lib/license_finder/package_managers/pipenv.rb