Skip to content

Commit

Permalink
python: Handle explicit PyPI source in pyproject.toml
Browse files Browse the repository at this point in the history
Fixes #7431

When a github user has poetry >= 1.5.0, they will be nagged by a warning
to run `poetry source add pypi`, which will add the following section to
the users pyproject.toml:

    [[tool.poetry.source]]
    name = "PyPI"
    priority = "primary"

This causes the problem outlined in #7431, that the index_finder will
fail due to this section missing a `url`.

This commit works around this issue by explicitly adding a url for the
case where the source "name" is equal to "PyPI".
  • Loading branch information
torarvid authored and jurre committed Jul 3, 2023
1 parent 27ffaa7 commit 2c7f3a2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/lib/dependabot/python/update_checker/index_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def pyproject_index_urls
sources.each do |source|
if source["default"]
urls[:main] = source["url"]
elsif source["name"] == "PyPI"
urls[:main] = "https://pypi.org/pypi/"
else
urls[:extra] << source["url"]
end
Expand Down
13 changes: 13 additions & 0 deletions python/spec/dependabot/python/update_checker/index_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@
end
end

context "set pypi explicitly in a pyproject.toml" do
let(:pyproject_fixture_name) { "pypi_explicit.toml" }
let(:dependency_files) { [pyproject] }

it { is_expected.to eq(["https://pypi.org/pypi/"]) }

context "that is unparseable" do
let(:pyproject_fixture_name) { "unparseable.toml" }

it { is_expected.to eq(["https://pypi.org/simple/"]) }
end
end

context "set in credentials" do
let(:credentials) do
[{
Expand Down
16 changes: 16 additions & 0 deletions python/spec/fixtures/pyproject_files/pypi_explicit.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.poetry]
name = "PythonProjects"
version = "2.0.0"
homepage = "https://github.com/roghu/py3_projects"
license = "MIT"
readme = "README.md"
authors = ["Dependabot <support@dependabot.com>"]
description = "Various small python projects."

[tool.poetry.dependencies]
python = "^3.7"
requests = "2.18.0"

[[tool.poetry.source]]
name = "PyPI"
priority = "primary"

0 comments on commit 2c7f3a2

Please sign in to comment.