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
PIPENV_INSTALLATION_ERROR =
"pipenv.patched.notpip._internal.exceptions.InstallationError: Command errored out"\
" with exit status 1: python setup.py egg_info"
TRACEBACK =
"Traceback (most recent call last):"
PIPENV_INSTALLATION_ERROR_REGEX =
/#{Regexp.quote(TRACEBACK)}[\s\S]*^\s+import\s(?<name>.+)[\s\S]*^#{Regexp.quote(PIPENV_INSTALLATION_ERROR)}/.
freeze
UNSUPPORTED_DEPS =
%w(pyobjc).freeze
UNSUPPORTED_DEP_REGEX =
/Could not find a version that satisfies the requirement.*(?:#{UNSUPPORTED_DEPS.join("|")})/.freeze
PIPENV_RANGE_WARNING =
/Warning:\sPython\s[<>].* was not found/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of PipenvVersionResolver.



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

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.



48
49
50
# File 'lib/dependabot/python/update_checker/pipenv_version_resolver.rb', line 48

def credentials
  @credentials
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



48
49
50
# File 'lib/dependabot/python/update_checker/pipenv_version_resolver.rb', line 48

def dependency
  @dependency
end

#dependency_filesObject (readonly)

Returns the value of attribute dependency_files.



48
49
50
# File 'lib/dependabot/python/update_checker/pipenv_version_resolver.rb', line 48

def dependency_files
  @dependency_files
end

Instance Method Details

#latest_resolvable_version(requirement: nil) ⇒ Object



56
57
58
59
60
61
# File 'lib/dependabot/python/update_checker/pipenv_version_resolver.rb', line 56

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)


63
64
65
66
67
68
# File 'lib/dependabot/python/update_checker/pipenv_version_resolver.rb', line 63

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

  @resolvable[version] = !!fetch_latest_resolvable_version_string(requirement: "==#{version}")
end