Skip to content

Commit

Permalink
chore: fix cleo typing (python-poetry#9100)
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus authored Mar 3, 2024
1 parent 2478f54 commit 173391b
Show file tree
Hide file tree
Showing 32 changed files with 258 additions and 56 deletions.
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ known-first-party = ["poetry"]
known-third-party = ["poetry.core"]
required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.per-file-ignores]
"src/poetry/console/*" = ["RUF012"] # Can't annotate properly until new version of Cleo

[tool.mypy]
files = "src, tests"
Expand Down
18 changes: 15 additions & 3 deletions src/poetry/console/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import contextlib

from typing import TYPE_CHECKING
from typing import Any
from typing import ClassVar

from cleo.helpers import argument
from cleo.helpers import option
Expand All @@ -14,12 +16,19 @@
from poetry.console.commands.installer_command import InstallerCommand


if TYPE_CHECKING:
from cleo.io.inputs.argument import Argument
from cleo.io.inputs.option import Option


class AddCommand(InstallerCommand, InitCommand):
name = "add"
description = "Adds a new dependency to <comment>pyproject.toml</>."

arguments = [argument("name", "The packages to add.", multiple=True)]
options = [
arguments: ClassVar[list[Argument]] = [
argument("name", "The packages to add.", multiple=True)
]
options: ClassVar[list[Option]] = [
option(
"group",
"-G",
Expand Down Expand Up @@ -95,7 +104,10 @@ class AddCommand(InstallerCommand, InitCommand):
{examples}
"""

loggers = ["poetry.repositories.pypi_repository", "poetry.inspection.info"]
loggers: ClassVar[list[str]] = [
"poetry.repositories.pypi_repository",
"poetry.inspection.info",
]

def handle(self) -> int:
from poetry.core.constraints.version import parse_constraint
Expand Down
10 changes: 8 additions & 2 deletions src/poetry/console/commands/build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING
from typing import ClassVar

from cleo.helpers import option

Expand All @@ -9,11 +11,15 @@
from poetry.utils.helpers import remove_directory


if TYPE_CHECKING:
from cleo.io.inputs.option import Option


class BuildCommand(EnvCommand):
name = "build"
description = "Builds a package, as a tarball and a wheel by default."

options = [
options: ClassVar[list[Option]] = [
option("format", "f", "Limit the format to either sdist or wheel.", flag=False),
option(
"clean",
Expand All @@ -35,7 +41,7 @@ class BuildCommand(EnvCommand):
),
]

loggers = [
loggers: ClassVar[list[str]] = [
"poetry.core.masonry.builders.builder",
"poetry.core.masonry.builders.sdist",
"poetry.core.masonry.builders.wheel",
Expand Down
16 changes: 14 additions & 2 deletions src/poetry/console/commands/cache/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import os

from typing import TYPE_CHECKING
from typing import ClassVar

from cleo.helpers import argument
from cleo.helpers import option
from packaging.utils import canonicalize_name
Expand All @@ -11,12 +14,21 @@
from poetry.utils.cache import FileCache


if TYPE_CHECKING:
from cleo.io.inputs.argument import Argument
from cleo.io.inputs.option import Option


class CacheClearCommand(Command):
name = "cache clear"
description = "Clears a Poetry cache by name."

arguments = [argument("cache", description="The name of the cache to clear.")]
options = [option("all", description="Clear all entries in the cache.")]
arguments: ClassVar[list[Argument]] = [
argument("cache", description="The name of the cache to clear.")
]
options: ClassVar[list[Option]] = [
option("all", description="Clear all entries in the cache.")
]

def handle(self) -> int:
cache = self.argument("cache")
Expand Down
5 changes: 4 additions & 1 deletion src/poetry/console/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import TYPE_CHECKING
from typing import Any
from typing import ClassVar

from cleo.helpers import option

Expand All @@ -11,6 +12,8 @@
if TYPE_CHECKING:
from pathlib import Path

from cleo.io.inputs.option import Option


class CheckCommand(Command):
name = "check"
Expand All @@ -19,7 +22,7 @@ class CheckCommand(Command):
" consistency with the poetry.lock file."
)

options = [
options: ClassVar[list[Option]] = [
option(
"lock",
None,
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/console/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import TYPE_CHECKING
from typing import Any
from typing import ClassVar

from cleo.commands.command import Command as BaseCommand
from cleo.exceptions import CleoValueError
Expand All @@ -13,7 +14,7 @@


class Command(BaseCommand):
loggers: list[str] = []
loggers: ClassVar[list[str]] = []

_poetry: Poetry | None = None

Expand Down
10 changes: 7 additions & 3 deletions src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import ClassVar
from typing import cast

from cleo.helpers import argument
Expand All @@ -19,19 +20,22 @@


if TYPE_CHECKING:
from cleo.io.inputs.argument import Argument
from cleo.io.inputs.option import Option

from poetry.config.config_source import ConfigSource


class ConfigCommand(Command):
name = "config"
description = "Manages configuration settings."

arguments = [
arguments: ClassVar[list[Argument]] = [
argument("key", "Setting key.", optional=True),
argument("value", "Setting value.", optional=True, multiple=True),
]

options = [
options: ClassVar[list[Option]] = [
option("list", None, "List configuration settings."),
option("unset", None, "Unset configuration setting."),
option("local", None, "Set/Get from the project's local configuration."),
Expand All @@ -48,7 +52,7 @@ class ConfigCommand(Command):
<comment>poetry config --unset repo.foo</comment>"""

LIST_PROHIBITED_SETTINGS = {"http-basic", "pypi-token"}
LIST_PROHIBITED_SETTINGS: ClassVar[set[str]] = {"http-basic", "pypi-token"}

@property
def unique_config_values(self) -> dict[str, tuple[Any, Any]]:
Expand Down
12 changes: 9 additions & 3 deletions src/poetry/console/commands/debug/resolve.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import ClassVar

from cleo.helpers import argument
from cleo.helpers import option
Expand All @@ -11,17 +12,19 @@


if TYPE_CHECKING:
from cleo.io.inputs.argument import Argument
from cleo.io.inputs.option import Option
from cleo.ui.table import Rows


class DebugResolveCommand(InitCommand):
name = "debug resolve"
description = "Debugs dependency resolution."

arguments = [
arguments: ClassVar[list[Argument]] = [
argument("package", "The packages to resolve.", optional=True, multiple=True)
]
options = [
options: ClassVar[list[Option]] = [
option(
"extras",
"E",
Expand All @@ -34,7 +37,10 @@ class DebugResolveCommand(InitCommand):
option("install", None, "Show what would be installed for the current system."),
]

loggers = ["poetry.repositories.pypi_repository", "poetry.inspection.info"]
loggers: ClassVar[list[str]] = [
"poetry.repositories.pypi_repository",
"poetry.inspection.info",
]

def handle(self) -> int:
from cleo.io.null_io import NullIO
Expand Down
5 changes: 4 additions & 1 deletion src/poetry/console/commands/env/info.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import ClassVar

from cleo.helpers import option

from poetry.console.commands.command import Command


if TYPE_CHECKING:
from cleo.io.inputs.option import Option

from poetry.utils.env import Env


class EnvInfoCommand(Command):
name = "env info"
description = "Displays information about the current environment."

options = [
options: ClassVar[list[Option]] = [
option("path", "p", "Only display the environment's path."),
option(
"executable", "e", "Only display the environment's python executable path."
Expand Down
11 changes: 10 additions & 1 deletion src/poetry/console/commands/env/list.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import ClassVar

from cleo.helpers import option

from poetry.console.commands.command import Command


if TYPE_CHECKING:
from cleo.io.inputs.option import Option


class EnvListCommand(Command):
name = "env list"
description = "Lists all virtualenvs associated with the current project."

options = [option("full-path", None, "Output the full paths of the virtualenvs.")]
options: ClassVar[list[Option]] = [
option("full-path", None, "Output the full paths of the virtualenvs.")
]

def handle(self) -> int:
from poetry.utils.env import EnvManager
Expand Down
12 changes: 10 additions & 2 deletions src/poetry/console/commands/env/remove.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import ClassVar

from cleo.helpers import argument
from cleo.helpers import option

from poetry.console.commands.command import Command


if TYPE_CHECKING:
from cleo.io.inputs.argument import Argument
from cleo.io.inputs.option import Option


class EnvRemoveCommand(Command):
name = "env remove"
description = "Remove virtual environments associated with the project."

arguments = [
arguments: ClassVar[list[Argument]] = [
argument(
"python",
"The python executables associated with, or names of the virtual"
Expand All @@ -19,7 +27,7 @@ class EnvRemoveCommand(Command):
multiple=True,
)
]
options = [
options: ClassVar[list[Option]] = [
option(
"all",
description=(
Expand Down
11 changes: 10 additions & 1 deletion src/poetry/console/commands/env/use.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import ClassVar

from cleo.helpers import argument

from poetry.console.commands.command import Command


if TYPE_CHECKING:
from cleo.io.inputs.argument import Argument


class EnvUseCommand(Command):
name = "env use"
description = "Activates or creates a new virtualenv for the current project."

arguments = [argument("python", "The python executable to use.")]
arguments: ClassVar[list[Argument]] = [
argument("python", "The python executable to use.")
]

def handle(self) -> int:
from poetry.utils.env import EnvManager
Expand Down
4 changes: 3 additions & 1 deletion src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import ClassVar
from typing import Dict
from typing import Mapping
from typing import Union
Expand All @@ -17,6 +18,7 @@


if TYPE_CHECKING:
from cleo.io.inputs.option import Option
from packaging.utils import NormalizedName
from poetry.core.packages.package import Package
from tomlkit.items import InlineTable
Expand All @@ -32,7 +34,7 @@ class InitCommand(Command):
"Creates a basic <comment>pyproject.toml</> file in the current directory."
)

options = [
options: ClassVar[list[Option]] = [
option("name", None, "Name of the package.", flag=False),
option("description", None, "Description of the package.", flag=False),
option("author", None, "Author name of the package.", flag=False),
Expand Down
Loading

0 comments on commit 173391b

Please sign in to comment.