Skip to content

Commit

Permalink
Merge branch 'python-poetry:main' into logging_integration
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-robins authored Nov 23, 2024
2 parents cca3f85 + aefc890 commit 280f693
Show file tree
Hide file tree
Showing 27 changed files with 56 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [Ubuntu, macOS, Windows]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
include:
- os: Ubuntu
image: ubuntu-22.04
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
exclude: ^(.*\.egg-info/|tests/(fixtures|ui).*)$
Expand All @@ -22,7 +22,7 @@ repos:
- id: check-docstring-first

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
rev: v0.7.2
hooks:
- id: ruff
- id: ruff-format
1 change: 1 addition & 0 deletions news/439.feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Python 3.13.
1 change: 1 addition & 0 deletions news/439.removal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dropped support for Python 3.8.
1 change: 1 addition & 0 deletions news/442.deps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed `rapidfuzz` dependency
123 changes: 4 additions & 119 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ classifiers = [
]

[tool.poetry.dependencies]
python = "^3.8"
rapidfuzz = "^3.0.0"
python = "^3.9"

[tool.poetry.group.dev.dependencies]
mypy = "^1.5"
Expand All @@ -50,7 +49,7 @@ furo = "^2023.9.10"

[tool.ruff]
fix = true
target-version = "py38"
target-version = "py39"
line-length = 88
extend-exclude = [
"docs/*",
Expand Down
15 changes: 6 additions & 9 deletions src/cleo/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import math

from dataclasses import dataclass
from difflib import SequenceMatcher
from html.parser import HTMLParser

from rapidfuzz.distance import Levenshtein


class TagStripper(HTMLParser):
def __init__(self) -> None:
Expand Down Expand Up @@ -51,12 +50,12 @@ def find_similar_names(name: str, names: list[str]) -> list[str]:
"""
Finds names similar to a given command name.
"""
threshold = 1e3
threshold = 0.4
distance_by_name = {}

if " " in name:
names = [name for name in names if " " in name]
for actual_name in names:
# Get Levenshtein distance between the input and each command name
distance = Levenshtein.distance(name, actual_name)
distance = SequenceMatcher(None, actual_name, name).ratio()

is_similar = distance <= len(name) / 3
substring_index = actual_name.find(name)
Expand All @@ -70,9 +69,7 @@ def find_similar_names(name: str, names: list[str]) -> list[str]:

# Only keep results with a distance below the threshold
distance_by_name = {
key: value
for key, value in distance_by_name.items()
if value[0] < 2 * threshold
key: value for key, value in distance_by_name.items() if value[0] > threshold
}
# Display results with shortest distance first
return sorted(distance_by_name, key=lambda key: distance_by_name[key])
Expand Down
4 changes: 2 additions & 2 deletions src/cleo/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import TYPE_CHECKING
from typing import Any
from typing import ClassVar
from typing import ContextManager
from typing import cast

from cleo.exceptions import CleoError
Expand All @@ -18,6 +17,7 @@


if TYPE_CHECKING:
from contextlib import AbstractContextManager
from typing import Literal

from cleo.application import Application
Expand Down Expand Up @@ -412,7 +412,7 @@ def spin(
fmt: str | None = None,
interval: int = 100,
values: list[str] | None = None,
) -> ContextManager[ProgressIndicator]:
) -> AbstractContextManager[ProgressIndicator]:
"""
Automatically spin a progress indicator.
"""
Expand Down
3 changes: 2 additions & 1 deletion src/cleo/descriptors/text_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from typing import TYPE_CHECKING
from typing import Any
from typing import Sequence

from cleo.commands.command import Command
from cleo.descriptors.descriptor import Descriptor
Expand All @@ -14,6 +13,8 @@


if TYPE_CHECKING:
from collections.abc import Sequence

from cleo.application import Application
from cleo.io.inputs.argument import Argument
from cleo.io.inputs.option import Option
Expand Down
3 changes: 2 additions & 1 deletion src/cleo/events/event_dispatcher.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Callable
from typing import cast


if TYPE_CHECKING:
from collections.abc import Callable

from cleo.events.event import Event

Listener = Callable[[Event, str, "EventDispatcher"], None]
Expand Down
3 changes: 2 additions & 1 deletion src/cleo/io/inputs/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

from typing import TYPE_CHECKING
from typing import Any
from typing import Sequence

from cleo.exceptions import CleoLogicError
from cleo.io.inputs.option import Option


if TYPE_CHECKING:
from collections.abc import Sequence

from cleo.io.inputs.argument import Argument


Expand Down
3 changes: 2 additions & 1 deletion src/cleo/io/io.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Iterable

from cleo.io.outputs.output import Type as OutputType
from cleo.io.outputs.output import Verbosity


if TYPE_CHECKING:
from collections.abc import Iterable

from cleo.io.inputs.input import Input
from cleo.io.outputs.output import Output
from cleo.io.outputs.section_output import SectionOutput
Expand Down
6 changes: 5 additions & 1 deletion src/cleo/io/outputs/null_output.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from __future__ import annotations

