1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# frozen_string_literal: true
module LicenseFinder
class Pipenv
def prepare
return unless pipfile?
shell.execute([:pipenv, '--python', python.version])
shell.execute([:pipenv, :run, :pipenv, :sync, '--pypi-mirror', python.pip_index_url])
end
def current_packages
return legacy_results unless pipfile?
python.pip_licenses
end
private
def shell
@shell ||= ::License::Management::Shell.new
end
def python
@python ||= ::License::Management::Python.new
end
def pipfile?
detected_package_path.dirname.join('Pipfile').exist?
end
def legacy_results
packages = {}
each_dependency(groups: allowed_groups) do |name, data, group|
version = canonicalize(data['version'])
package = packages.fetch(key_for(name, version)) do |key|
packages[key] = build_package_for(name, version)
end
package.groups << group
end
packages.values
end
def build_package_for(name, version)
PipPackage.new(name, version, pypi.definition_for(name, version))
end
def pypi
@pypi ||= ::Spandx::Python::PyPI.new(sources: ::Spandx::Python::Source.sources_from(lockfile_hash))
end
def lockfile_hash
@lockfile_hash ||= JSON.parse(IO.read(detected_package_path))
end
end
end
|