Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Pipenv to 2018.10.9 #696

Merged
merged 5 commits into from
Oct 9, 2018
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
2 changes: 1 addition & 1 deletion helpers/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pip==18.1
pip-tools==3.1.0
hashin==0.13.4
pipenv==2018.7.1
pipenv==2018.10.9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix many Python bugs

Suddenly, it introduces more bugs than you can expect 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, yeah, that's definitely a danger...! 😉

pipfile==0.0.2
poetry==0.11.5
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "toml-rb"
require "toml_converter"

require "python_requirement_parser"
require "dependabot/file_updaters/python/pip"
Expand Down Expand Up @@ -172,7 +173,9 @@ def freeze_dependencies_being_updated(pipfile_content)
end
end

TomlRB.dump(pipfile_object)
TomlConverter.convert_pipenv_outline_tables(
TomlRB.dump(pipfile_object)
)
end

def add_private_sources(pipfile_content)
Expand All @@ -192,7 +195,6 @@ def updated_generated_files

run_pipenv_command(
"PIPENV_YES=true PIPENV_MAX_RETRIES=2 "\
"pyenv exec pipenv run pip install pip==18.0 && "\
"pyenv exec pipenv lock"
)

Expand Down Expand Up @@ -231,12 +233,10 @@ def post_process_lockfile(updated_lockfile_content)
def generate_updated_requirements_files
run_pipenv_command(
"PIPENV_YES=true PIPENV_MAX_RETRIES=2 "\
"pyenv exec pipenv run pip install pip==18.0 && "\
"pyenv exec pipenv lock -r > req.txt"
)
run_pipenv_command(
"PIPENV_YES=true PIPENV_MAX_RETRIES=2 "\
"pyenv exec pipenv run pip install pip==18.0 && "\
"pyenv exec pipenv lock -r -d > dev-req.txt"
)
end
Expand Down
9 changes: 7 additions & 2 deletions lib/dependabot/file_updaters/python/pip/pipfile_preparer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "toml-rb"
require "toml_converter"

require "dependabot/file_parsers/python/pip"
require "dependabot/file_updaters/python/pip"
Expand All @@ -21,7 +22,9 @@ def replace_sources(credentials)
pipfile_sources.reject { |h| h["url"].include?("${") } +
config_variable_sources(credentials)

TomlRB.dump(pipfile_object)
TomlConverter.convert_pipenv_outline_tables(
TomlRB.dump(pipfile_object)
)
end

def freeze_top_level_dependencies_except(dependencies, lockfile)
Expand Down Expand Up @@ -53,7 +56,9 @@ def freeze_top_level_dependencies_except(dependencies, lockfile)
end
end

TomlRB.dump(pipfile_object)
TomlConverter.convert_pipenv_outline_tables(
TomlRB.dump(pipfile_object)
)
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "excon"
require "toml-rb"
require "toml_converter"

require "dependabot/file_parsers/python/pip"
require "dependabot/file_updaters/python/pip/pipfile_preparer"
Expand Down Expand Up @@ -76,7 +77,6 @@ def fetch_latest_resolvable_version
# to resolve the dependencies. That means this is slow.
run_pipenv_command(
"PIPENV_YES=true PIPENV_MAX_RETRIES=2 "\
"pyenv exec pipenv run pip install pip==18.0 && "\
"pyenv exec pipenv lock"
)

Expand Down Expand Up @@ -129,7 +129,7 @@ def handle_pipenv_errors(error)
end

if error.message.include?("Could not find a version") ||
error.message.include?("Warning: Python >")
error.message.include?("Not a valid python version")
check_original_requirements_resolvable
end

Expand Down Expand Up @@ -171,8 +171,7 @@ def check_original_requirements_resolvable
IO.popen("git init", err: %i(child out)) if setup_files.any?

run_pipenv_command("PIPENV_YES=true PIPENV_MAX_RETRIES=2 "\
"pyenv exec pipenv run pip install "\
"pip==18.0 && pyenv exec pipenv lock")
"pyenv exec pipenv lock")

true
rescue SharedHelpers::HelperSubprocessFailed => error
Expand All @@ -184,7 +183,7 @@ def check_original_requirements_resolvable
raise DependencyFileNotResolvable, msg
end

if error.message.include?("Warning: Python >")
if error.message.include?("Not a valid python version")
msg = "Pipenv does not support specifying Python ranges "\
"(see https://github.com/pypa/pipenv/issues/1050 for more "\
"details)."
Expand Down Expand Up @@ -285,7 +284,9 @@ def unlock_target_dependency(pipfile_content)
end
end

TomlRB.dump(pipfile_object)
TomlConverter.convert_pipenv_outline_tables(
TomlRB.dump(pipfile_object)
)
end

