diff --git a/docs/repositories.md b/docs/repositories.md index 16a1b90d182..6dc0209b3a7 100644 --- a/docs/repositories.md +++ b/docs/repositories.md @@ -126,7 +126,7 @@ priority = "primary" If `priority` is undefined, the source is considered a primary source that takes precedence over PyPI, secondary, supplemental and explicit sources. Package sources are considered in the following order: -1. [default source](#default-package-source), +1. [default source](#default-package-source) (DEPRECATED), 2. [primary sources](#primary-package-sources), 3. implicit PyPI (unless disabled by another [primary source](#primary-package-source), [default source](#default-package-source) or configured explicitly), 4. [secondary sources](#secondary-package-sources) (DEPRECATED), @@ -145,20 +145,29 @@ poetry source add --priority=primary PyPI ``` If you prefer to disable PyPI completely, -you may choose to set one of your package sources to be the [default](#default-package-source), just add a [primary source](#primary-package-sources) or configure PyPI as [explicit source](#explicit-package-sources). {{% /note %}} -#### Default Package Source +#### Default Package Source (DEPRECATED) + +*Deprecated in 1.8.0* + +{{% warning %}} + +Configuring a default package source is deprecated because it is the same +as the topmost [primary source](#primary-package-sources). +Just configure a primary package source and put it first in the list of package sources. + +{{% /warning %}} By default, if you have not configured any primary source, Poetry will configure [PyPI](https://pypi.org) as the package source for your project. You can alter this behaviour and exclusively look up packages only from the configured -package sources by adding at least one primary source -or a **single** source with `priority = "default"`. +package sources by adding at least one primary source (recommended) +or a **single** source with `priority = "default"` (deprecated). ```bash poetry source add --priority=default foo https://foo.bar/simple/ diff --git a/src/poetry/console/commands/source/add.py b/src/poetry/console/commands/source/add.py index 5e1526f0f95..6d1ab587ee6 100644 --- a/src/poetry/console/commands/source/add.py +++ b/src/poetry/console/commands/source/add.py @@ -107,12 +107,20 @@ def handle(self) -> int: priority = Priority[priority_str.upper()] if priority is Priority.SECONDARY: - allowed_prios = (p for p in Priority if p is not Priority.SECONDARY) + allowed_prios = ( + p for p in Priority if p not in {Priority.DEFAULT, Priority.SECONDARY} + ) self.line_error( "Warning: Priority 'secondary' is deprecated. Consider" " changing the priority to one of the non-deprecated values:" f" {', '.join(repr(p.name.lower()) for p in allowed_prios)}." ) + if priority is Priority.DEFAULT: + self.line_error( + "Warning: Priority 'default' is deprecated. You can achieve" + " the same effect by changing the priority to 'primary' and putting" + " the source first." + ) sources = AoT([]) new_source = Source(name=name, url=url, priority=priority) diff --git a/src/poetry/factory.py b/src/poetry/factory.py index 6ba8f7ae4c1..16400eda356 100644 --- a/src/poetry/factory.py +++ b/src/poetry/factory.py @@ -159,6 +159,14 @@ def create_pool( f" {', '.join(repr(p.name.lower()) for p in allowed_prios)}." ) io.write_error_line(f"Warning: {warning}") + elif priority is Priority.DEFAULT: + warning = ( + "Found deprecated priority 'default' for source" + f" '{source.get('name')}' in pyproject.toml. You can achieve" + " the same effect by changing the priority to 'primary' and putting" + " the source first." + ) + io.write_error_line(f"Warning: {warning}") if io.is_debug(): message = f"Adding repository {repository.name} ({repository.url})" diff --git a/tests/console/commands/source/test_add.py b/tests/console/commands/source/test_add.py index 01c24a37e1e..53ae876133a 100644 --- a/tests/console/commands/source/test_add.py +++ b/tests/console/commands/source/test_add.py @@ -22,27 +22,34 @@ def tester( return command_tester_factory("source add", poetry=poetry_with_source) +def _get_source_warning(priority: Priority) -> str: + if priority is Priority.SECONDARY: + return ( + "Warning: Priority 'secondary' is deprecated. Consider changing the" + " priority to one of the non-deprecated values: 'primary'," + " 'supplemental', 'explicit'." + ) + elif priority is Priority.DEFAULT: + return ( + "Warning: Priority 'default' is deprecated. You can achieve" + " the same effect by changing the priority to 'primary' and putting" + " the source first." + ) + return "" + + def assert_source_added_legacy( tester: CommandTester, poetry: Poetry, source_existing: Source, source_added: Source, ) -> None: - secondary_deprecated_str = ( - "" - if source_added.priority is not Priority.SECONDARY - else ( - "\nWarning: Priority 'secondary' is deprecated. Consider changing the" - " priority to one of the non-deprecated values: 'default', 'primary'," - " 'supplemental', 'explicit'." - ) - ) - assert ( - tester.io.fetch_error().strip() - == "Warning: Priority was set through a deprecated flag (--default or" - " --secondary). Consider using --priority next time." - + secondary_deprecated_str + warning = ( + "Warning: Priority was set through a deprecated flag (--default or" + " --secondary). Consider using --priority next time.\n" + + _get_source_warning(source_added.priority) ) + assert tester.io.fetch_error().strip() == warning assert ( tester.io.fetch_output().strip() == f"Adding source with name {source_added.name}." @@ -59,6 +66,7 @@ def assert_source_added( source_existing: Source, source_added: Source, ) -> None: + assert tester.io.fetch_error().strip() == _get_source_warning(source_added.priority) assert ( tester.io.fetch_output().strip() == f"Adding source with name {source_added.name}." @@ -126,9 +134,9 @@ def test_source_add_second_default_fails( tester.execute(f"--priority=default {source_default.name}1 {source_default.url}") assert ( tester.io.fetch_error().strip() - == f"Source with name {source_default.name} is already set to" - " default. Only one default source can be configured at a" - " time." + == f"{_get_source_warning(source_default.priority)}\n" + f"Source with name {source_default.name} is already set to default." + " Only one default source can be configured at a time." ) assert tester.status_code == 1 @@ -238,7 +246,7 @@ def test_source_add_existing_legacy( tester.io.fetch_error().strip() == "Warning: Priority was set through a deprecated flag" " (--default or --secondary). Consider using --priority next" - " time." + f" time.\n{_get_source_warning(Priority.DEFAULT)}" ) assert ( tester.io.fetch_output().strip() @@ -313,6 +321,7 @@ def test_source_add_existing_fails_due_to_other_default( poetry_with_source: Poetry, ) -> None: tester.execute(f"--priority=default {source_default.name} {source_default.url}") + tester.io.fetch_error() tester.io.fetch_output() name = getattr(source_existing.name, modifier)() @@ -320,9 +329,9 @@ def test_source_add_existing_fails_due_to_other_default( assert ( tester.io.fetch_error().strip() - == f"Source with name {source_default.name} is already set to" - " default. Only one default source can be configured at a" - " time." + == f"{_get_source_warning(source_default.priority)}\n" + f"Source with name {source_default.name} is already set to default." + " Only one default source can be configured at a time." ) assert tester.io.fetch_output().strip() == "" assert tester.status_code == 1 diff --git a/tests/test_factory.py b/tests/test_factory.py index 7b844d52e72..f317c9408ff 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -241,7 +241,12 @@ def test_poetry_with_default_source( poetry = Factory().create_poetry(fixture_dir("with_default_source"), io=io) assert len(poetry.pool.repositories) == 1 - assert io.fetch_error() == "" + assert ( + io.fetch_error().strip() + == "Warning: Found deprecated priority 'default' for source 'foo' in" + " pyproject.toml. You can achieve the same effect by changing the priority" + " to 'primary' and putting the source first." + ) def test_poetry_with_default_source_and_pypi(