Skip to content

Commit

Permalink
Merge branch 'pr/MatthieuBizien/6612' of https://github.com/real-yfpr…
Browse files Browse the repository at this point in the history
…ojects/poetry into pr/MatthieuBizien/6612
  • Loading branch information
real-yfprojects committed Sep 3, 2023
2 parents aefbbff + 9f868fc commit 56ad263
Show file tree
Hide file tree
Showing 36 changed files with 696 additions and 368 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ repos:
- id: validate_manifest

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
rev: v0.0.282
hooks:
- id: ruff
5 changes: 3 additions & 2 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
entry: poetry check
language: python
pass_filenames: false
files: ^(.*/)?pyproject.toml$
files: ^(.*/)?pyproject\.toml$

- id: poetry-lock
name: poetry-lock
description: run poetry lock to update lock file
entry: poetry lock
language: python
pass_filenames: false
files: ^(.*/)?(poetry\.lock|pyproject\.toml)$

- id: poetry-export
name: poetry-export
description: run poetry export to sync lock file with requirements.txt
entry: poetry export
language: python
pass_filenames: false
files: ^poetry.lock$
files: ^(.*/)?poetry\.lock$
args: ["-f", "requirements.txt", "-o", "requirements.txt"]
5 changes: 5 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ 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.

### Is Nox supported?