def add_private_sources(pipfile_content)
Expand Down
46 changes: 46 additions & 0 deletions lib/toml_converter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

# This module provides a (hopefully temporary) way to convert outline tables
# generated from dumping TomlRB into inline tables which are understood by
# Pipenv.
#
# This is required because Pipenv doesn't currently support outline tables.
# We have an issue open for that: https://github.com/pypa/pipenv/issues/2960
module TomlConverter
PIPENV_OUTLINE_TABLES_REGEX = /
\[(?<type>(dev-)?packages)\.(?<name>[^\]]+)\]
(?<content>.*?)(?=^\[|\z)
/mx

def self.convert_pipenv_outline_tables(content)
# First, find any outline tables that appear in the Pipfile
matches = []
content.scan(PIPENV_OUTLINE_TABLES_REGEX) { matches << Regexp.last_match }

# Next, remove all of them. We'll add them back in as inline tables next
updated_content = content.gsub(PIPENV_OUTLINE_TABLES_REGEX, "")

# Iterate through each of the outline tables we found, adding it back to the
# Pipfile as an inline table
matches.each do |match|
# If the heading for this section doesn't yet exist in the Pipfile, add it
unless updated_content.include?(match[:type])
updated_content += "\n\n[#{match[:type]}]\n"
end

# Build the inline table contents from the contents of the outline table
inline_content = match[:content].strip.gsub(/\s*\n+/, ", ")
content_to_insert = "#{match[:name]} = {#{inline_content}}"

# Insert the created inline table just below the heading for the correct
# section
updated_content.sub!(
"[#{match[:type]}]\n",
"[#{match[:type]}]\n#{content_to_insert}\n"
)
end

# Return the updated content
updated_content
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
}]
end

it { is_expected.to be >= Gem::Version.new("0.16.12") }
# This is broken on the latest Pipenv, and instead return `nil`
pending { is_expected.to be >= Gem::Version.new("0.16.12") }
end

context "with a subdependency" do
Expand Down
138 changes: 138 additions & 0 deletions spec/toml_converter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# frozen_string_literal: true

require "spec_helper"
require "toml_converter"

describe TomlConverter do
describe ".convert_pipenv_outline_tables" do
subject(:updated_content) do
described_class.convert_pipenv_outline_tables(content)
end

context "without any outline tables" do
let(:content) { fixture("python", "pipfiles", "exact_version") }
it { is_expected.to eq(content) }
end

context "without an outline table in the middle of the file" do
let(:content) do
<<~HEREDOC
[[source]]
name = "pypi"
url = "https://pypi.python.org/simple/"
verify_ssl = true

[packages]
flask = "==1.0.1"

[packages.raven]
extras = ["flask"]
version = ">= 5.27.1, <= 7.0.0"

[requires]
python_version = "2.7"
HEREDOC
end

it "converts the outline table to an inline table" do
expect(updated_content).to eq(
<<~HEREDOC
[[source]]
name = "pypi"
url = "https://pypi.python.org/simple/"
verify_ssl = true

[packages]
raven = {extras = ["flask"], version = ">= 5.27.1, <= 7.0.0"}
flask = "==1.0.1"

[requires]
python_version = "2.7"
HEREDOC
)
end
end

context "without an outline table at the end of the file" do
let(:content) do
<<~HEREDOC
[[source]]
name = "pypi"
url = "https://pypi.python.org/simple/"
verify_ssl = true

[packages]
flask = "==1.0.1"

[requires]
python_version = "2.7"

[packages.raven]
extras = ["flask"]
version = ">= 5.27.1, <= 7.0.0"
HEREDOC
end

it "converts the outline table to an inline table" do
expect(updated_content).to eq(
<<~HEREDOC
[[source]]
name = "pypi"
url = "https://pypi.python.org/simple/"
verify_ssl = true

[packages]
raven = {extras = ["flask"], version = ">= 5.27.1, <= 7.0.0"}
flask = "==1.0.1"

[requires]
python_version = "2.7"

HEREDOC
)
end
end

context "without an outline table for a dev-package" do
let(:content) do
<<~HEREDOC
[[source]]
name = "pypi"
url = "https://pypi.python.org/simple/"
verify_ssl = true

[packages]
flask = "==1.0.1"

[dev-packages.raven]
extras = ["flask"]
version = ">= 5.27.1, <= 7.0.0"

[requires]
python_version = "2.7"
HEREDOC
end

it "converts the outline table to an inline table" do
expect(updated_content).to eq(
<<~HEREDOC
[[source]]
name = "pypi"
url = "https://pypi.python.org/simple/"
verify_ssl = true

[packages]
flask = "==1.0.1"

[requires]
python_version = "2.7"


[dev-packages]
raven = {extras = ["flask"], version = ">= 5.27.1, <= 7.0.0"}
HEREDOC
)
end
end
end
end