Module: Dependabot::Python::Helpers

Defined in:
lib/dependabot/python/helpers.rb

Class Method Summary collapse

Class Method Details

.install_required_python(python_version) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dependabot/python/helpers.rb', line 9

def self.install_required_python(python_version)
  # The leading space is important in the version check
  return if SharedHelpers.run_shell_command("pyenv versions").include?(" #{python_major_minor(python_version)}.")

  if File.exist?("/usr/local/.pyenv/#{python_major_minor(python_version)}.tar.gz")
    SharedHelpers.run_shell_command(
      "tar xzf /usr/local/.pyenv/#{python_major_minor(python_version)}.tar.gz -C /usr/local/.pyenv/"
    )
    return if SharedHelpers.run_shell_command("pyenv versions").
              include?(" #{python_major_minor(python_version)}.")
  end

  Dependabot.logger.info("Installing required Python #{python_version}.")
  start = Time.now
  SharedHelpers.run_shell_command("pyenv install -s #{python_version}")
  SharedHelpers.run_shell_command("pyenv exec pip install --upgrade pip")
  SharedHelpers.run_shell_command("pyenv exec pip install -r" \
                                  "#{NativeHelpers.python_requirements_path}")
  time_taken = Time.now - start
  Dependabot.logger.info("Installing Python #{python_version} took #{time_taken}s.")
end

.python_major_minor(python_version) ⇒ Object



31
32
33
34
# File 'lib/dependabot/python/helpers.rb', line 31

def self.python_major_minor(python_version)
  python = Python::Version.new(python_version)
  "#{python.segments[0]}.#{python.segments[1]}"
end