Use the [`nox-poetry`](https://github.com/cjolowicz/nox-poetry) package to install locked versions of
dependencies specified in `poetry.lock` into [Nox](https://nox.thea.codes/en/stable/) sessions.

### I don't want Poetry to manage my virtual environments. Can I disable it?

While Poetry automatically creates virtual environments to always work isolated
Expand Down
30 changes: 21 additions & 9 deletions docs/pre-commit-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ the defaults are overwritten. You must fully specify all arguments for
your hook if you make use of `args:`.
{{% /note %}}

{{% note %}}
If the `pyproject.toml` file is not in the root directory, you can specify `args: ["-C", "./subdirectory"]`.
{{% /note %}}

## poetry-check

The `poetry-check` hook calls the `poetry check` command
Expand All @@ -34,10 +38,6 @@ to make sure the poetry configuration does not get committed in a broken state.
The hook takes the same arguments as the poetry command.
For more information see the [check command]({{< relref "cli#check" >}}).

{{% note %}}
If the `pyproject.toml` file is not in the root directory, you can specify `args: ["-C", "./subdirectory"]`.
{{% /note %}}

## poetry-lock

The `poetry-lock` hook calls the `poetry lock` command
Expand All @@ -48,7 +48,6 @@ to make sure the lock file is up-to-date when committing changes.
The hook takes the same arguments as the poetry command.
For more information see the [lock command]({{< relref "cli#lock" >}}).


## poetry-export

The `poetry-export` hook calls the `poetry export` command
Expand All @@ -64,7 +63,7 @@ The hook takes the same arguments as the poetry command.
For more information see the [export command]({{< relref "cli#export" >}}).

The default arguments are `args: ["-f", "requirements.txt", "-o", "requirements.txt"]`,
which will create/update the requirements.txt file in the current working directory.
which will create/update the `requirements.txt` file in the current working directory.

You may add `verbose: true` in your `.pre-commit-config.yaml` in order to output to the
console:
Expand All @@ -84,22 +83,35 @@ hooks:
args: ["--dev", "-f", "requirements.txt", "-o", "requirements.txt"]
```


## Usage

For more information on how to use pre-commit please see the [official documentation](https://pre-commit.com/).

A full `.pre-commit-config.yaml` example:
A minimalistic `.pre-commit-config.yaml` example:

```yaml
repos:
- repo: https://github.com/python-poetry/poetry
rev: '' # add version here
hooks:
- id: poetry-check
- id: poetry-lock
- id: poetry-export
```

A `.pre-commit-config.yaml` example for a monorepo setup or if the `pyproject.toml` file is not in the root directory:

```yaml
repos:
- repo: https://github.com/python-poetry/poetry
rev: '' # add version here
hooks:
- id: poetry-check
args: ["-C", "./subdirectory"]
- id: poetry-lock
args: ["-C", "./subdirectory"]
- id: poetry-export
args: ["-f", "requirements.txt", "-o", "requirements.txt"]
args: ["-C", "./subdirectory", "-f", "requirements.txt", "-o", "./subdirectory/requirements.txt"]
```

## FAQ
Expand Down
2 changes: 1 addition & 1 deletion docs/pyproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ To specify a script that [depends on an extra](#extras), you may provide an entr

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

{{% note %}}
Expand Down
12 changes: 12 additions & 0 deletions docs/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ poetry source add --priority=primary PyPI

This way, the priority of PyPI can be set in a fine-granular way.

The equivalent specification in `pyproject.toml` is:

```toml
[[tool.poetry.source]]
name = "pypi"
priority = "primary"
```

**Omit the `url` when specifying PyPI explicitly.** Because PyPI is internally configured
with Poetry, the PyPI repository cannot be configured with a given URL. Remember, you can always use
`poetry check` to ensure the validity of the `pyproject.toml` file.

{{% /warning %}}

{{% warning %}}
Expand Down
70 changes: 35 additions & 35 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ importlib-metadata = { version = ">=4.4", python = "<3.10" }
installer = "^0.7.0"
# jsonschema 4.18 uses Rust-based libraries which causes issues when building from source
jsonschema = ">=4.10.0,<4.18.0"
keyring = "^23.9.0"
keyring = "^24.0.0"
# packaging uses calver, so version is unclamped
packaging = ">=20.4"
pexpect = "^4.7.0"
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/group_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def project_with_activated_groups_only(self) -> ProjectPackage:

def _validate_group_options(self, group_options: dict[str, set[str]]) -> None:
"""
Raises en error if it detects that a group is not part of pyproject.toml
Raises an error if it detects that a group is not part of pyproject.toml
"""
invalid_options = defaultdict(set)
for opt, groups in group_options.items():
Expand Down
4 changes: 1 addition & 3 deletions src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ def _display_packages_information(
name = locked.pretty_name
install_marker = ""

if show_top_level and not any(
locked.is_same_package_as(r) for r in requires
):
if show_top_level and not any(locked.satisfies(r) for r in requires):
continue

if locked not in required_locked_packages:
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from cleo.io.null_io import NullIO
from poetry.core.packages.utils.link import Link
from requests.utils import atomic_open

from poetry.installation.chef import Chef
from poetry.installation.chef import ChefBuildError
Expand All @@ -29,7 +30,6 @@
from poetry.utils.authenticator import Authenticator
from poetry.utils.cache import ArtifactCache
from poetry.utils.env import EnvCommandError
from poetry.utils.helpers import atomic_open
from poetry.utils.helpers import get_file_hash
from poetry.utils.helpers import pluralize
from poetry.utils.helpers import remove_directory
Expand Down
5 changes: 1 addition & 4 deletions src/poetry/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ def validate_object(obj: dict[str, Any]) -> list[str]:
schema = json.loads(schema_file.read_text(encoding="utf-8"))

validator = jsonschema.Draft7Validator(schema)
validation_errors = sorted(
validator.iter_errors(obj),
key=lambda e: e.path, # type: ignore[no-any-return]
)
validation_errors = sorted(validator.iter_errors(obj), key=lambda e: e.path)

errors = []

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/layouts/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def get_package_include(self) -> InlineTable | None:
if self.basedir != Path():
package.append("from", self.basedir.as_posix())
else:
if include == self._project:
if module_name(self._project) == include:
# package include and package name are the same,
# packages table is redundant here.
return None
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/masonry/builders/editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import csv
import hashlib
import json
import locale
import os

from base64 import urlsafe_b64encode
Expand Down Expand Up @@ -126,7 +127,7 @@ def _add_pth(self) -> list[Path]:

try:
pth_file = self._env.site_packages.write_text(
pth_file, content, encoding="utf-8"
pth_file, content, encoding=locale.getpreferredencoding()
)
self._debug(
f" - Adding <c2>{pth_file.name}</c2> to <b>{pth_file.parent}</b> for"
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/mixology/incompatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def __str__(self) -> str:
if len(positive) != 1:
return f"if {' and '.join(positive)} then {' or '.join(negative)}"

positive_term = [term for term in self._terms if term.is_positive()][0]
positive_term = next(term for term in self._terms if term.is_positive())
return (
f"{self._terse(positive_term, allow_every=True)} requires"
f" {' or '.join(negative)}"
Expand Down
5 changes: 1 addition & 4 deletions src/poetry/mixology/version_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,7 @@ def _get_min(dependency: Dependency) -> tuple[bool, int, int]:
preference = Preference.DEFAULT
return is_specific_marker, preference, num_packages

if len(unsatisfied) == 1:
dependency = unsatisfied[0]
else:
dependency = min(*unsatisfied, key=_get_min)
dependency = min(unsatisfied, key=_get_min)

locked = self._provider.get_locked(dependency)
if locked is None:
Expand Down
5 changes: 1 addition & 4 deletions src/poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,7 @@ def _dump_package(self, package: Package) -> dict[str, Any]:
"description": package.description or "",
"optional": package.optional,
"python-versions": package.python_versions,
"files": sorted(
package.files,
key=lambda x: x["file"], # type: ignore[no-any-return]
),
"files": sorted(package.files, key=lambda x: x["file"]),
}

if dependencies:
Expand Down
Loading

0 comments on commit 56ad263

Please sign in to comment.