Class: Dependabot::Python::FileParser::PythonRequirementParser

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/python/file_parser/python_requirement_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependency_files:) ⇒ PythonRequirementParser

Returns a new instance of PythonRequirementParser.



18
19
20
# File 'lib/dependabot/python/file_parser/python_requirement_parser.rb', line 18

def initialize(dependency_files:)
  @dependency_files = dependency_files
end

Instance Attribute Details

#dependency_filesObject (readonly)

Returns the value of attribute dependency_files.



16
17
18
# File 'lib/dependabot/python/file_parser/python_requirement_parser.rb', line 16

def dependency_files
  @dependency_files
end

Instance Method Details

#imputed_requirementsObject

TODO: Add better Python version detection using dependency versions (e.g., Django 2.x implies Python 3)



35
36
37
38
39
40
41
42
43
# File 'lib/dependabot/python/file_parser/python_requirement_parser.rb', line 35

def imputed_requirements
  requirement_files.flat_map do |file|
    file.content.lines
        .select { |l| l.include?(";") && l.include?("python") }
        .filter_map { |l| l.match(/python_version(?<req>.*?["'].*?['"])/) }
        .map { |re| re.named_captures.fetch("req").gsub(/['"]/, "") }
        .select { |r| valid_requirement?(r) }
  end
end

#user_specified_requirementsObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/dependabot/python/file_parser/python_requirement_parser.rb', line 22

def user_specified_requirements
  [
    pipfile_python_requirement,
    pyproject_python_requirement,
    pip_compile_python_requirement,
    python_version_file_version,
    runtime_file_python_version,
    setup_file_requirement
  ].compact
end