Class: Dependabot::Python::UpdateChecker

Inherits:
UpdateCheckers::Base
  • Object
show all
Defined in:
lib/dependabot/python/update_checker.rb,
lib/dependabot/python/update_checker/index_finder.rb,
lib/dependabot/python/update_checker/pip_version_resolver.rb,
lib/dependabot/python/update_checker/requirements_updater.rb,
lib/dependabot/python/update_checker/latest_version_finder.rb,
lib/dependabot/python/update_checker/pipenv_version_resolver.rb,
lib/dependabot/python/update_checker/poetry_version_resolver.rb,
lib/dependabot/python/update_checker/pip_compile_version_resolver.rb

Defined Under Namespace

Classes: IndexFinder, LatestVersionFinder, PipCompileVersionResolver, PipVersionResolver, PipenvVersionResolver, PoetryVersionResolver, RequirementsUpdater

Constant Summary collapse

MAIN_PYPI_INDEXES =
%w(
  https://pypi.python.org/simple/
  https://pypi.org/simple/
).freeze
VERSION_REGEX =
/[0-9]+(?:\.[A-Za-z0-9\-_]+)*/.freeze

Instance Method Summary collapse

Instance Method Details

#latest_resolvable_versionObject


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dependabot/python/update_checker.rb', line 35

def latest_resolvable_version
  @latest_resolvable_version ||=
    case resolver_type
    when :pipenv
      pipenv_version_resolver.latest_resolvable_version(
        requirement: unlocked_requirement_string
      )
    when :poetry
      poetry_version_resolver.latest_resolvable_version(
        requirement: unlocked_requirement_string
      )
    when :pip_compile
      pip_compile_version_resolver.latest_resolvable_version(
        requirement: unlocked_requirement_string
      )
    when :requirements
      pip_version_resolver.latest_resolvable_version
    else raise "Unexpected resolver type #{resolver_type}"
    end
end

#latest_resolvable_version_with_no_unlockObject


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dependabot/python/update_checker.rb', line 56

def latest_resolvable_version_with_no_unlock
  @latest_resolvable_version_with_no_unlock ||=
    case resolver_type
    when :pipenv
      pipenv_version_resolver.latest_resolvable_version(
        requirement: current_requirement_string
      )
    when :poetry
      poetry_version_resolver.latest_resolvable_version(
        requirement: current_requirement_string
      )
    when :pip_compile
      pip_compile_version_resolver.latest_resolvable_version(
        requirement: current_requirement_string
      )
    when :requirements
      pip_version_resolver.latest_resolvable_version_with_no_unlock
    else raise "Unexpected resolver type #{resolver_type}"
    end
end

#latest_versionObject


31
32
33
# File 'lib/dependabot/python/update_checker.rb', line 31

def latest_version
  @latest_version ||= fetch_latest_version
end

#lowest_resolvable_security_fix_versionObject


77
78
79
80
81
82
83
84
85
86
# File 'lib/dependabot/python/update_checker.rb', line 77

def lowest_resolvable_security_fix_version
  raise "Dependency not vulnerable!" unless vulnerable?

  if defined?(@lowest_resolvable_security_fix_version)
    return @lowest_resolvable_security_fix_version
  end

  @lowest_resolvable_security_fix_version =
    fetch_lowest_resolvable_security_fix_version
end

#requirements_update_strategyObject


97
98
99
100
101
102
103
104
105
# File 'lib/dependabot/python/update_checker.rb', line 97

def requirements_update_strategy
  # If passed in as an option (in the base class) honour that option
  if @requirements_update_strategy
    return @requirements_update_strategy.to_sym
  end

  # Otherwise, check if this is a poetry library or not
  poetry_library? ? :widen_ranges : :bump_versions
end

#updated_requirementsObject


88
89
90
91
92
93
94
95
# File 'lib/dependabot/python/update_checker.rb', line 88

def updated_requirements
  RequirementsUpdater.new(
    requirements: dependency.requirements,
    latest_resolvable_version: preferred_resolvable_version&.to_s,
    update_strategy: requirements_update_strategy,
    has_lockfile: !(pipfile_lock || poetry_lock || pyproject_lock).nil?
  ).updated_requirements
end