Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
bcallonnec committed Jan 29, 2024
2 parents 0439a7e + ed1dcdd commit 6dd8236
Show file tree
Hide file tree
Showing 46 changed files with 1,964 additions and 190 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
freebsd_instance:
image_family: freebsd-13-1
image_family: freebsd-13-2
cpu: 2
memory: 4G

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v3
uses: actions/cache@v4
id: cache
with:
path: .venv
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ repos:
- id: validate_manifest

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
rev: v0.1.14
hooks:
- id: ruff
8 changes: 8 additions & 0 deletions docs/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ See the **advanced** installation instructions to use a preview or alternate ver

{{< steps >}}
{{< step >}}
**Install pipx**

If `pipx` is not already installed, you can follow any of the options in the
[official pipx installation instructions](https://pipx.pypa.io/stable/installation/).
Any non-ancient version of `pipx` will do.

{{< /step >}}
{{< step >}}
**Install Poetry**

```bash
Expand Down
4 changes: 2 additions & 2 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ poetry add git+https://github.com/sdispater/pendulum.git#develop
poetry add git+https://github.com/sdispater/pendulum.git#2.0.5

# or using SSH instead:
poetry add git+ssh://github.com/sdispater/pendulum.git#develop
poetry add git+ssh://github.com/sdispater/pendulum.git#2.0.5
poetry add git+ssh://git@github.com:sdispater/pendulum.git#develop
poetry add git+ssh://git@github.com:sdispater/pendulum.git#2.0.5
```

or reference a subdirectory:
Expand Down
17 changes: 17 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,23 @@ across all your projects if incorrectly set.

Use parallel execution when using the new (`>=1.1.0`) installer.

### `solver.lazy-wheel`

**Type**: `boolean`

**Default**: `true`

**Environment Variable**: `POETRY_SOLVER_LAZY_WHEEL`

*Introduced in 1.8.0*

Do not download entire wheels to extract metadata but use
[HTTP range requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests)
to only download the METADATA files of wheels.
Especially with slow network connections this setting can speed up dependency resolution significantly.
If the cache has already been filled or the server does not support HTTP range requests,
this setting makes no difference.

### `virtualenvs.create`

**Type**: `boolean`
Expand Down
10 changes: 10 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ commands =
`tox` will not do any install. Poetry installs all the dependencies and the current package in editable mode.
Thus, tests are running against the local files and not the built and installed package.

#### Note about credentials

Note that `tox` does not forward the environment variables of your current shell session by default.
This may cause Poetry to not be able to install dependencies in the `tox` environments if you have configured
credentials using the system keyring on Linux systems or using environment variables in general.
You can use the `passenv` [configuration option](https://tox.wiki/en/latest/config.html#passenv) to forward the
required variables explicitly or `passenv = "*"` to forward all of them.
Linux systems may require forwarding the `DBUS_SESSION_BUS_ADDRESS` variable to allow access to the system keyring,
though this may vary between desktop environments.

### Is Nox supported?

Use the [`nox-poetry`](https://github.com/cjolowicz/nox-poetry) package to install locked versions of
Expand Down
7 changes: 0 additions & 7 deletions docs/pyproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,6 @@ my_package_cli = 'my_package.console:run'

Here, we will have the `my_package_cli` script installed which will execute the `run` function in the `console` module in the `my_package` package.

To specify a script that [depends on an extra](#extras), you may provide an entry as an inline table:

```toml
[tool.poetry.scripts]
devtest = { reference = "mypackage:test.run_tests", extras = ["test"], type = "console" }
```

{{% note %}}
When a script is added or updated, run `poetry install` to make them available in the project's virtualenv.
{{% /note %}}
Expand Down
58 changes: 39 additions & 19 deletions docs/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ 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),
2. primary sources,
3. implicit PyPI (unless disabled by another [default source](#default-package-source) or configured explicitly),
4. [secondary sources](#secondary-package-sources) (DEPRECATED),
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).

[Explicit sources](#explicit-package-sources) are considered only for packages that explicitly [indicate their source](#package-source-constraint).
Expand All @@ -145,27 +145,54 @@ 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)

By default, Poetry configures [PyPI](https://pypi.org) as the default package source for your
project. You can alter this behaviour and exclusively look up packages only from the configured
package sources by adding a **single** source with `priority = "default"`.
*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

All primary package sources are searched for each dependency without a [source constraint](#package-source-constraint).
If you configure at least one primary source, the implicit PyPI source is disabled.

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

Sources without a priority are considered primary sources, too.

```bash
poetry source add foo https://foo.bar/simple/
```

{{% warning %}}

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

```bash
Expand All @@ -188,13 +215,6 @@ with Poetry, the PyPI repository cannot be configured with a given URL. Remember

{{% /warning %}}

{{% warning %}}

Configuring a custom package source as default, will effectively disable [PyPI](https://pypi.org)
as a package source for your project.

{{% /warning %}}

#### Secondary Package Sources (DEPRECATED)

*Deprecated in 1.5.0*
Expand Down
4 changes: 4 additions & 0 deletions src/poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class Config:
"max-workers": None,
"no-binary": None,
},
"solver": {
"lazy-wheel": True,
},
"warnings": {
"export": True,
},
Expand Down Expand Up @@ -296,6 +299,7 @@ def _get_normalizer(name: str) -> Callable[[str], Any]:
"experimental.system-git-client",
"installer.modern-installation",
"installer.parallel",
"solver.lazy-wheel",
"warnings.export",
}:
return boolean_normalizer
Expand Down
32 changes: 25 additions & 7 deletions src/poetry/console/commands/build.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING

from cleo.helpers import option

from poetry.console.commands.env_command import EnvCommand
from poetry.utils.env import build_environment


if TYPE_CHECKING:
from pathlib import Path


class BuildCommand(EnvCommand):
name = "build"
description = "Builds a package, as a tarball and a wheel by default."
Expand All @@ -29,21 +33,35 @@ class BuildCommand(EnvCommand):
"poetry.core.masonry.builders.wheel",
]

def handle(self) -> int:
from poetry.core.masonry.builder import Builder
def _build(
self,
fmt: str,
executable: str | Path | None = None,
*,
target_dir: Path | None = None,
) -> None:
from poetry.masonry.builders import BUILD_FORMATS

if fmt in BUILD_FORMATS:
builders = [BUILD_FORMATS[fmt]]
elif fmt == "all":
builders = list(BUILD_FORMATS.values())
else:
raise ValueError(f"Invalid format: {fmt}")

for builder in builders:
builder(self.poetry, executable=executable).build(target_dir)

def handle(self) -> int:
with build_environment(poetry=self.poetry, env=self.env, io=self.io) as env:
fmt = self.option("format") or "all"
dist_dir = Path(self.option("output"))
package = self.poetry.package
self.line(
f"Building <c1>{package.pretty_name}</c1> (<c2>{package.version}</c2>)"
)

if not dist_dir.is_absolute():
dist_dir = self.poetry.pyproject_path.parent / dist_dir

builder = Builder(self.poetry)
builder.build(fmt, executable=env.python, target_dir=dist_dir)
self._build(fmt, executable=env.python, target_dir=dist_dir)

return 0
3 changes: 2 additions & 1 deletion src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ def unique_config_values(self) -> dict[str, tuple[Any, Any]]:
),
"virtualenvs.path": (str, lambda val: str(Path(val))),
"virtualenvs.prefer-active-python": (boolean_validator, boolean_normalizer),
"virtualenvs.prompt": (str, str),
"experimental.system-git-client": (boolean_validator, boolean_normalizer),
"installer.modern-installation": (boolean_validator, boolean_normalizer),
"installer.parallel": (boolean_validator, boolean_normalizer),
"installer.max-workers": (lambda val: int(val) > 0, int_normalizer),
"virtualenvs.prompt": (str, lambda val: str(val)),
"installer.no-binary": (
PackageFilterPolicy.validator,
PackageFilterPolicy.normalize,
),
"solver.lazy-wheel": (boolean_validator, boolean_normalizer),
"warnings.export": (boolean_validator, boolean_normalizer),
}

Expand Down
10 changes: 9 additions & 1 deletion src/poetry/console/commands/source/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>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)
Expand Down
31 changes: 11 additions & 20 deletions src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: {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})"
Expand All @@ -175,32 +183,15 @@ def create_pool(

# Only add PyPI if no default repository is configured
if not explicit_pypi:
if pool.has_default():
if pool.has_default() or pool.has_primary_repositories():
if io.is_debug():
io.write_line("Deactivating the PyPI repository")
else:
from poetry.repositories.pypi_repository import PyPiRepository

if pool.has_primary_repositories():
io.write_error_line(
"<warning>"
"Warning: In a future version of Poetry, PyPI will be disabled"
" automatically if at least one custom primary source is"
" configured. In order to avoid"
" a breaking change and make your pyproject.toml forward"
" compatible, add PyPI explicitly via 'poetry source add pypi'."
" By the way, this has the advantage that you can set the"
" priority of PyPI as with any other source."
"</warning>"
)

if pool.has_primary_repositories():
pypi_priority = Priority.SECONDARY
else:
pypi_priority = Priority.DEFAULT

pool.add_repository(
PyPiRepository(disable_cache=disable_cache), priority=pypi_priority
PyPiRepository(disable_cache=disable_cache),
priority=Priority.PRIMARY,
)

if not pool.repositories:
Expand Down
Loading

0 comments on commit 6dd8236

Please sign in to comment.