Skip to content

Commit 1df6f53

Browse files
committed
sources: deprecate priority 'default'
1 parent 901cdb2 commit 1df6f53

File tree

5 files changed

+68
-29
lines changed

5 files changed

+68
-29
lines changed

docs/repositories.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ priority = "primary"
126126
If `priority` is undefined, the source is considered a primary source that takes precedence over PyPI, secondary, supplemental and explicit sources.
127127

128128
Package sources are considered in the following order:
129-
1. [default source](#default-package-source),
129+
1. [default source](#default-package-source-deprecated) (DEPRECATED),
130130
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),
131+
3. implicit PyPI (unless disabled by another [primary source](#primary-package-sources), [default source](#default-package-source-deprecated) or configured explicitly),
132132
4. [secondary sources](#secondary-package-sources-deprecated) (DEPRECATED),
133133
5. [supplemental sources](#supplemental-package-sources).
134134

@@ -145,20 +145,29 @@ 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),
149148
just add a [primary source](#primary-package-sources)
150149
or configure PyPI as [explicit source](#explicit-package-sources).
151150

152151
{{% /note %}}
153152

154153

155-
#### Default Package Source
154+
#### Default Package Source (DEPRECATED)
155+
156+
*Deprecated in 1.8.0*
157+
158+
{{% warning %}}
159+
160+
Configuring a default package source is deprecated because it is the same
161+
as the topmost [primary source](#primary-package-sources).
162+
Just configure a primary package source and put it first in the list of package sources.
163+
164+
{{% /warning %}}
156165

157166
By default, if you have not configured any primary source,
158167
Poetry will configure [PyPI](https://pypi.org) as the package source for your project.
159168
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"`.
169+
package sources by adding at least one primary source (recommended)
170+
or a **single** source with `priority = "default"` (deprecated).
162171

163172
```bash
164173
poetry source add --priority=default foo https://foo.bar/simple/

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,20 @@ def handle(self) -> int:
107107
priority = Priority[priority_str.upper()]
108108

109109
if priority is Priority.SECONDARY:
110-
allowed_prios = (p for p in Priority if p is not Priority.SECONDARY)
110+
allowed_prios = (
111+
p for p in Priority if p not in {Priority.DEFAULT, Priority.SECONDARY}
112+
)
111113
self.line_error(
112114
"<warning>Warning: Priority 'secondary' is deprecated. Consider"
113115
" changing the priority to one of the non-deprecated values:"
114116
f" {', '.join(repr(p.name.lower()) for p in allowed_prios)}.</warning>"
115117
)
118+
if priority is Priority.DEFAULT:
119+
self.line_error(
120+
"<warning>Warning: Priority 'default' is deprecated. You can achieve"
121+
" the same effect by changing the priority to 'primary' and putting"
122+
" the source first.</warning>"
123+
)
116124

117125
sources = AoT([])
118126
new_source = Source(name=name, url=url, priority=priority)

src/poetry/factory.py

+8
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ def create_pool(
159159
f" {', '.join(repr(p.name.lower()) for p in allowed_prios)}."
160160
)
161161
io.write_error_line(f"<warning>Warning: {warning}</warning>")
162+
elif priority is Priority.DEFAULT:
163+
warning = (
164+
"Found deprecated priority 'default' for source"
165+
f" '{source.get('name')}' in pyproject.toml. You can achieve"
166+
" the same effect by changing the priority to 'primary' and putting"
167+
" the source first."
168+
)
169+
io.write_error_line(f"<warning>Warning: {warning}</warning>")
162170

163171
if io.is_debug():
164172
message = f"Adding repository {repository.name} ({repository.url})"

tests/console/commands/source/test_add.py

+30-21
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,34 @@ def tester(
2222
return command_tester_factory("source add", poetry=poetry_with_source)
2323

2424

25+
def _get_source_warning(priority: Priority) -> str:
26+
if priority is Priority.SECONDARY:
27+
return (
28+
"Warning: Priority 'secondary' is deprecated. Consider changing the"
29+
" priority to one of the non-deprecated values: 'primary',"
30+
" 'supplemental', 'explicit'."
31+
)
32+
elif priority is Priority.DEFAULT:
33+
return (
34+
"Warning: Priority 'default' is deprecated. You can achieve"
35+
" the same effect by changing the priority to 'primary' and putting"
36+
" the source first."
37+
)
38+
return ""
39+
40+
2541
def assert_source_added_legacy(
2642
tester: CommandTester,
2743
poetry: Poetry,
2844
source_existing: Source,
2945
source_added: Source,
3046
) -> None:
31-
secondary_deprecated_str = (
32-
""
33-
if source_added.priority is not Priority.SECONDARY
34-
else (
35-
"\nWarning: Priority 'secondary' is deprecated. Consider changing the"
36-
" priority to one of the non-deprecated values: 'default', 'primary',"
37-
" 'supplemental', 'explicit'."
38-
)
39-
)
40-
assert (
41-
tester.io.fetch_error().strip()
42-
== "Warning: Priority was set through a deprecated flag (--default or"
43-
" --secondary). Consider using --priority next time."
44-
+ secondary_deprecated_str
47+
warning = (
48+
"Warning: Priority was set through a deprecated flag (--default or"
49+
" --secondary). Consider using --priority next time.\n"
50+
+ _get_source_warning(source_added.priority)
4551
)
52+
assert tester.io.fetch_error().strip() == warning
4653
assert (
4754
tester.io.fetch_output().strip()
4855
== f"Adding source with name {source_added.name}."
@@ -59,6 +66,7 @@ def assert_source_added(
5966
source_existing: Source,
6067
source_added: Source,
6168
) -> None:
69+
assert tester.io.fetch_error().strip() == _get_source_warning(source_added.priority)
6270
assert (
6371
tester.io.fetch_output().strip()
6472
== f"Adding source with name {source_added.name}."
@@ -126,9 +134,9 @@ def test_source_add_second_default_fails(
126134
tester.execute(f"--priority=default {source_default.name}1 {source_default.url}")
127135
assert (
128136
tester.io.fetch_error().strip()
129-
== f"Source with name {source_default.name} is already set to"
130-
" default. Only one default source can be configured at a"
131-
" time."
137+
== f"{_get_source_warning(source_default.priority)}\n"
138+
f"Source with name {source_default.name} is already set to default."
139+
" Only one default source can be configured at a time."
132140
)
133141
assert tester.status_code == 1
134142

@@ -238,7 +246,7 @@ def test_source_add_existing_legacy(
238246
tester.io.fetch_error().strip()
239247
== "Warning: Priority was set through a deprecated flag"
240248
" (--default or --secondary). Consider using --priority next"
241-
" time."
249+
f" time.\n{_get_source_warning(Priority.DEFAULT)}"
242250
)
243251
assert (
244252
tester.io.fetch_output().strip()
@@ -313,16 +321,17 @@ def test_source_add_existing_fails_due_to_other_default(
313321
poetry_with_source: Poetry,
314322
) -> None:
315323
tester.execute(f"--priority=default {source_default.name} {source_default.url}")
324+
tester.io.fetch_error()
316325
tester.io.fetch_output()
317326

318327
name = getattr(source_existing.name, modifier)()
319328
tester.execute(f"--priority=default {name} {source_existing.url}")
320329

321330
assert (
322331
tester.io.fetch_error().strip()
323-
== f"Source with name {source_default.name} is already set to"
324-
" default. Only one default source can be configured at a"
325-
" time."
332+
== f"{_get_source_warning(source_default.priority)}\n"
333+
f"Source with name {source_default.name} is already set to default."
334+
" Only one default source can be configured at a time."
326335
)
327336
assert tester.io.fetch_output().strip() == ""
328337
assert tester.status_code == 1

tests/test_factory.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ def test_poetry_with_default_source(
241241
poetry = Factory().create_poetry(fixture_dir("with_default_source"), io=io)
242242

243243
assert len(poetry.pool.repositories) == 1
244-
assert io.fetch_error() == ""
244+
assert (
245+
io.fetch_error().strip()
246+
== "<warning>Warning: Found deprecated priority 'default' for source 'foo' in"
247+
" pyproject.toml. You can achieve the same effect by changing the priority"
248+
" to 'primary' and putting the source first."
249+
)
245250

246251

247252
def test_poetry_with_default_source_and_pypi(

0 commit comments

Comments
 (0)