diff --git a/python/lib/dependabot/python/update_checker.rb b/python/lib/dependabot/python/update_checker.rb index 0d1f1b43922..0113a8b7153 100644 --- a/python/lib/dependabot/python/update_checker.rb +++ b/python/lib/dependabot/python/update_checker.rb @@ -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 diff --git a/python/lib/dependabot/python/version.rb b/python/lib/dependabot/python/version.rb index 3eaaba4190a..1dbb88b1544 100644 --- a/python/lib/dependabot/python/version.rb +++ b/python/lib/dependabot/python/version.rb @@ -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) } diff --git a/python/spec/dependabot/python/version_spec.rb b/python/spec/dependabot/python/version_spec.rb index a05d6ec5762..759816a760e 100644 --- a/python/spec/dependabot/python/version_spec.rb +++ b/python/spec/dependabot/python/version_spec.rb @@ -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" } @@ -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) }