Skip to content

Commit

Permalink
Fix multiple Python requirements separated by whitespace
Browse files Browse the repository at this point in the history
Standard Python does not support this, but Poetry does, so when they
appear on Poetry dependency files, they make dependabot crash.
  • Loading branch information
deivid-rodriguez authored and jeffwidman committed Sep 17, 2022
1 parent 37c897a commit aaf292f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/lib/dependabot/python/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def initialize(*requirements)
requirements = requirements.flatten.flat_map do |req_string|
next if req_string.nil?

# Standard python doesn't support whitespace in requirements, but Poetry does.
req_string = req_string.gsub(/(\d +)([<=>])/, '\1,\2')

req_string.split(",").map(&:strip).map do |r|
convert_python_constraint_to_ruby_constraint(r)
end
Expand Down
10 changes: 10 additions & 0 deletions python/spec/dependabot/python/requirement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
let(:requirement_string) { ">=2.0,<2.1" }
it { is_expected.to eq(Gem::Requirement.new(">=2.0", "<2.1")) }
end

context "separated by whitespace (supported by Poetry)" do
let(:requirement_string) { ">=2.0 <2.1" }
it { is_expected.to eq(Gem::Requirement.new(">=2.0", "<2.1")) }
end
end

context "with multiple operators after the first" do
Expand All @@ -125,6 +130,11 @@
let(:requirement_string) { ">=2.0,<2.1,<2.2" }
it { is_expected.to eq(Gem::Requirement.new(">=2.0", "<2.1", "<2.2")) }
end

context "separated by whitespace (supported by Poetry)" do
let(:requirement_string) { ">=2.0 <2.1 <2.2" }
it { is_expected.to eq(Gem::Requirement.new(">=2.0", "<2.1", "<2.2")) }
end
end

context "with an array" do
Expand Down

0 comments on commit aaf292f

Please sign in to comment.