from typing import Iterable
from typing import TYPE_CHECKING

from cleo.io.outputs.output import Output
from cleo.io.outputs.output import Type
from cleo.io.outputs.output import Verbosity


if TYPE_CHECKING:
from collections.abc import Iterable


class NullOutput(Output):
@property
def verbosity(self) -> Verbosity:
Expand Down
3 changes: 2 additions & 1 deletion src/cleo/io/outputs/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

from enum import Enum
from typing import TYPE_CHECKING
from typing import Iterable

from cleo._utils import strip_tags
from cleo.formatters.formatter import Formatter


if TYPE_CHECKING:
from collections.abc import Iterable

from cleo.io.outputs.section_output import SectionOutput


Expand Down
2 changes: 1 addition & 1 deletion src/cleo/loaders/factory_command_loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Callable
from collections.abc import Callable

from cleo.commands.command import Command
from cleo.exceptions import CleoCommandNotFoundError
Expand Down
4 changes: 1 addition & 3 deletions src/cleo/ui/exception_trace/frame_collection.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import annotations

from typing import List

from cleo.ui.exception_trace.frame import Frame


class FrameCollection(List[Frame]):
class FrameCollection(list[Frame]):
def __init__(self, frames: list[Frame] | None = None, count: int = 0) -> None:
if frames is None:
frames = []
Expand Down
2 changes: 1 addition & 1 deletion src/cleo/ui/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import re
import time

from re import Match
from typing import TYPE_CHECKING
from typing import ClassVar
from typing import Match

from cleo._utils import format_time
from cleo.cursor import Cursor
Expand Down
4 changes: 2 additions & 2 deletions src/cleo/ui/progress_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@


if TYPE_CHECKING:
from typing import Iterator
from typing import Match
from collections.abc import Iterator
from re import Match

from cleo.io.outputs.output import Output

Expand Down
2 changes: 1 addition & 1 deletion src/cleo/ui/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import os
import subprocess

from collections.abc import Callable
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import Callable

from cleo.formatters.style import Style
from cleo.io.outputs.stream_output import StreamOutput
Expand Down
10 changes: 5 additions & 5 deletions src/cleo/ui/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from copy import deepcopy
from itertools import repeat
from typing import TYPE_CHECKING
from typing import Iterator
from typing import List
from typing import Union
from typing import cast

Expand All @@ -21,10 +19,12 @@


if TYPE_CHECKING:
from collections.abc import Iterator

from cleo.io.io import IO

Row = List[Union[str, TableCell]]
Rows = List[Union[Row, TableSeparator]]
Row = list[Union[str, TableCell]]
Rows = list[Union[Row, TableSeparator]]
Header = Row


Expand Down Expand Up @@ -113,7 +113,7 @@ def set_headers(self, headers: Header | list[Header]) -> Table:
headers = cast("Header", headers)
headers = [headers]

headers = cast("List[Header]", headers)
headers = cast("list[Header]", headers)

self._headers = headers

Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@


if TYPE_CHECKING:
from typing import Callable
from typing import Iterator
from collections.abc import Callable
from collections.abc import Iterator

from pytest_mock import MockerFixture

Expand Down
2 changes: 1 addition & 1 deletion tests/io/inputs/test_argv_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


if TYPE_CHECKING:
from typing import Iterator
from collections.abc import Iterator


@pytest.fixture()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_find_ambiguous_namespace(app: Application) -> None:
CleoNamespaceNotFoundError,
match=(
r'There are no commands in the "f" namespace\.\n\n'
r"Did you mean one of these\?\n foo\n foo1"
r"Did you mean this\?\n foo"
),
):
app.find_namespace("f")
Expand Down
10 changes: 4 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ def test_format_time(input_secs: float, expected: str) -> None:
@pytest.mark.parametrize(
["name", "expected"],
[
("", ["help", "foo1", "foo2", "bar1", "bar2", "foo bar1", "foo bar2"]),
("hellp", ["help"]),
("bar2", ["bar2", "bar1", "foo bar2"]),
("bar1", ["bar1", "bar2", "foo bar1"]),
("foo", ["foo1", "foo2", "foo bar1", "foo bar2"]),
("env add", ["env remove", "env activate", "env info", "env list", "env use"]),
("evn add", ["env activate", "env use"]),
("env", ["env remove", "env info", "env list", "env use"]),
],
)
def test_find_similar_names(name: str, expected: list[str]) -> None:
names = ["help", "foo1", "foo2", "bar1", "bar2", "foo bar1", "foo bar2"]
names = ["env info", "env use", "env activate", "env remove", "env list"]
assert find_similar_names(name, names) == expected


Expand Down
2 changes: 1 addition & 1 deletion tests/ui/test_progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


if TYPE_CHECKING:
from typing import Callable
from collections.abc import Callable

from cleo.io.buffered_io import BufferedIO

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/test_progress_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


if TYPE_CHECKING:
from typing import Callable
from collections.abc import Callable

from cleo.io.buffered_io import BufferedIO

Expand Down

0 comments on commit 280f693

Please sign in to comment.