Skip to content

Commit

Permalink
Merge pull request #26 from sisp/ruff
Browse files Browse the repository at this point in the history
Use Ruff instead of Black/isort/Flake8
  • Loading branch information
timofurrer committed Mar 25, 2024
2 parents f15f150 + c32092f commit b8f7e01
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
- run: pip install -U pip poetry
- run: poetry config virtualenvs.create false
- run: poetry install
- run: flake8 --max-line-length 88 src/ tests/
- run: black --diff --check src/ tests/
- run: ruff check src/ tests/
- run: ruff format --diff --check src/ tests/
- run: mypy src/ tests/
- run: pytest

Expand Down
8 changes: 4 additions & 4 deletions examples/naval.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def ship_new(name):
@click.option("--speed", metavar="KN", default=10, help="Speed in knots.")
def ship_move(ship, x, y, speed):
"""Moves SHIP to the new location X,Y."""
click.echo("Moving ship %s to %s,%s with speed %s" % (ship, x, y, speed))
click.echo(f"Moving ship {ship} to {x},{y} with speed {speed}")


@ship.command("shoot")
Expand All @@ -40,7 +40,7 @@ def ship_move(ship, x, y, speed):
@click.argument("y", type=float)
def ship_shoot(ship, x, y):
"""Makes SHIP fire to X,Y."""
click.echo("Ship %s fires to %s,%s" % (ship, x, y))
click.echo(f"Ship {ship} fires to {x},{y}")


@cli.group("mine", cls=DYMGroup)
Expand All @@ -61,15 +61,15 @@ def mine():
@click.option("ty", "--drifting", flag_value="drifting", help="Drifting mine.")
def mine_set(x, y, ty):
"""Sets a mine at a specific coordinate."""
click.echo("Set %s mine at %s,%s" % (ty, x, y))
click.echo(f"Set {ty} mine at {x},{y}")


@mine.command("remove")
@click.argument("x", type=float)
@click.argument("y", type=float)
def mine_remove(x, y):
"""Removes a mine at a specific coordinate."""
click.echo("Removed mine at %s,%s" % (x, y))
click.echo(f"Removed mine at {x},{y}")


if __name__ == "__main__":
Expand Down
19 changes: 16 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,23 @@ click = ">=7"

[tool.poetry.dev-dependencies]
pytest = "^6.2.5"
black = "^24.3.0"
isort = "^5.9.3"
flake8 = {version = "^7.0.0", python = ">=3.8.1"}
mypy = "^0.910"
ruff = "0.3.4"

[tool.ruff]
src = ["src"]
target-version = "py38"

[tool.ruff.lint]
select = ["ALL"]
ignore = ["ANN101", "COM812", "D", "FA", "ISC001"]

[tool.ruff.lint.flake8-type-checking]
strict = true

[tool.ruff.lint.per-file-ignores]
"examples/**" = ["ANN", "D", "INP001"]
"tests/**" = ["ANN", "D", "INP001", "S101"]

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
10 changes: 5 additions & 5 deletions src/click_didyoumean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class DYMMixin:
a certain command is not registered.
"""

def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: # noqa: ANN401
self.max_suggestions = kwargs.pop("max_suggestions", 3)
self.cutoff = kwargs.pop("cutoff", 0.5)
super().__init__(*args, **kwargs) # type: ignore
super().__init__(*args, **kwargs) # type: ignore[call-arg]

def resolve_command(
self, ctx: click.Context, args: typing.List[str]
Expand All @@ -32,13 +32,13 @@ def resolve_command(
to the raised exception message.
"""
try:
return super(DYMMixin, self).resolve_command(ctx, args) # type: ignore
return super().resolve_command(ctx, args) # type: ignore[misc]
except click.exceptions.UsageError as error:
error_msg = str(error)
original_cmd_name = click.utils.make_str(args[0])
matches = difflib.get_close_matches(
original_cmd_name,
self.list_commands(ctx), # type: ignore
self.list_commands(ctx), # type: ignore[attr-defined]
self.max_suggestions,
self.cutoff,
)
Expand All @@ -47,7 +47,7 @@ def resolve_command(
error_msg += "\n\n"
error_msg += f"Did you mean one of these?\n {fmt_matches}"

raise click.exceptions.UsageError(error_msg, error.ctx)
raise click.exceptions.UsageError(error_msg, error.ctx) from error


class DYMGroup(DYMMixin, click.Group):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from click_didyoumean import DYMCommandCollection, DYMGroup


@pytest.fixture(scope="function")
def runner(request):
@pytest.fixture()
def runner():
return CliRunner()


Expand Down

0 comments on commit b8f7e01

Please sign in to comment.