From 6934b14107b9cd79eb173fb1b86031c7f8d0f9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 17 Oct 2023 17:16:43 +0200 Subject: [PATCH] Avoid trying to parse poetry.lock if pyproject.toml is invalid for Poetry --- .../file_parser/pyproject_files_parser.rb | 2 +- .../file_parser/pyproject_files_parser_spec.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/python/lib/dependabot/python/file_parser/pyproject_files_parser.rb b/python/lib/dependabot/python/file_parser/pyproject_files_parser.rb index db0c77f3ea8..6ce7ef57e8f 100644 --- a/python/lib/dependabot/python/file_parser/pyproject_files_parser.rb +++ b/python/lib/dependabot/python/file_parser/pyproject_files_parser.rb @@ -27,7 +27,7 @@ def dependency_set dependency_set = Dependabot::FileParsers::Base::DependencySet.new dependency_set += pyproject_dependencies if using_poetry? || using_pep621? - dependency_set += lockfile_dependencies if lockfile + dependency_set += lockfile_dependencies if using_poetry? && lockfile dependency_set end diff --git a/python/spec/dependabot/python/file_parser/pyproject_files_parser_spec.rb b/python/spec/dependabot/python/file_parser/pyproject_files_parser_spec.rb index 0b1caa68ff2..f3f85f7d8b6 100644 --- a/python/spec/dependabot/python/file_parser/pyproject_files_parser_spec.rb +++ b/python/spec/dependabot/python/file_parser/pyproject_files_parser_spec.rb @@ -311,6 +311,23 @@ subject(:dependencies) { parser.dependency_set.dependencies } its(:length) { is_expected.to eq(0) } + + context "and a leftover poetry.lock" do + let(:poetry_lock) do + Dependabot::DependencyFile.new( + name: "poetry.lock", + content: poetry_lock_body + ) + end + let(:poetry_lock_body) do + fixture("poetry_locks", poetry_lock_fixture_name) + end + let(:poetry_lock_fixture_name) { "poetry.lock" } + + let(:files) { [pyproject, pdm_lock, poetry_lock] } + + its(:length) { is_expected.to eq(0) } + end end context "with optional dependencies" do