Class: Dependabot::Python::UpdateChecker::PipCompileVersionResolver

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

Overview

This class does version resolution for pip-compile. Its approach is:

  • Unlock the dependency we’re checking in the requirements.in file

  • Run ‘pip-compile` and see what the result is

Constant Summary collapse

GIT_DEPENDENCY_UNREACHABLE_REGEX =
/git clone --filter=blob:none --quiet (?<url>[^\s]+).* /
GIT_REFERENCE_NOT_FOUND_REGEX =
/Did not find branch or tag '(?<tag>[^\n"]+)'/m
NATIVE_COMPILATION_ERROR =
"pip._internal.exceptions.InstallationSubprocessError: Getting requirements to build wheel exited with 1"
PYTHON_PACKAGE_NAME_REGEX =
/[A-Za-z0-9_\-]+/
RESOLUTION_IMPOSSIBLE_ERROR =
"ResolutionImpossible"
ERROR_REGEX =
/(?<=ERROR\:\W).*$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, dependency_files:, credentials:, repo_contents_path:) ⇒ PipCompileVersionResolver

Returns a new instance of PipCompileVersionResolver.



41
42
43
44
45
46
47
# File 'lib/dependabot/python/update_checker/pip_compile_version_resolver.rb', line 41

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

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



38
39
40
# File 'lib/dependabot/python/update_checker/pip_compile_version_resolver.rb', line 38

def credentials
  @credentials
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



36
37
38
# File 'lib/dependabot/python/update_checker/pip_compile_version_resolver.rb', line 36

def dependency
  @dependency
end

#dependency_filesObject (readonly)

Returns the value of attribute dependency_files.



37
38
39
# File 'lib/dependabot/python/update_checker/pip_compile_version_resolver.rb', line 37

def dependency_files
  @dependency_files
end

#repo_contents_pathObject (readonly)

Returns the value of attribute repo_contents_path.



39
40
41
# File 'lib/dependabot/python/update_checker/pip_compile_version_resolver.rb', line 39

def repo_contents_path
  @repo_contents_path
end

Instance Method Details

#latest_resolvable_version(requirement: nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/dependabot/python/update_checker/pip_compile_version_resolver.rb', line 49

def latest_resolvable_version(requirement: nil)
  @latest_resolvable_version_string ||= {}
  return @latest_resolvable_version_string[requirement] if @latest_resolvable_version_string.key?(requirement)

  version_string =
    fetch_latest_resolvable_version_string(requirement: requirement)

  @latest_resolvable_version_string[requirement] ||=
    version_string.nil? ? nil : Python::Version.new(version_string)
end

#resolvable?(version:) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
67
68
69
# File 'lib/dependabot/python/update_checker/pip_compile_version_resolver.rb', line 60

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

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