Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require "dependabot/python/file_parser/python_requirement_parser"
require "dependabot/python/file_updater"
require "dependabot/shared_helpers"
require "dependabot/python/helpers"
require "dependabot/python/native_helpers"
require "dependabot/python/python_versions"
require "dependabot/python/name_normaliser"
Expand Down Expand Up @@ -65,7 +66,7 @@ def fetch_updated_dependency_files
def compile_new_requirement_files
SharedHelpers.in_a_temporary_directory do
write_updated_dependency_files
install_required_python
Helpers.install_required_python(python_version)

filenames_to_compile.each do |filename|
# Shell out to pip-compile, generate a new set of requirements.
Expand Down Expand Up @@ -212,16 +213,6 @@ def write_updated_dependency_files
end
end

def install_required_python
# The leading space is important
return if run_command("pyenv versions").include?(" #{python_version}")

run_command("pyenv install -s #{python_version}")
run_command("pyenv exec pip install --upgrade pip")
run_command("pyenv exec pip install -r " \
"#{NativeHelpers.python_requirements_path}")
end

def sanitized_setup_file_content(file)
@sanitized_setup_file_content ||= {}
return @sanitized_setup_file_content[file.name] if @sanitized_setup_file_content[file.name]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,7 @@ def install_required_python
nil
end

return if run_command("pyenv versions").include?("#{python_version}\n")

requirements_path = NativeHelpers.python_requirements_path
run_command("pyenv install -s #{python_version}")
run_command("pyenv exec pip install -r #{requirements_path}")
Helpers.install_required_python(python_version)
end

def sanitized_setup_file_content(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "open3"
require "dependabot/dependency"
require "dependabot/shared_helpers"
require "dependabot/python/helpers"
require "dependabot/python/version"
require "dependabot/python/requirement"
require "dependabot/python/python_versions"
Expand Down Expand Up @@ -170,12 +171,7 @@ def updated_lockfile_content_for(pyproject_content)
write_temporary_dependency_files(pyproject_content)
add_auth_env_vars

if python_version && !pre_installed_python?(python_version)
run_poetry_command("pyenv install -s #{python_version}")
run_poetry_command("pyenv exec pip install --upgrade pip")
run_poetry_command("pyenv exec pip install -r" \
"#{NativeHelpers.python_requirements_path}")
end
Helpers.install_required_python(python_version)

# use system git instead of the pure Python dulwich
unless python_version&.start_with?("3.6")
Expand Down
20 changes: 20 additions & 0 deletions python/lib/dependabot/python/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require "dependabot/logger"

module Dependabot
module Python
module Helpers
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_version}")

Dependabot.logger.info("Installing required Python #{python_version}.")
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}")
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require "dependabot/python/file_updater/setup_file_sanitizer"
require "dependabot/python/version"
require "dependabot/shared_helpers"
require "dependabot/python/helpers"
require "dependabot/python/native_helpers"
require "dependabot/python/python_versions"
require "dependabot/python/name_normaliser"
Expand Down Expand Up @@ -70,7 +71,7 @@ def fetch_latest_resolvable_version_string(requirement:)
SharedHelpers.in_a_temporary_directory do
SharedHelpers.with_git_configured(credentials: credentials) do
write_temporary_dependency_files(updated_req: requirement)
install_required_python
Helpers.install_required_python(python_version)

filenames_to_compile.each do |filename|
# Shell out to pip-compile.
Expand Down Expand Up @@ -319,16 +320,6 @@ def write_original_manifest_files
end
end

def install_required_python
# The leading space is important
return if run_command("pyenv versions").include?(" #{python_version}")

run_command("pyenv install -s #{python_version}")
run_command("pyenv exec pip install --upgrade pip")
run_command("pyenv exec pip install -r" \
"#{NativeHelpers.python_requirements_path}")
end

def sanitized_setup_file_content(file)
@sanitized_setup_file_content ||= {}
return @sanitized_setup_file_content[file.name] if @sanitized_setup_file_content[file.name]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,7 @@ def install_required_python
nil
end

# The leading space is important
return if run_command("pyenv versions").include?(" #{python_version}")

requirements_path = NativeHelpers.python_requirements_path
run_command("pyenv install -s #{python_version}")
run_command("pyenv exec pip install --upgrade pip")
run_command("pyenv exec pip install -r " \
"#{requirements_path}")
Helpers.install_required_python(python_version)
end

def sanitized_setup_file_content(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def resolvable?(version:)

private

# rubocop:disable Metrics/PerceivedComplexity
def fetch_latest_resolvable_version_string(requirement:)
@latest_resolvable_version_string ||= {}
return @latest_resolvable_version_string[requirement] if @latest_resolvable_version_string.key?(requirement)
Expand All @@ -93,14 +92,7 @@ def fetch_latest_resolvable_version_string(requirement:)
write_temporary_dependency_files(updated_req: requirement)
add_auth_env_vars

if python_version && !pre_installed_python?(python_version)
run_poetry_command("pyenv install -s #{python_version}")
run_poetry_command("pyenv exec pip install --upgrade pip")
run_poetry_command(
"pyenv exec pip install -r " \
"#{NativeHelpers.python_requirements_path}"
)
end
Helpers.install_required_python(python_version)

# use system git instead of the pure Python dulwich
unless python_version&.start_with?("3.6")
Expand All @@ -123,7 +115,6 @@ def fetch_latest_resolvable_version_string(requirement:)
end
end
end
# rubocop:enable Metrics/PerceivedComplexity

def fetch_version_from_parsed_lockfile(updated_lockfile)
version =
Expand Down Expand Up @@ -346,7 +337,7 @@ def run_poetry_command(command)
stdout, process = Open3.capture2e(command)
time_taken = Time.now - start

# Raise an error with the output from the shell session if Pipenv
# Raise an error with the output from the shell session if poetry
# returns a non-zero status
return if process.success?

Expand Down