Skip to content

Commit

Permalink
Merge pull request #10844 from dependabot/amazimbe/fix-python-version…
Browse files Browse the repository at this point in the history
…-ignore-range

Add semver ignore-condition range code into python version
  • Loading branch information
randhircs authored Oct 25, 2024
2 parents 2fdc6c1 + 478aa9a commit dbf5b05
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
4 changes: 2 additions & 2 deletions python/lib/dependabot/python/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ def updated_version_req_lower_bound
.reject { |req_string| req_string.start_with?("<") }
.select { |req_string| req_string.match?(VERSION_REGEX) }
.map { |req_string| req_string.match(VERSION_REGEX) }
.select { |version| Gem::Version.correct?(version) }
.max_by { |version| Gem::Version.new(version) }
.select { |version| Python::Version.correct?(version) }
.max_by { |version| Python::Version.new(version) }

">=#{version_for_requirement || 0}"
end
Expand Down
32 changes: 32 additions & 0 deletions python/lib/dependabot/python/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,38 @@ def lowest_prerelease_suffix
"dev0"
end

sig { override.returns(T::Array[String]) }
def ignored_patch_versions
parts = release_segment # e.g [1,2,3] if version is 1.2.3-alpha3
version_parts = parts.fill(0, parts.length...2)
upper_parts = version_parts.first(1) + [version_parts[1].to_i + 1] + [lowest_prerelease_suffix]
lower_bound = "> #{self}"
upper_bound = "< #{upper_parts.join('.')}"

["#{lower_bound}, #{upper_bound}"]
end

sig { override.returns(T::Array[String]) }
def ignored_minor_versions
parts = release_segment # e.g [1,2,3] if version is 1.2.3-alpha3
version_parts = parts.fill(0, parts.length...2)
lower_parts = version_parts.first(1) + [version_parts[1].to_i + 1] + [lowest_prerelease_suffix]
upper_parts = version_parts.first(0) + [version_parts[0].to_i + 1] + [lowest_prerelease_suffix]
lower_bound = ">= #{lower_parts.join('.')}"
upper_bound = "< #{upper_parts.join('.')}"

["#{lower_bound}, #{upper_bound}"]
end

sig { override.returns(T::Array[String]) }
def ignored_major_versions
version_parts = release_segment # e.g [1,2,3] if version is 1.2.3-alpha3
lower_parts = [version_parts[0].to_i + 1] + [lowest_prerelease_suffix] # earliest next major version prerelease
lower_bound = ">= #{lower_parts.join('.')}"

[lower_bound]
end

private

sig { params(other: Dependabot::Python::Version).returns(Integer) }
Expand Down
28 changes: 24 additions & 4 deletions python/spec/dependabot/python/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@
describe ".new" do
subject(:version) { described_class.new(version_string) }

before do
Dependabot::Experiments.register(:python_new_version, true)
end

context "with an empty string" do
let(:version_string) { "" }
let(:error_msg) { "Malformed version string - string is empty" }
Expand Down Expand Up @@ -342,6 +338,30 @@
it { is_expected.to eq "dev0" }
end

describe "#ignored_major_versions" do
subject(:ignored_versions) { version.ignored_major_versions }

let(:version_string) { "1.2.3-alpha.1" }

it { is_expected.to eq([">= 2.dev0"]) }
end

describe "#ignored_minor_versions" do
subject(:ignored_versions) { version.ignored_minor_versions }

let(:version_string) { "1.2.3-alpha.1" }

it { is_expected.to eq([">= 1.3.dev0, < 2.dev0"]) }
end

describe "#ignored_patch_versions" do
subject(:ignored_versions) { version.ignored_patch_versions }

let(:version_string) { "1.2.3-alpha.1" }

it { is_expected.to eq(["> #{version_string}, < 1.3.dev0"]) }
end

describe "compatibility with Gem::Requirement" do
subject { requirement.satisfied_by?(version) }

Expand Down

0 comments on commit dbf5b05

Please sign in to comment.