-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8312 from dependabot/deivid-rodriguez/pipenv-upgrade
Replace `pipenv lock` with `pipenv upgrade`
- Loading branch information
Showing
12 changed files
with
171 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "dependabot/shared_helpers" | ||
require "dependabot/python/file_parser" | ||
require "json" | ||
|
||
module Dependabot | ||
module Python | ||
class PipenvRunner | ||
def initialize(dependency:, lockfile:, language_version_manager:) | ||
@dependency = dependency | ||
@lockfile = lockfile | ||
@language_version_manager = language_version_manager | ||
end | ||
|
||
def run_upgrade(constraint) | ||
command = "pyenv exec pipenv upgrade #{dependency_name}#{constraint}" | ||
command << " --dev" if lockfile_section == "develop" | ||
|
||
run(command) | ||
end | ||
|
||
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 | ||
|
||
def run(command) | ||
run_command( | ||
"pyenv local #{language_version_manager.python_major_minor}", | ||
fingerprint: "pyenv local <python_major_minor>" | ||
) | ||
|
||
run_command(command) | ||
end | ||
|
||
private | ||
|
||
attr_reader :dependency, :lockfile, :language_version_manager | ||
|
||
def fetch_version_from_parsed_lockfile(updated_lockfile) | ||
deps = updated_lockfile[lockfile_section] || {} | ||
|
||
deps.dig(dependency_name, "version") | ||
&.gsub(/^==/, "") | ||
end | ||
|
||
def run_command(command, fingerprint: nil) | ||
SharedHelpers.run_shell_command(command, env: pipenv_env_variables, fingerprint: fingerprint) | ||
end | ||
|
||
def lockfile_section | ||
if dependency.requirements.any? | ||
dependency.requirements.first[:groups].first | ||
else | ||
Python::FileParser::DEPENDENCY_GROUP_KEYS.each do |keys| | ||
section = keys.fetch(:lockfile) | ||
return section if JSON.parse(lockfile.content)[section].keys.any?(dependency_name) | ||
end | ||
end | ||
end | ||
|
||
def dependency_name | ||
dependency.metadata[:original_name] || dependency.name | ||
end | ||
|
||
def pipenv_env_variables | ||
{ | ||
"PIPENV_YES" => "true", # Install new Python ver if needed | ||
"PIPENV_MAX_RETRIES" => "3", # Retry timeouts | ||
"PIPENV_NOSPIN" => "1", # Don't pollute logs with spinner | ||
"PIPENV_TIMEOUT" => "600", # Set install timeout to 10 minutes | ||
"PIP_DEFAULT_TIMEOUT" => "60" # Set pip timeout to 1 minute | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.