Class: Dependabot::Python::UpdateChecker::RequirementsUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/python/update_checker/requirements_updater.rb

Defined Under Namespace

Classes: UnfixableRequirement

Constant Summary collapse

PYPROJECT_OR_SEPARATOR =
/(?<=[a-zA-Z0-9*])\s*\|+/.freeze
PYPROJECT_SEPARATOR =
/#{PYPROJECT_OR_SEPARATOR}|,/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(requirements:, update_strategy:, has_lockfile:, latest_resolvable_version:) ⇒ RequirementsUpdater

Returns a new instance of RequirementsUpdater.


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dependabot/python/update_checker/requirements_updater.rb', line 20

def initialize(requirements:, update_strategy:, has_lockfile:,
               latest_resolvable_version:)
  @requirements = requirements
  @update_strategy = update_strategy
  @has_lockfile = has_lockfile

  return unless latest_resolvable_version

  @latest_resolvable_version =
    Python::Version.new(latest_resolvable_version)
end

Instance Attribute Details

#has_lockfileObject (readonly)

Returns the value of attribute has_lockfile


17
18
19
# File 'lib/dependabot/python/update_checker/requirements_updater.rb', line 17

def has_lockfile
  @has_lockfile
end

#latest_resolvable_versionObject (readonly)

Returns the value of attribute latest_resolvable_version


17
18
19
# File 'lib/dependabot/python/update_checker/requirements_updater.rb', line 17

def latest_resolvable_version
  @latest_resolvable_version
end

#requirementsObject (readonly)

Returns the value of attribute requirements


17
18
19
# File 'lib/dependabot/python/update_checker/requirements_updater.rb', line 17

def requirements
  @requirements
end

#update_strategyObject (readonly)

Returns the value of attribute update_strategy


17
18
19
# File 'lib/dependabot/python/update_checker/requirements_updater.rb', line 17

def update_strategy
  @update_strategy
end

Instance Method Details

#updated_requirementsObject


32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dependabot/python/update_checker/requirements_updater.rb', line 32

def updated_requirements
  requirements.map do |req|
    case req[:file]
    when "setup.py" then updated_setup_requirement(req)
    when "pyproject.toml" then updated_pyproject_requirement(req)
    when "Pipfile" then updated_pipfile_requirement(req)
    when /\.txt$|\.in$/ then updated_requirement(req)
    else raise "Unexpected filename: #{req[:file]}"
    end
  end
end