Skip to content

Commit 901cdb2

Browse files
committed
sources: make warning about disabling PyPI become true
1 parent b7961ff commit 901cdb2

File tree

3 files changed

+44
-58
lines changed

3 files changed

+44
-58
lines changed

docs/repositories.md

+28-17
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ If `priority` is undefined, the source is considered a primary source that takes
127127

128128
Package sources are considered in the following order:
129129
1. [default source](#default-package-source),
130-
2. primary sources,
131-
3. implicit PyPI (unless disabled by another [default source](#default-package-source) or configured explicitly),
132-
4. [secondary sources](#secondary-package-sources) (DEPRECATED),
130+
2. [primary sources](#primary-package-sources),
131+
3. implicit PyPI (unless disabled by another [primary source](#primary-package-sources), [default source](#default-package-source) or configured explicitly),
132+
4. [secondary sources](#secondary-package-sources-deprecated) (DEPRECATED),
133133
5. [supplemental sources](#supplemental-package-sources).
134134

135135
[Explicit sources](#explicit-package-sources) are considered only for packages that explicitly [indicate their source](#package-source-constraint).
@@ -145,27 +145,45 @@ poetry source add --priority=primary PyPI
145145
```
146146

147147
If you prefer to disable PyPI completely,
148-
you may choose to set one of your package sources to be the [default](#default-package-source)
148+
you may choose to set one of your package sources to be the [default](#default-package-source),
149+
just add a [primary source](#primary-package-sources)
149150
or configure PyPI as [explicit source](#explicit-package-sources).
150151

151152
{{% /note %}}
152153

153154

154155
#### Default Package Source
155156

156-
By default, Poetry configures [PyPI](https://pypi.org) as the default package source for your
157-
project. You can alter this behaviour and exclusively look up packages only from the configured
158-
package sources by adding a **single** source with `priority = "default"`.
157+
By default, if you have not configured any primary source,
158+
Poetry will configure [PyPI](https://pypi.org) as the package source for your project.
159+
You can alter this behaviour and exclusively look up packages only from the configured
160+
package sources by adding at least one primary source
161+
or a **single** source with `priority = "default"`.
159162

160163
```bash
161164
poetry source add --priority=default foo https://foo.bar/simple/
162165
```
163166

167+
168+
#### Primary Package Sources
169+
170+
All primary package sources are searched for each dependency without a [source constraint](#package-source-constraint).
171+
If you configure at least one primary source, the implicit PyPI source is disabled.
172+
173+
```bash
174+
poetry source add --priority=primary foo https://foo.bar/simple/
175+
```
176+
177+
Sources without a priority are considered primary sources, too.
178+
179+
```bash
180+
poetry source add foo https://foo.bar/simple/
181+
```
182+
164183
{{% warning %}}
165184

166-
In a future version of Poetry, PyPI will be disabled automatically
167-
if at least one custom primary source is configured.
168-
If you are using custom sources in addition to PyPI, you should configure PyPI explicitly
185+
The implicit PyPI source is disabled automatically if at least one primary source is configured.
186+
If you want to use PyPI in addition to a primary source, configure it explicitly
169187
with a certain priority, e.g.
170188

171189
```bash
@@ -188,13 +206,6 @@ with Poetry, the PyPI repository cannot be configured with a given URL. Remember
188206

189207
{{% /warning %}}
190208

191-
{{% warning %}}
192-
193-
Configuring a custom package source as default, will effectively disable [PyPI](https://pypi.org)
194-
as a package source for your project.
195-
196-
{{% /warning %}}
197-
198209
#### Secondary Package Sources (DEPRECATED)
199210

200211
*Deprecated in 1.5.0*

src/poetry/factory.py

+3-20
Original file line numberDiff line numberDiff line change
@@ -175,32 +175,15 @@ def create_pool(
175175

176176
# Only add PyPI if no default repository is configured
177177
if not explicit_pypi:
178-
if pool.has_default():
178+
if pool.has_default() or pool.has_primary_repositories():
179179
if io.is_debug():
180180
io.write_line("Deactivating the PyPI repository")
181181
else:
182182
from poetry.repositories.pypi_repository import PyPiRepository
183183

184-
if pool.has_primary_repositories():
185-
io.write_error_line(
186-
"<warning>"
187-
"Warning: In a future version of Poetry, PyPI will be disabled"
188-
" automatically if at least one custom primary source is"
189-
" configured. In order to avoid"
190-
" a breaking change and make your pyproject.toml forward"
191-
" compatible, add PyPI explicitly via 'poetry source add pypi'."
192-
" By the way, this has the advantage that you can set the"
193-
" priority of PyPI as with any other source."
194-
"</warning>"
195-
)
196-
197-
if pool.has_primary_repositories():
198-
pypi_priority = Priority.SECONDARY
199-
else:
200-
pypi_priority = Priority.DEFAULT
201-
202184
pool.add_repository(
203-
PyPiRepository(disable_cache=disable_cache), priority=pypi_priority
185+
PyPiRepository(disable_cache=disable_cache),
186+
priority=Priority.PRIMARY,
204187
)
205188

206189
if not pool.repositories:

tests/test_factory.py

+13-21
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,11 @@ def test_poetry_with_non_default_source(
280280
poetry = Factory().create_poetry(fixture_dir(project), io=io)
281281

282282
assert not poetry.pool.has_default()
283-
assert poetry.pool.has_repository("PyPI")
284-
assert poetry.pool.get_priority("PyPI") is Priority.SECONDARY
285-
assert isinstance(poetry.pool.repository("PyPI"), PyPiRepository)
283+
assert not poetry.pool.has_repository("PyPI")
286284
assert poetry.pool.has_repository("foo")
287285
assert poetry.pool.get_priority("foo") is Priority.PRIMARY
288286
assert isinstance(poetry.pool.repository("foo"), LegacyRepository)
289-
assert {repo.name for repo in poetry.pool.repositories} == {"PyPI", "foo"}
290-
error = io.fetch_error()
291-
assert "Warning: In a future version of Poetry, PyPI will be disabled" in error
287+
assert {repo.name for repo in poetry.pool.repositories} == {"foo"}
292288

293289

294290
def test_poetry_with_non_default_secondary_source_legacy(
@@ -300,7 +296,7 @@ def test_poetry_with_non_default_secondary_source_legacy(
300296

301297
assert poetry.pool.has_repository("PyPI")
302298
assert isinstance(poetry.pool.repository("PyPI"), PyPiRepository)
303-
assert poetry.pool.get_priority("PyPI") is Priority.DEFAULT
299+
assert poetry.pool.get_priority("PyPI") is Priority.PRIMARY
304300
assert poetry.pool.has_repository("foo")
305301
assert isinstance(poetry.pool.repository("foo"), LegacyRepository)
306302
assert {repo.name for repo in poetry.pool.repositories} == {"PyPI", "foo"}
@@ -313,7 +309,7 @@ def test_poetry_with_non_default_secondary_source(
313309

314310
assert poetry.pool.has_repository("PyPI")
315311
assert isinstance(poetry.pool.repository("PyPI"), PyPiRepository)
316-
assert poetry.pool.get_priority("PyPI") is Priority.DEFAULT
312+
assert poetry.pool.get_priority("PyPI") is Priority.PRIMARY
317313
assert poetry.pool.has_repository("foo")
318314
assert isinstance(poetry.pool.repository("foo"), LegacyRepository)
319315
assert {repo.name for repo in poetry.pool.repositories} == {"PyPI", "foo"}
@@ -329,7 +325,7 @@ def test_poetry_with_non_default_multiple_secondary_sources_legacy(
329325

330326
assert poetry.pool.has_repository("PyPI")
331327
assert isinstance(poetry.pool.repository("PyPI"), PyPiRepository)
332-
assert poetry.pool.get_priority("PyPI") is Priority.DEFAULT
328+
assert poetry.pool.get_priority("PyPI") is Priority.PRIMARY
333329
assert poetry.pool.has_repository("foo")
334330
assert isinstance(poetry.pool.repository("foo"), LegacyRepository)
335331
assert poetry.pool.has_repository("bar")
@@ -346,7 +342,7 @@ def test_poetry_with_non_default_multiple_secondary_sources(
346342

347343
assert poetry.pool.has_repository("PyPI")
348344
assert isinstance(poetry.pool.repository("PyPI"), PyPiRepository)
349-
assert poetry.pool.get_priority("PyPI") is Priority.DEFAULT
345+
assert poetry.pool.get_priority("PyPI") is Priority.PRIMARY
350346
assert poetry.pool.has_repository("foo")
351347
assert isinstance(poetry.pool.repository("foo"), LegacyRepository)
352348
assert poetry.pool.has_repository("bar")
@@ -364,12 +360,10 @@ def test_poetry_with_non_default_multiple_sources_legacy(
364360
assert not poetry.pool.has_default()
365361
assert poetry.pool.has_repository("bar")
366362
assert isinstance(poetry.pool.repository("bar"), LegacyRepository)
367-
assert poetry.pool.has_repository("PyPI")
368-
assert poetry.pool.get_priority("PyPI") is Priority.SECONDARY
369-
assert isinstance(poetry.pool.repository("PyPI"), PyPiRepository)
363+
assert not poetry.pool.has_repository("PyPI")
370364
assert poetry.pool.has_repository("foo")
371365
assert isinstance(poetry.pool.repository("foo"), LegacyRepository)
372-
assert {repo.name for repo in poetry.pool.repositories} == {"bar", "PyPI", "foo"}
366+
assert {repo.name for repo in poetry.pool.repositories} == {"bar", "foo"}
373367

374368

375369
def test_poetry_with_non_default_multiple_sources(
@@ -378,14 +372,12 @@ def test_poetry_with_non_default_multiple_sources(
378372
poetry = Factory().create_poetry(fixture_dir("with_non_default_multiple_sources"))
379373

380374
assert not poetry.pool.has_default()
381-
assert poetry.pool.has_repository("PyPI")
382-
assert isinstance(poetry.pool.repository("PyPI"), PyPiRepository)
383-
assert poetry.pool.get_priority("PyPI") is Priority.SECONDARY
375+
assert not poetry.pool.has_repository("PyPI")
384376
assert poetry.pool.has_repository("bar")
385377
assert isinstance(poetry.pool.repository("bar"), LegacyRepository)
386378
assert poetry.pool.has_repository("foo")
387379
assert isinstance(poetry.pool.repository("foo"), LegacyRepository)
388-
assert {repo.name for repo in poetry.pool.repositories} == {"PyPI", "bar", "foo"}
380+
assert {repo.name for repo in poetry.pool.repositories} == {"bar", "foo"}
389381

390382

391383
def test_poetry_with_non_default_multiple_sources_pypi(
@@ -417,7 +409,7 @@ def test_poetry_with_no_default_source(fixture_dir: FixtureDirGetter) -> None:
417409
poetry = Factory().create_poetry(fixture_dir("sample_project"))
418410

419411
assert poetry.pool.has_repository("PyPI")
420-
assert poetry.pool.get_priority("PyPI") is Priority.DEFAULT
412+
assert poetry.pool.get_priority("PyPI") is Priority.PRIMARY
421413
assert isinstance(poetry.pool.repository("PyPI"), PyPiRepository)
422414
assert {repo.name for repo in poetry.pool.repositories} == {"PyPI"}
423415

@@ -429,7 +421,7 @@ def test_poetry_with_supplemental_source(
429421
poetry = Factory().create_poetry(fixture_dir("with_supplemental_source"), io=io)
430422

431423
assert poetry.pool.has_repository("PyPI")
432-
assert poetry.pool.get_priority("PyPI") is Priority.DEFAULT
424+
assert poetry.pool.get_priority("PyPI") is Priority.PRIMARY
433425
assert isinstance(poetry.pool.repository("PyPI"), PyPiRepository)
434426
assert poetry.pool.has_repository("supplemental")
435427
assert poetry.pool.get_priority("supplemental") is Priority.SUPPLEMENTAL
@@ -447,7 +439,7 @@ def test_poetry_with_explicit_source(
447439
assert len(poetry.pool.repositories) == 1
448440
assert len(poetry.pool.all_repositories) == 2
449441
assert poetry.pool.has_repository("PyPI")
450-
assert poetry.pool.get_priority("PyPI") is Priority.DEFAULT
442+
assert poetry.pool.get_priority("PyPI") is Priority.PRIMARY
451443
assert isinstance(poetry.pool.repository("PyPI"), PyPiRepository)
452444
assert poetry.pool.has_repository("explicit")
453445
assert isinstance(poetry.pool.repository("explicit"), LegacyRepository)

0 commit comments

Comments
 (0)