Class: LicenseFinder::Pip
- Inherits:
-
Object
- Object
- LicenseFinder::Pip
- Defined in:
- lib/license_finder/pip.rb
Constant Summary collapse
- GET_DEPENDENCIES_PY =
<<-PYTHON from pip.util import get_installed_distributions dists = [(x.project_name, x.version, x.location) for x in get_installed_distributions()] dists = ["[\\\"{0}\\\", \\\"{1}\\\", \\\"{2}\\\"]".format(*dist) for dist in dists] print "[" + ",".join(dists) + "]" PYTHON
Class Method Summary collapse
Class Method Details
.current_dists ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/license_finder/pip.rb', line 16 def self.current_dists return @dists if @dists command = GET_DEPENDENCIES_PY.gsub(/\n+/, ";") output = `python -c '#{command}'` @dists = JSON(output).map do |dist_ary| PythonPackage.new(OpenStruct.new( :name => dist_ary[0], :version => dist_ary[1], :full_gem_path => File.join(dist_ary[2], dist_ary[0]), :python? => true )) end end |
.has_requirements? ⇒ Boolean
33 34 35 |
# File 'lib/license_finder/pip.rb', line 33 def self.has_requirements? File.exists?(requirements_path) end |
.license_for(package) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/license_finder/pip.rb', line 37 def self.license_for(package) info = package.json license = info.fetch("license", "UNKNOWN") if license == "UNKNOWN" classifiers = info.fetch("classifiers", []) license = classifiers.map do |c| if c.start_with?("License") c.gsub(/^License.*::\s*(.*)$/, '\1') end end.compact.first end license || "other" end |