Class: Dependabot::Python::UpdateChecker::PipenvVersionResolver

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

Overview

This class does version resolution for Pipfiles. Its current approach is somewhat crude:

  • Unlock the dependency we’re checking in the Pipfile

  • Freeze all of the other dependencies in the Pipfile

  • Run ‘pipenv lock` and see what the result is

Unfortunately, Pipenv doesn’t resolve how we’d expect - it appears to just raise if the latest version can’t be resolved. Knowing that is still better than nothing, though.

Constant Summary collapse

GIT_DEPENDENCY_UNREACHABLE_REGEX =
/git clone -q (?<url>[^\s]+).* /.freeze
GIT_REFERENCE_NOT_FOUND_REGEX =
%r{git checkout -q (?<tag>[^\n"]+)\n?[^\n]*/(?<name>.*?)(\\n'\]|$)}m.
freeze
UNSUPPORTED_DEPS =
%w(pyobjc).freeze
UNSUPPORTED_DEP_REGEX =
/"python setup\.py egg_info".*(?:#{UNSUPPORTED_DEPS.join("|")})/.
freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, dependency_files:, credentials:) ⇒ PipenvVersionResolver

Returns a new instance of PipenvVersionResolver.



45
46
47
48
49
# File 'lib/dependabot/python/update_checker/pipenv_version_resolver.rb', line 45

def initialize(dependency:, dependency_files:, credentials:)
  @dependency               = dependency
  @dependency_files         = dependency_files
  @credentials              = credentials
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



43
44
45
# File 'lib/dependabot/python/update_checker/pipenv_version_resolver.rb', line 43

def credentials
  @credentials
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



43
44
45
# File 'lib/dependabot/python/update_checker/pipenv_version_resolver.rb', line 43

def dependency
  @dependency
end

#dependency_filesObject (readonly)

Returns the value of attribute dependency_files.



43
44
45
# File 'lib/dependabot/python/update_checker/pipenv_version_resolver.rb', line 43

def dependency_files
  @dependency_files
end

Instance Method Details

#latest_resolvable_version(requirement: nil) ⇒ Object



51
52
53
54
55
56
# File 'lib/dependabot/python/update_checker/pipenv_version_resolver.rb', line 51

def latest_resolvable_version(requirement: nil)
  version_string =
    fetch_latest_resolvable_version_string(requirement: requirement)

  version_string.nil? ? nil : Python::Version.new(version_string)
end

#resolvable?(version:) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
# File 'lib/dependabot/python/update_checker/pipenv_version_resolver.rb', line 58

def resolvable?(version:)
  @resolvable ||= {}
  return @resolvable[version] if @resolvable.key?(version)

  if fetch_latest_resolvable_version_string(requirement: "==#{version}")
    @resolvable[version] = true
  else
    @resolvable[version] = false
  end
end