Skip to content

Commit

Permalink
Add support for python 3.8 deprecation warning and unsupported error (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
amazimbe authored Dec 24, 2024
1 parent ec380a2 commit c0b00ef
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 1 deletion.
35 changes: 34 additions & 1 deletion python/lib/dependabot/python/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,43 @@ module Python

class Language < Dependabot::Ecosystem::VersionManager
extend T::Sig
# These versions should match the versions specified at the top of `python/Dockerfile`
PYTHON_3_13 = "3.13"
PYTHON_3_12 = "3.12"
PYTHON_3_11 = "3.11"
PYTHON_3_10 = "3.10"
PYTHON_3_9 = "3.9"
PYTHON_3_8 = "3.8"

DEPRECATED_VERSIONS = T.let([Version.new(PYTHON_3_8)].freeze, T::Array[Dependabot::Version])

# Keep versions in ascending order
SUPPORTED_VERSIONS = T.let([
Version.new(PYTHON_3_9),
Version.new(PYTHON_3_10),
Version.new(PYTHON_3_11),
Version.new(PYTHON_3_12),
Version.new(PYTHON_3_13)
].freeze, T::Array[Dependabot::Version])

sig { params(raw_version: String, requirement: T.nilable(Requirement)).void }
def initialize(raw_version, requirement = nil)
super(LANGUAGE, Version.new(raw_version), [], [], requirement)
super(LANGUAGE, Version.new(raw_version), DEPRECATED_VERSIONS, SUPPORTED_VERSIONS, requirement)
end

sig { override.returns(T::Boolean) }
def deprecated?
return false if unsupported?
return false unless Dependabot::Experiments.enabled?(:python_3_8_deprecation_warning)

deprecated_versions.include?(version)
end

sig { override.returns(T::Boolean) }
def unsupported?
return false unless Dependabot::Experiments.enabled?(:python_3_8_unsupported_error)

supported_versions.all? { |supported| supported > version }
end
end
end
Expand Down
121 changes: 121 additions & 0 deletions python/spec/dependabot/python/language_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# typed: false
# frozen_string_literal: true

require "dependabot/python/language"
require "dependabot/ecosystem"
require_relative "../../spec_helper"

RSpec.describe Dependabot::Python::Language do
subject(:language) { described_class.new(version) }

describe "#deprecated?" do
let(:version) { "3.8" }

before do
allow(::Dependabot::Experiments).to receive(:enabled?)
.with(:python_3_8_deprecation_warning)
.and_return(deprecation_enabled)
allow(::Dependabot::Experiments).to receive(:enabled?)
.with(:python_3_8_unsupported_error)
.and_return(unsupported_enabled)
end

context "when python_3_8_deprecation_warning is enabled and version is deprecated" do
let(:deprecation_enabled) { true }
let(:unsupported_enabled) { false }

it "returns true" do
expect(language.deprecated?).to be true
end
end

context "when python_3_8_deprecation_warning is enabled but version is not deprecated" do
let(:version) { "3.13" }
let(:deprecation_enabled) { true }
let(:unsupported_enabled) { false }

it "returns false" do
expect(language.deprecated?).to be false
end
end

context "when python_3_8_deprecation_warning is disabled" do
let(:deprecation_enabled) { false }
let(:unsupported_enabled) { false }

it "returns false" do
expect(language.deprecated?).to be false
end
end

context "when version is unsupported" do
let(:deprecation_enabled) { true }
let(:unsupported_enabled) { true }

it "returns false, as unsupported takes precedence" do
expect(language.deprecated?).to be false
end
end
end

describe "#unsupported?" do
let(:version) { "3.8" }

before do
allow(::Dependabot::Experiments).to receive(:enabled?)
.with(:python_3_8_unsupported_error)
.and_return(unsupported_enabled)
end

context "when python_3_8_unsupported_error is enabled and version is unsupported" do
let(:unsupported_enabled) { true }

it "returns true" do
expect(language.unsupported?).to be true
end
end

context "when python_3_8_unsupported_error is enabled but version is supported" do
let(:version) { "3.13" }
let(:unsupported_enabled) { true }

it "returns false" do
expect(language.unsupported?).to be false
end
end

context "when python_3_8_unsupported_error is disabled" do
let(:unsupported_enabled) { false }

it "returns false" do
expect(language.unsupported?).to be false
end
end
end

describe "#raise_if_unsupported!" do
let(:version) { "3.8" }

before do
allow(Dependabot::Experiments).to receive(:enabled?)
.with(:python_3_8_unsupported_error)
.and_return(unsupported_enabled)
end

context "when python_3_8_unsupported_error is enabled and version is unsupported" do
let(:unsupported_enabled) { true }

it "raises a ToolVersionNotSupported error" do
expect { language.raise_if_unsupported! }.to raise_error(Dependabot::ToolVersionNotSupported)
end
end

context "when python_3_8_unsupported_error is disabled" do
let(:unsupported_enabled) { false }

it "does not raise an error" do
expect { language.raise_if_unsupported! }.not_to raise_error
end
end
end
end

0 comments on commit c0b00ef

Please sign in to comment.