Skip to content

feat(source/show): notify when PyPI is implicit #9974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/poetry/console/commands/source/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,25 @@ class SourceShowCommand(Command):
),
]

def notify_implicit_pypi(self) -> None:
if not self.poetry.pool.has_repository("pypi"):
return

self.line(
"<c1><b>PyPI</> is implicitly enabled as a <b>primary</> source. "
"If you wish to disable it, or alter its priority please refer to "
"<b>https://python-poetry.org/docs/repositories/#package-sources</>.</>"
)
self.line("")

def handle(self) -> int:
sources = self.poetry.get_sources()
names = self.argument("source")
lower_names = [name.lower() for name in names]

if not sources:
self.line("No sources configured for this project.")
self.line("No sources configured for this project.\n")
self.notify_implicit_pypi()
return 0

if names and not any(s.name.lower() in lower_names for s in sources):
Expand All @@ -42,10 +54,15 @@ def handle(self) -> int:
)
return 1

is_pypi_implicit = True

for source in sources:
if names and source.name.lower() not in lower_names:
continue

if source.name.lower() == "pypi":
is_pypi_implicit = False

table = self.table(style="compact")
rows: Rows = [["<info>name</>", f" : <c1>{source.name}</>"]]
if source.url:
Expand All @@ -55,4 +72,7 @@ def handle(self) -> int:
table.render()
self.line("")

if not names and is_pypi_implicit:
self.notify_implicit_pypi()

return 0
16 changes: 16 additions & 0 deletions tests/console/commands/source/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pytest

from poetry.repositories.pypi_repository import PyPiRepository


if TYPE_CHECKING:
from cleo.testers.command_tester import CommandTester
Expand Down Expand Up @@ -178,6 +180,20 @@ def test_source_show_no_sources(tester_no_sources: CommandTester) -> None:
assert tester_no_sources.status_code == 0


def test_source_show_no_sources_implicit_pypi(
tester_no_sources: CommandTester, poetry_without_source: Poetry
) -> None:
poetry_without_source.pool.add_repository(PyPiRepository())
tester_no_sources.execute("")

output = tester_no_sources.io.fetch_output().strip()

assert "No sources configured for this project." in output
assert "PyPI is implicitly enabled as a primary source." in output

assert tester_no_sources.status_code == 0


def test_source_show_error(tester: CommandTester) -> None:
tester.execute("error")
assert tester.io.fetch_error().strip() == "No source found with name(s): error"
Expand Down
Loading