Commit c71deb4b by pre-commit-ci[bot] Committed by GitHub

[pre-commit.ci] pre-commit autoupdate (#8136)

Co-authored-by: Bartek Sokorski <b.sokorski@gmail.com>
parent fd717ca1
......@@ -21,7 +21,7 @@ repos:
- id: check-docstring-first
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
......@@ -30,7 +30,7 @@ repos:
hooks:
- id: validate_manifest
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.272
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
hooks:
- id: ruff
......@@ -135,6 +135,9 @@ known-first-party = ["poetry"]
known-third-party = ["poetry.core"]
required-imports = ["from __future__ import annotations"]
[tool.ruff.per-file-ignores]
"src/poetry/console/*" = ["RUF012"] # Can't annotate properly until new version of Cleo
[tool.black]
target-version = ['py38']
preview = true
......
......@@ -9,6 +9,7 @@ from copy import deepcopy
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import ClassVar
from packaging.utils import canonicalize_name
......@@ -104,7 +105,7 @@ _default_config: Config | None = None
class Config:
default_config: dict[str, Any] = {
default_config: ClassVar[dict[str, Any]] = {
"cache-dir": str(DEFAULT_CACHE_DIR),
"virtualenvs": {
"create": True,
......
......@@ -21,11 +21,9 @@ class Source:
self.priority = Priority[self.priority.upper()]
if default or secondary:
warnings.warn(
(
"Parameters 'default' and 'secondary' to"
" 'Source' are deprecated. Please provide"
" 'priority' instead."
),
"Parameters 'default' and 'secondary' to"
" 'Source' are deprecated. Please provide"
" 'priority' instead.",
DeprecationWarning,
stacklevel=2,
)
......
......@@ -30,10 +30,8 @@ class AddCommand(InstallerCommand, InitCommand):
option(
"dev",
"D",
(
"Add as a development dependency. (<warning>Deprecated</warning>) Use"
" --group=dev instead."
),
"Add as a development dependency. (<warning>Deprecated</warning>) Use"
" --group=dev instead.",
),
option("editable", "e", "Add vcs/path dependencies as editable."),
option(
......@@ -66,10 +64,8 @@ class AddCommand(InstallerCommand, InitCommand):
option(
"dry-run",
None,
(
"Output the operations but do not execute anything (implicitly enables"
" --verbose)."
),
"Output the operations but do not execute anything (implicitly enables"
" --verbose).",
),
option("lock", None, "Do not perform operations (only update the lockfile)."),
]
......
......@@ -22,10 +22,8 @@ class CheckCommand(Command):
option(
"lock",
None,
(
"Checks that <comment>poetry.lock</> exists for the current"
" version of <comment>pyproject.toml</>."
),
"Checks that <comment>poetry.lock</> exists for the current"
" version of <comment>pyproject.toml</>.",
),
]
......
......@@ -13,10 +13,8 @@ class EnvRemoveCommand(Command):
arguments = [
argument(
"python",
(
"The python executables associated with, or names of the virtual"
" environments which are to be removed."
),
"The python executables associated with, or names of the virtual"
" environments which are to be removed.",
optional=True,
multiple=True,
)
......
......@@ -40,20 +40,16 @@ class InitCommand(Command):
option(
"dependency",
None,
(
"Package to require, with an optional version constraint, "
"e.g. requests:^2.10.0 or requests=2.11.1."
),
"Package to require, with an optional version constraint, "
"e.g. requests:^2.10.0 or requests=2.11.1.",
flag=False,
multiple=True,
),
option(
"dev-dependency",
None,
(
"Package to require for development, with an optional version"
" constraint, e.g. requests:^2.10.0 or requests=2.11.1."
),
"Package to require for development, with an optional version"
" constraint, e.g. requests:^2.10.0 or requests=2.11.1.",
flag=False,
multiple=True,
),
......@@ -330,10 +326,8 @@ You can specify a package in the following forms:
choices.append("")
package = self.choice(
(
"\nEnter package # to add, or the complete package name if"
" it is not listed"
),
"\nEnter package # to add, or the complete package name if"
" it is not listed",
choices,
attempts=3,
default=len(choices) - 1,
......
......@@ -14,18 +14,14 @@ class InstallCommand(InstallerCommand):
option(
"no-dev",
None,
(
"Do not install the development dependencies."
" (<warning>Deprecated</warning>)"
),
"Do not install the development dependencies."
" (<warning>Deprecated</warning>)",
),
option(
"sync",
None,
(
"Synchronize the environment with the locked packages and the specified"
" groups."
),
"Synchronize the environment with the locked packages and the specified"
" groups.",
),
option(
"no-root", None, "Do not install the root package (the current project)."
......@@ -33,28 +29,22 @@ class InstallCommand(InstallerCommand):
option(
"no-directory",
None,
(
"Do not install any directory path dependencies; useful to install"
" dependencies without source code, e.g. for caching of Docker layers)"
),
"Do not install any directory path dependencies; useful to install"
" dependencies without source code, e.g. for caching of Docker layers)",
flag=True,
multiple=False,
),
option(
"dry-run",
None,
(
"Output the operations but do not execute anything "
"(implicitly enables --verbose)."
),
"Output the operations but do not execute anything "
"(implicitly enables --verbose).",
),
option(
"remove-untracked",
None,
(
"Removes packages not present in the lock file."
" (<warning>Deprecated</warning>)"
),
"Removes packages not present in the lock file."
" (<warning>Deprecated</warning>)",
),
option(
"extras",
......@@ -68,11 +58,9 @@ class InstallCommand(InstallerCommand):
option(
"compile",
None,
(
"Compile Python source files to bytecode."
" (This option has no effect if modern-installation is disabled"
" because the old installer always compiles.)"
),
"Compile Python source files to bytecode."
" (This option has no effect if modern-installation is disabled"
" because the old installer always compiles.)",
),
]
......
......@@ -16,11 +16,9 @@ class LockCommand(InstallerCommand):
option(
"check",
None,
(
"Check that the <comment>poetry.lock</> file corresponds to the current"
" version of <comment>pyproject.toml</>. (<warning>Deprecated</>) Use"
" <comment>poetry check --lock</> instead."
),
"Check that the <comment>poetry.lock</> file corresponds to the current"
" version of <comment>pyproject.toml</>. (<warning>Deprecated</>) Use"
" <comment>poetry check --lock</> instead.",
),
]
......
......@@ -21,19 +21,15 @@ class RemoveCommand(InstallerCommand):
option(
"dev",
"D",
(
"Remove a package from the development dependencies."
" (<warning>Deprecated</warning>)"
" Use --group=dev instead."
),
"Remove a package from the development dependencies."
" (<warning>Deprecated</warning>)"
" Use --group=dev instead.",
),
option(
"dry-run",
None,
(
"Output the operations but do not execute anything "
"(implicitly enables --verbose)."
),
"Output the operations but do not execute anything "
"(implicitly enables --verbose).",
),
option("lock", None, "Do not perform operations (only update the lockfile)."),
]
......
......@@ -23,10 +23,8 @@ class SelfUpdateCommand(SelfCommand):
option(
"dry-run",
None,
(
"Output the operations but do not execute anything "
"(implicitly enables --verbose)."
),
"Output the operations but do not execute anything "
"(implicitly enables --verbose).",
),
]
help = """\
......
......@@ -48,10 +48,8 @@ class ShowCommand(GroupCommand, EnvCommand):
option(
"why",
None,
(
"When showing the full list, or a <info>--tree</info> for a single"
" package, also display why it's included."
),
"When showing the full list, or a <info>--tree</info> for a single"
" package, also display why it's included.",
),
option("latest", "l", "Show the latest version."),
option(
......
......@@ -21,10 +21,8 @@ class SourceAddCommand(Command):
),
argument(
"url",
(
"Source repository URL."
" Required, except for PyPI, for which it is not allowed."
),
"Source repository URL."
" Required, except for PyPI, for which it is not allowed.",
optional=True,
),
]
......@@ -33,28 +31,22 @@ class SourceAddCommand(Command):
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)"
),
"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)"
),
"Set this source as secondary. (<warning>Deprecated</warning>, use"
" --priority)",
),
option(
"priority",
"p",
(
"Set the priority of this source. One of:"
f" {', '.join(p.name.lower() for p in Priority)}. Defaults to"
f" {Priority.PRIMARY.name.lower()}."
),
"Set the priority of this source. One of:"
f" {', '.join(p.name.lower() for p in Priority)}. Defaults to"
f" {Priority.PRIMARY.name.lower()}.",
flag=False,
),
]
......
......@@ -20,18 +20,14 @@ class UpdateCommand(InstallerCommand):
option(
"no-dev",
None,
(
"Do not update the development dependencies."
" (<warning>Deprecated</warning>)"
),
"Do not update the development dependencies."
" (<warning>Deprecated</warning>)",
),
option(
"dry-run",
None,
(
"Output the operations but do not execute anything "
"(implicitly enables --verbose)."
),
"Output the operations but do not execute anything "
"(implicitly enables --verbose).",
),
option("lock", None, "Do not perform operations (only update the lockfile)."),
]
......
......@@ -48,10 +48,8 @@ class Chooser:
if link.is_wheel:
if not self._no_binary_policy.allows(package.name):
logger.debug(
(
"Skipping wheel for %s as requested in no binary policy for"
" package (%s)"
),
"Skipping wheel for %s as requested in no binary policy for"
" package (%s)",
link.filename,
package.name,
)
......@@ -59,10 +57,8 @@ class Chooser:
if not Wheel(link.filename).is_supported_by_environment(self._env):
logger.debug(
(
"Skipping wheel %s as this is not supported by the current"
" environment"
),
"Skipping wheel %s as this is not supported by the current"
" environment",
link.filename,
)
continue
......
......@@ -370,12 +370,10 @@ class Executor:
if self.supports_fancy_output():
self._write(
operation,
(
f" <fg=default;options=bold,dark>•</> {operation_message}: "
"<fg=default;options=bold,dark>Skipped</> "
"<fg=default;options=dark>for the following reason:</> "
f"<fg=default;options=bold,dark>{operation.skip_reason}</>"
),
f" <fg=default;options=bold,dark>•</> {operation_message}: "
"<fg=default;options=bold,dark>Skipped</> "
"<fg=default;options=dark>for the following reason:</> "
f"<fg=default;options=bold,dark>{operation.skip_reason}</>",
)
self._skipped[operation.job_type] += 1
......
......@@ -35,12 +35,10 @@ if sys.platform == "darwin":
if any(file.exists() for file in (auth_toml, config_toml)):
logger.warning(
(
"Configuration file exists at %s, reusing this"
" directory.\n\nConsider moving TOML configuration files to %s, as"
" support for the legacy directory will be removed in an upcoming"
" release."
),
"Configuration file exists at %s, reusing this"
" directory.\n\nConsider moving TOML configuration files to %s, as"
" support for the legacy directory will be removed in an upcoming"
" release.",
_LEGACY_CONFIG_DIR,
CONFIG_DIR,
)
......
......@@ -144,10 +144,8 @@ class _Writer:
self._visit(without_line)
self._write(
incompatibility,
(
f"{conjunction} because {with_line!s} ({line}),"
f" {incompatibility_string}."
),
f"{conjunction} because {with_line!s} ({line}),"
f" {incompatibility_string}.",
numbered=numbered,
)
else:
......@@ -172,11 +170,9 @@ class _Writer:
self._write(
incompatibility,
(
f"{conjunction} because {cause.conflict!s}"
f" ({self._line_numbers[cause.conflict]}),"
f" {incompatibility_string}"
),
f"{conjunction} because {cause.conflict!s}"
f" ({self._line_numbers[cause.conflict]}),"
f" {incompatibility_string}",
numbered=numbered,
)
elif isinstance(cause.conflict.cause, ConflictCause) or isinstance(
......
......@@ -19,10 +19,8 @@ class PythonRequirementSolutionProvider(HasSolutionsForException):
return False
m = re.match(
(
"^The current project's Python requirement (.+) is not compatible "
"with some of the required packages Python requirement"
),
"^The current project's Python requirement (.+) is not compatible "
"with some of the required packages Python requirement",
str(exception),
)
......
......@@ -9,6 +9,7 @@ from hashlib import sha256
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import ClassVar
from typing import cast
from packaging.utils import canonicalize_name
......@@ -50,8 +51,13 @@ class Locker:
_VERSION = "2.0"
_READ_VERSION_RANGE = ">=1,<3"
_legacy_keys = ["dependencies", "source", "extras", "dev-dependencies"]
_relevant_keys = [*_legacy_keys, "group"]
_legacy_keys: ClassVar[list[str]] = [
"dependencies",
"source",
"extras",
"dev-dependencies",
]
_relevant_keys: ClassVar[list[str]] = [*_legacy_keys, "group"]
def __init__(self, lock: Path, local_config: dict[str, Any]) -> None:
self._lock = lock
......
......@@ -7,6 +7,7 @@ import time
from collections import defaultdict
from contextlib import contextmanager
from typing import TYPE_CHECKING
from typing import ClassVar
from typing import cast
from cleo.ui.progress_indicator import ProgressIndicator
......@@ -93,7 +94,7 @@ class Indicator(ProgressIndicator):
class Provider:
UNSAFE_PACKAGES: set[str] = set()
UNSAFE_PACKAGES: ClassVar[set[str]] = set()
def __init__(
self,
......
......@@ -258,11 +258,9 @@ class InstalledRepository(Repository):
name = distribution.metadata.get("name") # type: ignore[attr-defined]
if name is None:
logger.warning(
(
"Project environment contains an invalid distribution"
" (<c1>%s</>). Consider removing it manually or recreate"
" the environment."
),
"Project environment contains an invalid distribution"
" (<c1>%s</>). Consider removing it manually or recreate"
" the environment.",
path,
)
skipped.add(path)
......
......@@ -5,6 +5,7 @@ import re
from functools import cached_property
from typing import TYPE_CHECKING
from typing import ClassVar
from typing import DefaultDict
from typing import List
......@@ -31,7 +32,7 @@ logger = logging.getLogger(__name__)
class LinkSource:
VERSION_REGEX = re.compile(r"(?i)([a-z0-9_\-.]+?)-(?=\d)([a-z0-9_.!+-]+)")
CLEAN_REGEX = re.compile(r"[^a-z0-9$&+,/:;=?@.#%_\\|-]", re.I)
SUPPORTED_FORMATS = [
SUPPORTED_FORMATS: ClassVar[list[str]] = [
".tar.gz",
".whl",
".zip",
......
......@@ -62,10 +62,8 @@ class PyPiRepository(HTTPRepository):
results.append(package)
except InvalidVersion:
self._log(
(
f'Unable to parse version "{result.version}" for the'
f" {result.name} package, skipping"
),
f'Unable to parse version "{result.version}" for the'
f" {result.name} package, skipping",
level="debug",
)
......
......@@ -135,11 +135,9 @@ class RepositoryPool(AbstractRepository):
if default or secondary:
warnings.warn(
(
"Parameters 'default' and 'secondary' to"
" 'RepositoryPool.add_repository' are deprecated. Please provide"
" the keyword-argument 'priority' instead."
),
"Parameters 'default' and 'secondary' to"
" 'RepositoryPool.add_repository' are deprecated. Please provide"
" the keyword-argument 'priority' instead.",
DeprecationWarning,
stacklevel=2,
)
......
......@@ -38,11 +38,9 @@ class TOMLFile(BaseTOMLFile):
def __getattr__(self, item: str) -> Any:
warnings.warn(
(
"`__getattr__` will be removed from the `TOMLFile` in a future release."
"\n\nInstead of accessing properties of the underlying `Path` as "
"`tomlfile.whatever`, prefer `tomlfile.path.whatever`."
),
"`__getattr__` will be removed from the `TOMLFile` in a future release."
"\n\nInstead of accessing properties of the underlying `Path` as "
"`tomlfile.whatever`, prefer `tomlfile.path.whatever`.",
DeprecationWarning,
stacklevel=2,
)
......
......@@ -78,10 +78,8 @@ class EnvManager:
def _detect_active_python(io: None | IO = None) -> Path | None:
io = io or NullIO()
io.write_error_line(
(
"Trying to detect current active python executable as specified in"
" the config."
),
"Trying to detect current active python executable as specified in"
" the config.",
verbosity=Verbosity.VERBOSE,
)
......@@ -91,10 +89,8 @@ class EnvManager:
io.write_error_line(f"Found: {executable}", verbosity=Verbosity.VERBOSE)
else:
io.write_error_line(
(
"Unable to detect the current active python executable. Falling"
" back to default."
),
"Unable to detect the current active python executable. Falling"
" back to default.",
verbosity=Verbosity.VERBOSE,
)
......
......@@ -5,6 +5,7 @@ import ast
from configparser import ConfigParser
from typing import TYPE_CHECKING
from typing import Any
from typing import ClassVar
from poetry.core.constraints.version import Version
......@@ -18,7 +19,7 @@ class SetupReader:
Class that reads a setup.py file without executing it.
"""
DEFAULT: dict[str, Any] = {
DEFAULT: ClassVar[dict[str, Any]] = {
"name": None,
"version": None,
"install_requires": [],
......@@ -26,7 +27,7 @@ class SetupReader:
"python_requires": None,
}
FILES = ["setup.py", "setup.cfg"]
FILES: ClassVar[list[str]] = ["setup.py", "setup.cfg"]
@classmethod
def read_from_directory(cls, directory: Path) -> dict[str, Any]:
......
......@@ -296,10 +296,8 @@ class Git:
if isinstance(e, KeyError):
# the local copy is at a bad state, lets remove it
logger.debug(
(
"Removing local clone (<c1>%s</>) of repository as it is in a"
" broken state."
),
"Removing local clone (<c1>%s</>) of repository as it is in a"
" broken state.",
local.path,
)
remove_directory(Path(local.path), force=True)
......@@ -308,11 +306,9 @@ class Git:
raise
logger.debug(
(
"\nRequested ref (<c2>%s</c2>) was not fetched to local copy and"
" cannot be used. The following error was"
" raised:\n\n\t<warning>%s</>"
),
"\nRequested ref (<c2>%s</c2>) was not fetched to local copy and"
" cannot be used. The following error was"
" raised:\n\n\t<warning>%s</>",
refspec.key,
e,
)
......@@ -447,10 +443,8 @@ class Git:
# without additional configuration or changes for existing projects that
# use http basic auth credentials.
logger.debug(
(
"Unable to fetch from private repository '%s', falling back to"
" system git"
),
"Unable to fetch from private repository '%s', falling back to"
" system git",
url,
)
......
......@@ -848,15 +848,13 @@ def test_predefined_all_options(tester: CommandTester, repo: TestRepository) ->
]
tester.execute(
(
"--name my-package "
"--description 'This is a description' "
"--author 'Foo Bar <foo@example.com>' "
"--python '^3.8' "
"--license MIT "
"--dependency pendulum "
"--dev-dependency pytest"
),
"--name my-package "
"--description 'This is a description' "
"--author 'Foo Bar <foo@example.com>' "
"--python '^3.8' "
"--license MIT "
"--dependency pendulum "
"--dev-dependency pytest",
inputs="\n".join(inputs),
)
......@@ -947,12 +945,10 @@ line-length = 88
repo.add_package(get_package("foo", "1.19.2"))
tester.execute(
(
"--author 'Your Name <you@example.com>' "
"--name 'my-package' "
"--python '^3.6' "
"--dependency foo"
),
"--author 'Your Name <you@example.com>' "
"--name 'my-package' "
"--python '^3.6' "
"--dependency foo",
interactive=False,
)
......
......@@ -3,6 +3,7 @@ from __future__ import annotations
import re
from typing import TYPE_CHECKING
from typing import ClassVar
import pytest
......@@ -32,7 +33,7 @@ class FooCommand(Command):
class AddCommandPlugin(ApplicationPlugin):
commands = [FooCommand]
commands: ClassVar[list[type[Command]]] = [FooCommand]
@pytest.fixture
......
......@@ -2,6 +2,7 @@ from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING
from typing import ClassVar
from typing import Protocol
import pytest
......@@ -22,6 +23,7 @@ if TYPE_CHECKING:
from cleo.io.io import IO
from pytest_mock import MockerFixture
from poetry.console.commands.command import Command
from tests.conftest import Config
from tests.types import FixtureDirGetter
......@@ -38,7 +40,7 @@ class MyPlugin(Plugin):
class MyCommandPlugin(ApplicationPlugin):
commands = []
commands: ClassVar[list[type[Command]]] = []
class InvalidPlugin:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment