Class: LicenseFinder::Pip
Constant Summary
collapse
- DEFAULT_VERSION =
'3'
Instance Method Summary
collapse
#active?, #command_exists?, #current_packages_with_relations, #detected_package_path, id, #installed?, #project_root?, takes_priority_over
Constructor Details
#initialize(options = {}) ⇒ Pip
Returns a new instance of Pip.
9
10
11
12
13
14
|
# File 'lib/license_finder/package_managers/pip.rb', line 9
def initialize(options = {})
super
@requirements_path = options[:pip_requirements_path] || Pathname('requirements.txt')
@python_version = options[:python_version] || DEFAULT_VERSION
raise "Invalid python version \'#{@python_version}\'. Valid versions are '2' or '3'." unless %w[2 3].include?(@python_version)
end
|
Instance Method Details
#current_packages ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/license_finder/package_managers/pip.rb', line 16
def current_packages
pip_output.map do |name, version, children, location|
PipPackage.new(
name,
version,
PyPI.definition(name, version),
logger: logger,
children: children,
install_path: Pathname(location).join(name)
)
end
end
|
#package_management_command ⇒ Object
29
30
31
|
# File 'lib/license_finder/package_managers/pip.rb', line 29
def package_management_command
"pip#{@python_version}"
end
|
#possible_package_paths ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/license_finder/package_managers/pip.rb', line 46
def possible_package_paths
if project_path.nil?
[@requirements_path]
else
[project_path.join(@requirements_path)]
end
end
|
#prepare ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/license_finder/package_managers/pip.rb', line 37
def prepare
prep_cmd = "#{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
|
#prepare_command ⇒ Object
33
34
35
|
# File 'lib/license_finder/package_managers/pip.rb', line 33
def prepare_command
"pip#{@python_version} install"
end
|