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

Selecting the correct requirement based on the given marker condition. #11204

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
35 changes: 32 additions & 3 deletions python/lib/dependabot/python/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,39 @@ def group_from_filename(filename)

def blocking_marker?(dep)
return false if dep["markers"] == "None"
return true if dep["markers"].include?("<")
return false if dep["markers"].include?(">")

dep["requirement"]&.include?("<")
marker = dep["markers"]
version = python_raw_version

if marker.include?("python_version")
!marker_satisfied?(marker, version)
else
return true if dep["markers"].include?("<")
return false if dep["markers"].include?(">")

dep["requirement"]&.include?("<")
end
end

def marker_satisfied?(marker, python_version)
return true if marker == "None"
thavaahariharangit marked this conversation as resolved.
Show resolved Hide resolved

operator, version = marker.match(/([<>=!]=?)\s*"?([\d.]+)"?/).captures

case operator
when "<"
Gem::Version.new(python_version) < Gem::Version.new(version)
thavaahariharangit marked this conversation as resolved.
Show resolved Hide resolved
when "<="
Gem::Version.new(python_version) <= Gem::Version.new(version)
when ">"
Gem::Version.new(python_version) > Gem::Version.new(version)
when ">="
Gem::Version.new(python_version) >= Gem::Version.new(version)
when "=="
Gem::Version.new(python_version) == Gem::Version.new(version)
else
false
end
end

def setup_file_dependencies
Expand Down
8 changes: 6 additions & 2 deletions python/spec/dependabot/python/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
end

context "with markers" do
before do
allow(parser).to receive(:python_raw_version).and_return("2.6")
end

context "when including a < in the marker" do
let(:requirements_fixture_name) { "markers.txt" }

Expand All @@ -116,10 +120,10 @@

expect(dependency).to be_a(Dependabot::Dependency)
expect(dependency.name).to eq("distro")
expect(dependency.version).to eq("1.3.0")
expect(dependency.version).to eq("1.0.4")
expect(dependency.requirements).to eq(
[{
requirement: "==1.3.0",
requirement: "==1.0.4",
file: "requirements.txt",
groups: ["dependencies"],
source: nil
Expand Down
Loading