Sha256: e54656e7f7c0ad454a8b5568b087bc2d279173bc5e682d8b80180af78ee05f29

Contents?: true

Size: 1.46 KB

Versions: 38

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require "parallel"

module Licensed
  module Sources
    class Pipenv < Source
      def enabled?
        Licensed::Shell.tool_available?("pipenv") && File.exist?(config.pwd.join("Pipfile.lock"))
      end

      def enumerate_dependencies
        Parallel.map(pakages_from_pipfile_lock, in_threads: Parallel.processor_count) do |package_name|
          package = package_info(package_name)
          location = File.join(package["Location"], package["Name"].gsub("-", "_") +  "-" + package["Version"] + ".dist-info")
          Dependency.new(
            name: package["Name"],
            version: package["Version"],
            path: location,
            metadata: {
              "type"        => Pipenv.type,
              "summary"     => package["Summary"],
              "homepage"    => package["Home-page"]
            }
          )
        end
      end

      private

      def pakages_from_pipfile_lock
        Licensed::Shell.execute("pipenv", "run", "pip", "list")
            .lines
            .drop(2)  # Header
            .map { |line| line.strip.split.first.strip }
      end

      def package_info(package_name)
        p_info = Licensed::Shell.execute("pipenv", "run", "pip", "--disable-pip-version-check", "show", package_name).lines
        p_info.each_with_object(Hash.new(0)) { |pkg, a|
          k, v = pkg.split(":", 2)
          next if k.nil? || k.empty?
          a[k.strip] = v&.strip
        }
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
licensed-3.6.0 lib/licensed/sources/pipenv.rb
licensed-3.5.0 lib/licensed/sources/pipenv.rb
licensed-3.4.4 lib/licensed/sources/pipenv.rb
licensed-3.4.3 lib/licensed/sources/pipenv.rb
licensed-3.4.2 lib/licensed/sources/pipenv.rb
licensed-3.4.1 lib/licensed/sources/pipenv.rb
licensed-3.4.0 lib/licensed/sources/pipenv.rb
licensed-3.3.1 lib/licensed/sources/pipenv.rb
licensed-3.3.0 lib/licensed/sources/pipenv.rb
licensed-3.2.3 lib/licensed/sources/pipenv.rb
licensed-3.2.2 lib/licensed/sources/pipenv.rb
licensed-3.2.1 lib/licensed/sources/pipenv.rb
licensed-3.2.0 lib/licensed/sources/pipenv.rb
licensed-3.1.0 lib/licensed/sources/pipenv.rb
licensed-3.0.1 lib/licensed/sources/pipenv.rb
licensed-3.0.0 lib/licensed/sources/pipenv.rb
licensed-2.15.2 lib/licensed/sources/pipenv.rb
licensed-2.15.1 lib/licensed/sources/pipenv.rb
licensed-2.15.0 lib/licensed/sources/pipenv.rb
licensed-2.14.4 lib/licensed/sources/pipenv.rb