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, #ignored?, inherited, #initialize, type

Constructor Details

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

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/licensed/sources/pip.rb', line 11

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

#enumerate_dependenciesObject



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

def enumerate_dependencies
  packages_from_requirements_txt.map 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