Skip to content
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

remove deprecated source priorities default and secondary #9698

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
13 changes: 4 additions & 9 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ poetry add requests pendulum
```

{{% note %}}
A package is looked up, by default, only from the [Default Package Source]({{< relref "repositories/#default-package-source" >}}).
You can modify the default source (PyPI); or add and use [Supplemental Package Sources]({{< relref "repositories/#supplemental-package-sources" >}})
A package is looked up, by default, only from [PyPI](https://pypi.org).
You can modify the default source (PyPI);
or add and use [Supplemental Package Sources]({{< relref "repositories/#supplemental-package-sources" >}})
or [Explicit Package Sources]({{< relref "repositories/#explicit-package-sources" >}}).

For more information, refer to the [Package Sources]({{< relref "repositories/#package-sources" >}}) documentation.
Expand Down Expand Up @@ -865,13 +866,7 @@ poetry source add --priority=explicit pypi

#### Options

* `--default`: Set this source as the [default]({{< relref "repositories#default-package-source" >}}) (disable PyPI). Deprecated in favor of `--priority`.
* `--secondary`: Set this source as a [secondary]({{< relref "repositories#secondary-package-sources" >}}) source. Deprecated in favor of `--priority`.
* `--priority`: Set the priority of this source. Accepted values are: [`default`]({{< relref "repositories#default-package-source" >}}), [`secondary`]({{< relref "repositories#secondary-package-sources" >}}), [`supplemental`]({{< relref "repositories#supplemental-package-sources" >}}), and [`explicit`]({{< relref "repositories#explicit-package-sources" >}}). Refer to the dedicated sections in [Repositories]({{< relref "repositories" >}}) for more information.

{{% note %}}
At most one of the options above can be provided. See [package sources]({{< relref "repositories#package-sources" >}}) for more information.
{{% /note %}}
* `--priority`: Set the priority of this source. Accepted values are: [`supplemental`]({{< relref "repositories#supplemental-package-sources" >}}), and [`explicit`]({{< relref "repositories#explicit-package-sources" >}}). Refer to the dedicated sections in [Repositories]({{< relref "repositories" >}}) for more information.

### source show

Expand Down
86 changes: 15 additions & 71 deletions docs/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ poetry publish --build --repository foo-pub

## Package Sources

By default, Poetry is configured to use the Python ecosystem's canonical package index
By default, if you have not configured any primary source,
Poetry is configured to use the Python ecosystem's canonical package index
[PyPI](https://pypi.org).
You can alter this behaviour and exclusively look up packages only from the configured
package sources by adding at least one primary source.

{{% note %}}

With the exception of the implicitly configured source for [PyPI](https://pypi.org) named `pypi`,
Except for the implicitly configured source for [PyPI](https://pypi.org) named `PyPI`,
package sources are local to a project and must be configured within the project's
[`pyproject.toml`]({{< relref "pyproject" >}}) file. This is **not** the same configuration used
when publishing a package.
Expand Down Expand Up @@ -142,56 +145,17 @@ url = "https://foo.bar/simple/"
priority = "primary"
```

If `priority` is undefined, the source is considered a primary source that takes precedence over PyPI, secondary, supplemental and explicit sources.
If `priority` is undefined, the source is considered a primary source,
which disables the implicit PyPI source and takes precedence over supplemental sources.

