Skip to content

Commit e10de6e

Browse files
julia-thornCopilotmarkhallen
authored
(fix) Handle Poetry group metadata without dependencies table (#14689)
* fix(python): handle Poetry groups without dependencies table * Fix lint issue * Fix CoPilot suggestions * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix flaky smoke test * Fix security alert * Revert "Fix security alert" This reverts commit 133a269. * Revert "Fix flaky smoke test" This reverts commit 0ba52f1. * trigger ci * trigger ci * trigger ci * trigger ci --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Mark Allen <markhallen@gmail.com>
1 parent 28ffa28 commit e10de6e

6 files changed

Lines changed: 67 additions & 3 deletions

File tree

python/lib/dependabot/python/file_parser/pyproject_files_parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ def pep621_pep735_dependencies
113113
sig do
114114
params(
115115
type: String,
116-
deps_hash: T::Hash[String,
117-
T.untyped]
116+
deps_hash: T.nilable(T::Hash[String, T.untyped])
118117
).returns(Dependabot::FileParsers::Base::DependencySet)
119118
end
120119
def parse_poetry_dependency_group(type, deps_hash)
121120
dependencies = Dependabot::FileParsers::Base::DependencySet.new
121+
return dependencies if deps_hash.nil?
122122

123123
deps_hash.each do |name, req|
124124
next if normalise(name) == "python"

python/lib/dependabot/python/update_checker/poetry_version_resolver.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ def set_target_dependency_req(pyproject_content, updated_requirement)
341341
TomlRB.dump(pyproject_object)
342342
end
343343

344-
sig { params(toml_node: T::Hash[String, T.untyped], requirement: String).void }
344+
sig { params(toml_node: T.nilable(T::Hash[String, T.untyped]), requirement: String).void }
345345
def update_dependency_requirement(toml_node, requirement)
346+
return unless toml_node
347+
346348
names = toml_node.keys
347349
pkg_name = names.find { |nm| normalise(nm) == dependency.name }
348350
return unless pkg_name

python/spec/dependabot/python/file_parser/pyproject_files_parser_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,21 @@
329329
end
330330
end
331331

332+
context "with optional poetry group metadata and pep735 groups" do
333+
subject(:dependency_names) { dependencies.map(&:name) }
334+
335+
let(:pyproject_fixture_name) { "poetry_group_optional_without_dependencies.toml" }
336+
337+
it "parses without error when tool.poetry.group has no dependencies table" do
338+
expect { parser.dependency_set }.not_to raise_error
339+
end
340+
341+
it "includes dependencies declared in dependency-groups" do
342+
expect(dependency_names).to include("requests")
343+
expect(dependency_names).to include("onnxruntime-gpu")
344+
end
345+
end
346+
332347
context "with a group that has no dependencies key" do
333348
subject(:dependency_names) { dependencies.map(&:name) }
334349

python/spec/dependabot/python/update_checker/poetry_version_resolver_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@
9898
it { is_expected.to eq(Gem::Version.new("2.18.4")) }
9999
end
100100

101+
context "with a metadata-only poetry group" do
102+
let(:pyproject_fixture_name) { "poetry_metadata_only_group.toml" }
103+
104+
it "resolves the latest version when a poetry group has no dependencies table" do
105+
expect(latest_resolvable_version).to eq(Gem::Version.new("2.18.4"))
106+
end
107+
end
108+
101109
context "with a non-package mode project" do
102110
let(:pyproject_fixture_name) { "poetry_non_package_mode_simple.toml" }
103111
let(:lockfile_fixture_name) { "version_not_specified.lock" }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[tool.poetry]
2+
name = "poetry-group-optional-without-dependencies"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Dependabot <support@dependabot.com>"]
6+
7+
[tool.poetry.dependencies]
8+
python = ">=3.11"
9+
10+
[dependency-groups]
11+
dev = [
12+
"requests==2.18.0",
13+
]
14+
gpu = [
15+
"onnxruntime-gpu==1.23.2",
16+
]
17+
18+
[tool.poetry.group.gpu]
19+
optional = true
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[tool.poetry]
2+
name = "poetry-metadata-only-group"
3+
version = "2.0.0"
4+
homepage = "https://github.com/roghu/py3_projects"
5+
license = "MIT"
6+
readme = "README.md"
7+
authors = ["Dependabot <support@dependabot.com>"]
8+
description = "Various small python projects."
9+
10+
[tool.poetry.dependencies]
11+
python = "3.11.1"
12+
requests = "2.18.0"
13+
14+
[dependency-groups]
15+
gpu = [
16+
"onnxruntime-gpu==1.23.2",
17+
]
18+
19+
[tool.poetry.group.gpu]
20+
optional = true

0 commit comments

Comments
 (0)