Class: LicenseFinder::Pip

Inherits:
PackageManager show all
Defined in:
lib/license_finder/package_managers/pip.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PackageManager

#active?, command_exists?, #current_packages_with_relations, #detected_package_path, installed?, takes_priority_over

Constructor Details

#initialize(options = {}) ⇒ Pip

Returns a new instance of Pip.



8
9
10
11
# File 'lib/license_finder/package_managers/pip.rb', line 8

def initialize(options = {})
  super
  @requirements_path = options[:pip_requirements_path] || Pathname('requirements.txt')
end

Class Method Details

.package_management_commandObject



26
27
28
# File 'lib/license_finder/package_managers/pip.rb', line 26

def self.package_management_command
  'pip'
end

.prepare_commandObject



30
31
32
# File 'lib/license_finder/package_managers/pip.rb', line 30

def self.prepare_command
  'pip install'
end

Instance Method Details

#current_packagesObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/license_finder/package_managers/pip.rb', line 13

def current_packages
  pip_output.map do |name, version, children, location|
    PipPackage.new(
      name,
      version,
      pypi_def(name, version),
      logger: logger,
      children: children,
      install_path: Pathname(location).join(name)
    )
  end
end

#possible_package_pathsObject



43
44
45
46
47
48
49
# File 'lib/license_finder/package_managers/pip.rb', line 43

def possible_package_paths
  if project_path.nil?
    [@requirements_path]
  else
    [project_path.join(@requirements_path)]
  end
end

#prepareObject



34
35
36
37
38
39
40
41
# File 'lib/license_finder/package_managers/pip.rb', line 34

def prepare
  prep_cmd = "#{Pip.prepare_command} -r #{@requirements_path}"
  _stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(prep_cmd) }
  return if status.success?

  log_errors stderr
  raise "Prepare command '#{prep_cmd}' failed" unless @prepare_no_fail
end