Class: Spandx::Python::Pypi

Inherits:
Core::Gateway show all
Defined in:
lib/spandx/python/pypi.rb

Constant Summary collapse

SUBSTITUTIONS =
[
  '-py2.py3',
  '-py2',
  '-py3',
  '-none-any.whl',
  '.tar.gz',
  '.zip',
].freeze

Instance Method Summary collapse

Methods included from Core::Registerable

#all, #inherited, #registry

Constructor Details

#initialize(http: Spandx.http) ⇒ Pypi

Returns a new instance of Pypi.



15
16
17
18
# File 'lib/spandx/python/pypi.rb', line 15

def initialize(http: Spandx.http)
  @http = http
  @definitions = {}
end

Instance Method Details

#definition_for(name, version, sources: default_sources) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/spandx/python/pypi.rb', line 37

def definition_for(name, version, sources: default_sources)
  @definitions.fetch([name, version]) do |key|
    sources.each do |source|
      response = source.lookup(name, version)
      next if response.empty?

      match = response.fetch('info', {})
      @definitions[key] = match
      return match
    end
    {}
  end
end

#each(sources: default_sources) ⇒ Object



24
25
26
# File 'lib/spandx/python/pypi.rb', line 24

def each(sources: default_sources)
  each_package(sources) { |x| yield x }
end

#licenses_for(dependency) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/spandx/python/pypi.rb', line 28

def licenses_for(dependency)
  definition = definition_for(
    dependency.name,
    dependency.version,
    sources: sources_for(dependency)
  )
  [definition['license']]
end

#matches?(dependency) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/spandx/python/pypi.rb', line 20

def matches?(dependency)
  dependency.package_manager == :pypi
end

#version_from(url) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/spandx/python/pypi.rb', line 51

def version_from(url)
  path = cleanup(url)
  return if path.rindex('-').nil?

  section = path.scan(/-\d+\..*/)
  section = path.scan(/-\d+\.?.*/) if section.empty?
  section[-1][1..-1]
rescue StandardError => error
  warn([url, error].inspect)
end