forked from dependabot/dependabot-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enables python ecosystem metric collection (dependabot#10986)
Enables python ecosystem metric collection (dependabot#10986)
- Loading branch information
1 parent
50b93dc
commit 2f0fb29
Showing
5 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# typed: strong | ||
# frozen_string_literal: true | ||
|
||
require "sorbet-runtime" | ||
require "dependabot/python/version" | ||
require "dependabot/ecosystem" | ||
|
||
module Dependabot | ||
module Python | ||
LANGUAGE = "python" | ||
|
||
class Language < Dependabot::Ecosystem::VersionManager | ||
extend T::Sig | ||
|
||
sig { params(raw_version: String, requirement: T.nilable(Requirement)).void } | ||
def initialize(raw_version, requirement = nil) | ||
super(LANGUAGE, Version.new(raw_version), [], [], requirement) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# typed: strong | ||
# frozen_string_literal: true | ||
|
||
require "sorbet-runtime" | ||
require "dependabot/python/version" | ||
require "dependabot/ecosystem" | ||
require "dependabot/python/requirement" | ||
|
||
module Dependabot | ||
module Python | ||
ECOSYSTEM = "Python" | ||
|
||
# Keep versions in ascending order | ||
SUPPORTED_PYTHON_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version]) | ||
|
||
DEPRECATED_PYTHON_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version]) | ||
|
||
class PipPackageManager < Dependabot::Ecosystem::VersionManager | ||
extend T::Sig | ||
|
||
NAME = "pip" | ||
|
||
SUPPORTED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version]) | ||
|
||
DEPRECATED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version]) | ||
|
||
sig do | ||
params( | ||
raw_version: String, | ||
requirement: T.nilable(Requirement) | ||
).void | ||
end | ||
def initialize(raw_version, requirement = nil) | ||
super( | ||
NAME, | ||
Version.new(raw_version), | ||
SUPPORTED_VERSIONS, | ||
DEPRECATED_VERSIONS, | ||
requirement, | ||
) | ||
end | ||
|
||
sig { override.returns(T::Boolean) } | ||
def deprecated? | ||
false | ||
end | ||
|
||
sig { override.returns(T::Boolean) } | ||
def unsupported? | ||
false | ||
end | ||
end | ||
|
||
class PeotryPackageManager < Dependabot::Ecosystem::VersionManager | ||
extend T::Sig | ||
|
||
NAME = "poetry" | ||
|
||
SUPPORTED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version]) | ||
|
||
DEPRECATED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version]) | ||
|
||
sig do | ||
params( | ||
raw_version: String, | ||
requirement: T.nilable(Requirement) | ||
).void | ||
end | ||
def initialize(raw_version, requirement = nil) | ||
super( | ||
NAME, | ||
Version.new(raw_version), | ||
DEPRECATED_PYTHON_VERSIONS, | ||
SUPPORTED_PYTHON_VERSIONS, | ||
requirement, | ||
) | ||
end | ||
|
||
sig { override.returns(T::Boolean) } | ||
def deprecated? | ||
false | ||
end | ||
|
||
sig { override.returns(T::Boolean) } | ||
def unsupported? | ||
false | ||
end | ||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
python/spec/dependabot/python/peotry_package_manager_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# typed: false | ||
# frozen_string_literal: true | ||
|
||
require "dependabot/python/package_manager" | ||
require "dependabot/ecosystem" | ||
require "spec_helper" | ||
|
||
RSpec.describe Dependabot::Python::PeotryPackageManager do | ||
let(:package_manager) { described_class.new("1.8.3") } | ||
|
||
describe "#initialize" do | ||
context "when version is a String" do | ||
it "sets the version correctly" do | ||
expect(package_manager.version).to eq("1.8.3") | ||
end | ||
|
||
it "sets the name correctly" do | ||
expect(package_manager.name).to eq("poetry") | ||
end | ||
end | ||
|
||
context "when poetry version is extracted from pyenv is well formed" do | ||
# If this test starts failing, you need to adjust the "detect_poetry_version" function | ||
# to return a valid version in format x.x, x.x.x etc. examples: 3.12.5, 3.12 | ||
version = Dependabot::SharedHelpers.run_shell_command("pyenv exec poetry --version") | ||
.split("version ").last&.split(")")&.first | ||
|
||
it "does not raise error" do | ||
expect(version.match(/^\d+(?:\.\d+)*$/)).to be_truthy | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# typed: false | ||
# frozen_string_literal: true | ||
|
||
require "dependabot/python/package_manager" | ||
require "dependabot/ecosystem" | ||
require "spec_helper" | ||
|
||
RSpec.describe Dependabot::Python::PipPackageManager do | ||
let(:package_manager) { described_class.new("24.0") } | ||
|
||
describe "#initialize" do | ||
context "when version is a String" do | ||
it "sets the version correctly" do | ||
expect(package_manager.version).to eq("24.0") | ||
end | ||
|
||
it "sets the name correctly" do | ||
expect(package_manager.name).to eq("pip") | ||
end | ||
end | ||
|
||
context "when pip version is extracted from pyenv is well formed" do | ||
# If this test starts failing, you need to adjust the "detect_pip_version" function | ||
# to return a valid version in format x.x, x.x.x etc. examples: 3.12.5, 3.12 | ||
version = Dependabot::SharedHelpers.run_shell_command("pyenv exec pip -V") | ||
.split("from").first&.split("pip")&.last&.strip.to_s | ||
|
||
it "does not raise error" do | ||
expect(version.match(/^\d+(?:\.\d+)*$/)).to be_truthy | ||
end | ||
end | ||
end | ||
end |