Class: Licensed::Sources::Pip

Inherits:
Source
  • Object
show all
Defined in:
lib/licensed/sources/pip.rb

Constant Summary collapse

VERSION_OPERATORS =
%w(< > <= >= == !=).freeze
PACKAGE_REGEX =
/^([\w\.-]+)(#{VERSION_OPERATORS.join("|")})?/

Instance Attribute Summary

Attributes inherited from Source

#config

Instance Method Summary collapse

Methods inherited from Source

#dependencies, full_type, #ignored?, inherited, #initialize, type, type_and_version

Constructor Details

This class inherits a constructor from Licensed::Sources::Source

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/licensed/sources/pip.rb', line 13

def enabled?
  return unless virtual_env_pip && Licensed::Shell.tool_available?(virtual_env_pip)
  File.exist?(config.pwd.join("requirements.txt"))
end

#enumerate_dependenciesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/licensed/sources/pip.rb', line 18

def enumerate_dependencies
  Parallel.map(packages_from_requirements_txt, 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"        => Pip.type,
        "summary"     => package["Summary"],
        "homepage"    => package["Home-page"]
      }
    )
  end
end