Skip to content

Commit 353dc1f

Browse files
committed
feat(source/show): notify when PyPI is implicit
Add a notice when all sources are listed and PyPI is implicitly enabled.
1 parent 0e4f0e7 commit 353dc1f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/poetry/console/commands/source/show.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,25 @@ class SourceShowCommand(Command):
2626
),
2727
]
2828

29+
def notify_implicit_pypi(self) -> None:
30+
if not self.poetry.pool.has_repository("pypi"):
31+
return
32+
33+
self.line(
34+
"<c1><b>PyPI</> is implicitly enabled as a <b>primary</> source. "
35+
"If you wish to disable it, or alter its priority please refer to "
36+
"<b>https://python-poetry.org/docs/repositories/#package-sources</>.</>"
37+
)
38+
self.line("")
39+
2940
def handle(self) -> int:
3041
sources = self.poetry.get_sources()
3142
names = self.argument("source")
3243
lower_names = [name.lower() for name in names]
3344

3445
if not sources:
35-
self.line("No sources configured for this project.")
46+
self.line("No sources configured for this project.\n")
47+
self.notify_implicit_pypi()
3648
return 0
3749

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

57+
is_pypi_implicit = True
58+
4559
for source in sources:
4660
if names and source.name.lower() not in lower_names:
4761
continue
4862

63+
if source.name.lower() == "pypi":
64+
is_pypi_implicit = False
65+
4966
table = self.table(style="compact")
5067
rows: Rows = [["<info>name</>", f" : <c1>{source.name}</>"]]
5168
if source.url:
@@ -55,4 +72,7 @@ def handle(self) -> int:
5572
table.render()
5673
self.line("")
5774

75+
if not names and is_pypi_implicit:
76+
self.notify_implicit_pypi()
77+
5878
return 0

tests/console/commands/source/test_show.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import pytest
66

7+
from poetry.repositories.pypi_repository import PyPiRepository
8+
79

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

180182

183+
def test_source_show_no_sources_implicit_pypi(
184+
tester_no_sources: CommandTester, poetry_without_source: Poetry
185+
) -> None:
186+
poetry_without_source.pool.add_repository(PyPiRepository())
187+
tester_no_sources.execute("")
188+
189+
output = tester_no_sources.io.fetch_output().strip()
190+
191+
assert "No sources configured for this project." in output
192+
assert "PyPI is implicitly enabled as a primary source." in output
193+
194+
assert tester_no_sources.status_code == 0
195+
196+
181197
def test_source_show_error(tester: CommandTester) -> None:
182198
tester.execute("error")
183199
assert tester.io.fetch_error().strip() == "No source found with name(s): error"

0 commit comments

Comments
 (0)