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 =

rubocop:disable Layout/LineLength

/git clone -q (?<url>[^\s]+).* /
GIT_REFERENCE_NOT_FOUND_REGEX =
%r{git checkout -q (?<tag>[^\n"]+)\n?[^\n]*/(?<name>.*?)(\\n'\]|$)}m
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)}/
UNSUPPORTED_DEPS =
%w(pyobjc).freeze
UNSUPPORTED_DEP_REGEX =
/Could not find a version that satisfies the requirement.*(?:#{UNSUPPORTED_DEPS.join("|")})/
PIPENV_RANGE_WARNING =
/Warning:\sPython\s[<>].* was not found/
DEPENDENCY_TYPES =

rubocop:enable Layout/LineLength

%w(packages dev-packages).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of PipenvVersionResolver.



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

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.



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

def credentials
  @credentials
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



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

def dependency
  @dependency
end

#dependency_filesObject (readonly)

Returns the value of attribute dependency_files.



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

def dependency_files
  @dependency_files
end

Instance Method Details

#latest_resolvable_version(requirement: nil) ⇒ Object



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

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)


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

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

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