Package sources are considered in the following order:
1. [default source](#default-package-source-deprecated) (DEPRECATED),
2. [primary sources](#primary-package-sources),
3. implicit PyPI (unless disabled by another [primary source](#primary-package-sources), [default source](#default-package-source-deprecated) or configured explicitly),
4. [secondary sources](#secondary-package-sources-deprecated) (DEPRECATED),
5. [supplemental sources](#supplemental-package-sources).
1. [primary sources](#primary-package-sources) or implicit PyPI (if there are no primary sources),
2. [supplemental sources](#supplemental-package-sources).

[Explicit sources](#explicit-package-sources) are considered only for packages that explicitly [indicate their source](#package-source-constraint).

Within each priority class, package sources are considered in order of appearance in `pyproject.toml`.

{{% note %}}

If you want to change the priority of [PyPI](https://pypi.org), you can set it explicitly, e.g.

```bash
poetry source add --priority=primary PyPI
```

If you prefer to disable PyPI completely,
just add a [primary source](#primary-package-sources)
or configure PyPI as [explicit source](#explicit-package-sources).

{{% /note %}}


#### 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 (recommended)
or a **single** source with `priority = "default"` (deprecated).

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


#### Primary Package Sources

Expand Down Expand Up @@ -234,27 +198,6 @@ with Poetry, the PyPI repository cannot be configured with a given URL. Remember

{{% /warning %}}

#### Secondary Package Sources (DEPRECATED)

*Deprecated in 1.5.0*

If package sources are configured as secondary, all it means is that these will be given a lower
priority when selecting compatible package distribution that also exists in your default and primary package sources. If the package source should instead be searched only if higher-priority repositories did not return results, please consider a [supplemental source](#supplemental-package-sources) instead.

You can configure a package source as a secondary source with `priority = "secondary"` in your package
source configuration.

```bash
poetry source add --priority=secondary foo https://foo.bar/simple/
```

There can be more than one secondary package source.

{{% warning %}}

Secondary package sources are deprecated in favor of supplemental package sources.

{{% /warning %}}

#### Supplemental Package Sources

Expand Down Expand Up @@ -305,9 +248,10 @@ poetry add --source pytorch-gpu-src torch torchvision torchaudio

#### Package Source Constraint

All package sources (including secondary and possibly supplemental sources) will be searched during the package lookup
process. These network requests will occur for all sources, regardless of if the package is
found at one or more sources.
All package sources (including possibly supplemental sources) will be searched
during the package lookup process.
These network requests will occur for all primary sources, regardless of if the package is
found at one or more sources, and all supplemental sources until the package is found.

In order to limit the search for a specific package to a particular package repository, you can specify the source explicitly.

Expand Down Expand Up @@ -398,8 +342,8 @@ httpx = {version = "^0.22.0", source = "pypi"}

{{% warning %}}

If any source within a project is configured with `priority = "default"`, The implicit `pypi` source will
be disabled and not used for any packages.
The implicit `PyPI` source will be disabled and not used for any packages
if at least one [primary source](#primary-package-sources) is configured.

{{% /warning %}}

Expand Down
17 changes: 1 addition & 16 deletions src/poetry/config/source.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import dataclasses
import warnings

from typing import TYPE_CHECKING

Expand All @@ -16,27 +15,13 @@
class Source:
name: str
url: str = ""
default: dataclasses.InitVar[bool] = False
secondary: dataclasses.InitVar[bool] = False
priority: Priority = (
Priority.PRIMARY
) # cheating in annotation: str will be converted to Priority in __post_init__

def __post_init__(self, default: bool, secondary: bool) -> None:
def __post_init__(self) -> None:
if isinstance(self.priority, str):
self.priority = Priority[self.priority.upper()]
if default or secondary:
warnings.warn(
"Parameters 'default' and 'secondary' to"
" 'Source' are deprecated. Please provide"
" 'priority' instead.",
DeprecationWarning,
stacklevel=2,
)
if default:
self.priority = Priority.DEFAULT
elif secondary:
self.priority = Priority.SECONDARY

def to_dict(self) -> dict[str, str | bool]:
return dataclasses.asdict(
Expand Down
67 changes: 1 addition & 66 deletions src/poetry/console/commands/source/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ class SourceAddCommand(Command):
]

options: ClassVar[list[Option]] = [
option(
"default",
"d",
"Set this source as the default (disable PyPI). A "
"default source will also be the fallback source if "
"you add other sources. (<warning>Deprecated</warning>, use --priority)",
),
option(
"secondary",
"s",
"Set this source as secondary. (<warning>Deprecated</warning>, use"
" --priority)",
),
option(
"priority",
"p",
Expand All @@ -65,8 +52,6 @@ def handle(self) -> int:
name: str = self.argument("name")
lower_name = name.lower()
url: str = self.argument("url")
is_default: bool = self.option("default", False)
is_secondary: bool = self.option("secondary", False)
priority_str: str | None = self.option("priority", None)

if lower_name == "pypi":
Expand All @@ -82,66 +67,16 @@ def handle(self) -> int:
)
return 1

if is_default and is_secondary:
self.line_error(
"<error>Cannot configure a source as both <c1>default</c1> and"
" <c1>secondary</c1>.</error>"
)
return 1

if is_default or is_secondary:
if priority_str is not None:
self.line_error(
"<error>Priority was passed through both --priority and a"
" deprecated flag (--default or --secondary). Please only provide"
" one of these.</error>"
)
return 1
else:
self.line_error(
"<warning>Warning: Priority was set through a deprecated flag"
" (--default or --secondary). Consider using --priority next"
" time.</warning>"
)

if is_default:
priority = Priority.DEFAULT
elif is_secondary:
priority = Priority.SECONDARY
elif priority_str is None:
if priority_str is None:
priority = Priority.PRIMARY
else:
priority = Priority[priority_str.upper()]

if priority is Priority.SECONDARY:
allowed_prios = (
p for p in Priority if p not in {Priority.DEFAULT, Priority.SECONDARY}
)
self.line_error(
"<warning>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)}.</warning>"
)
if priority is Priority.DEFAULT:
self.line_error(
"<warning>Warning: Priority 'default' is deprecated. You can achieve"
" the same effect by changing the priority to 'primary' and putting"
" the source first.</warning>"
)

sources = AoT([])
new_source = Source(name=name, url=url, priority=priority)
is_new_source = True

for source in self.poetry.get_sources():
if source.priority is Priority.DEFAULT and priority is Priority.DEFAULT:
self.line_error(
f"<error>Source with name <c1>{source.name}</c1> is already set to"
" default. Only one default source can be configured at a"
" time.</error>"
)
return 1

if source.name.lower() == lower_name:
source = new_source
is_new_source = False
Expand Down
44 changes: 5 additions & 39 deletions src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,54 +130,20 @@ def create_pool(
source, config, disable_cache=disable_cache
)
priority = Priority[source.get("priority", Priority.PRIMARY.name).upper()]
if "default" in source or "secondary" in source:
warning = (
"Found deprecated key 'default' or 'secondary' in"
" pyproject.toml configuration for source"
f" {source.get('name')}. Please provide the key 'priority'"
" instead. Accepted values are:"
f" {', '.join(repr(p.name.lower()) for p in Priority)}."
)
io.write_error_line(f"<warning>Warning: {warning}</warning>")
if source.get("default"):
priority = Priority.DEFAULT
elif source.get("secondary"):
priority = Priority.SECONDARY

if priority is Priority.SECONDARY:
allowed_prios = (p for p in Priority if p is not Priority.SECONDARY)
warning = (
"Found deprecated priority 'secondary' for source"
f" '{source.get('name')}' in pyproject.toml. Consider changing the"
" priority to one of the non-deprecated values:"
f" {', '.join(repr(p.name.lower()) for p in allowed_prios)}."
)
io.write_error_line(f"<warning>Warning: {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: {warning}</warning>")

if io.is_debug():
message = f"Adding repository {repository.name} ({repository.url})"
if priority is Priority.DEFAULT:
message += " and setting it as the default one"
else:
message += f" and setting it as {priority.name.lower()}"

io.write_line(message)
io.write_line(
f"Adding repository {repository.name} ({repository.url})"
f" and setting it as {priority.name.lower()}"
)

pool.add_repository(repository, priority=priority)
if repository.name.lower() == "pypi":
explicit_pypi = True

# Only add PyPI if no default repository is configured
if not explicit_pypi:
if pool.has_default() or pool.has_primary_repositories():
if pool.has_primary_repositories():
if io.is_debug():
io.write_line("Deactivating the PyPI repository")
else:
Expand Down
26 changes: 0 additions & 26 deletions src/poetry/json/schemas/poetry.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,9 @@
"description": "The url of the repository.",
"format": "uri"
},
"default": {
"type": "boolean",
"description": "Make this repository the default (disable PyPI). (deprecated, see priority)"
},
"secondary": {
"type": "boolean",
"description": "Declare this repository as secondary, i.e. default repositories take precedence. (deprecated, see priority)"
},
"priority": {
"enum": [
"primary",
"default",
"secondary",
"supplemental",
"explicit"
],
Expand All @@ -58,22 +48,6 @@
"type": "boolean",
"description": "For PEP 503 simple API repositories, pre-fetch and index the available packages. (experimental)"
}
},
"not": {
"anyOf": [
{
"required": [
"priority",
"default"
]
},
{
"required": [
"priority",
"secondary"
]
}
]
}
}
}
Expand Down
Loading
Loading