Class: Dependabot::Python::PipenvRunner

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/python/pipenv_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, lockfile:, language_version_manager:, dependency_files: nil, repo_contents_path: nil) ⇒ PipenvRunner

Returns a new instance of PipenvRunner.



24
25
26
27
28
29
30
# File 'lib/dependabot/python/pipenv_runner.rb', line 24

def initialize(dependency:, lockfile:, language_version_manager:, dependency_files: nil, repo_contents_path: nil)
  @dependency = dependency
  @lockfile = lockfile
  @language_version_manager = language_version_manager
  @dependency_files = dependency_files
  @repo_contents_path = repo_contents_path
end

Instance Method Details

#run(command, fingerprint: nil) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/dependabot/python/pipenv_runner.rb', line 68

def run(command, fingerprint: nil)
  run_command(
    "pyenv local #{language_version_manager.python_major_minor}",
    fingerprint: "pyenv local <python_major_minor>"
  )

  run_command(command, fingerprint: fingerprint)
end

#run_pipenv_graph ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/dependabot/python/pipenv_runner.rb', line 57

def run_pipenv_graph
  SharedHelpers.in_a_temporary_repo_directory(base_directory, repo_contents_path) do
    File.write(".python-version", language_version_manager.python_major_minor)
    write_temporary_dependency_files
    language_version_manager.install_required_python
    run_command("pyenv exec pipenv sync --dev", fingerprint: "pyenv exec pipenv sync --dev")
    run_command("pyenv exec pipenv graph --json", fingerprint: "pyenv exec pipenv graph --json")
  end
end

#run_upgrade(constraint) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dependabot/python/pipenv_runner.rb', line 33

def run_upgrade(constraint)
  constraint = "" if constraint == "*"

  # Build the full package specification with extras
  extras_spec = extras_specification
  package_spec = "#{dependency_name}#{extras_spec}#{constraint}"

  command = "pyenv exec pipenv upgrade --verbose #{package_spec}"
  command << " --dev" if lockfile_section == "develop"

  run(command, fingerprint: "pyenv exec pipenv upgrade --verbose <dependency_name><extras><constraint>")
end

#run_upgrade_and_fetch_version(constraint) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/dependabot/python/pipenv_runner.rb', line 47

def run_upgrade_and_fetch_version(constraint)
  run_upgrade(constraint)

  updated_lockfile = JSON.parse(File.read("Pipfile.lock"))

  fetch_version_from_parsed_lockfile(updated_lockfile)
end