From ce732ac782fe83059e9f2d1df74371858ba3e405 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 14 Dec 2024 19:34:47 +0100 Subject: [PATCH 1/4] Replace isort with ruff check and black with ruff format --- .pre-commit-config.yaml | 12 ++++-------- docs/gen_config.py | 2 +- py/soundswallower/__init__.py | 12 +++++++----- pyproject.toml | 27 +++++++++++++++++---------- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f760ce1c..1e8680ae 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,19 +8,15 @@ repos: - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files -- repo: https://github.com/psf/black - rev: 24.8.0 +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.8.3 hooks: - - id: black + - id: ruff + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.13.0 hooks: - id: mypy -- repo: https://github.com/PyCQA/isort - rev: 5.13.2 - hooks: - - id: isort - args: [--profile=black] - repo: https://github.com/pre-commit/mirrors-clang-format rev: v19.1.5 hooks: diff --git a/docs/gen_config.py b/docs/gen_config.py index dedebafd..551809b4 100644 --- a/docs/gen_config.py +++ b/docs/gen_config.py @@ -50,7 +50,7 @@ if arg.doc is not None: arg_text += arg.doc if arg.default is not None: - if arg.type == bool: + if arg.type is bool: default = arg.default == "yes" else: default = arg.type(arg.default) diff --git a/py/soundswallower/__init__.py b/py/soundswallower/__init__.py index 51b47cf5..17c00ecb 100644 --- a/py/soundswallower/__init__.py +++ b/py/soundswallower/__init__.py @@ -21,11 +21,13 @@ import wave from typing import Optional, Tuple -from ._soundswallower import Config # noqa: F401 -from ._soundswallower import Decoder # noqa: F401 -from ._soundswallower import Endpointer # noqa: F401 -from ._soundswallower import FsgModel # noqa: F401 -from ._soundswallower import Vad # noqa: F401 +from ._soundswallower import ( # noqa: F401 + Config, + Decoder, + Endpointer, + FsgModel, + Vad, +) def get_model_path(subpath: Optional[str] = None) -> str: diff --git a/pyproject.toml b/pyproject.toml index d3da66c7..7400c58d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,12 +33,11 @@ classifiers = [ [project.optional-dependencies] dev = [ - "pytest", + "mypy==1.13.0", "numpy", "pre-commit", - "black==24.8.0", - "isort", - "mypy==1.13.0", + "pytest", + "ruff", ] [project.urls] @@ -73,13 +72,21 @@ skip = [ [tool.cibuildwheel.macos] archs = ["x86_64", "universal2", "arm64"] -[tool.isort] -known_first_party = ["soundswallower"] -profile = "black" +[tool.ruff.lint] +select = [ + "B", # flake8-bugbear + "BLE", # flake8-blind-except + "C4", # flake8-comprehensions + "C90", # mccabe code complexity + "E", # pycodestyle errors + "F", # pyflakes + "I", # isort + "PL", # pylint + "W", # pycodestyle whitespace +] -[tool.flake8] -extend-ignore = "E203" -max-line-length = "88" +[tool.ruff.lint.isort] +known-first-party = ["soundswallower"] [tool.scikit-build] metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" From 33d42f479d251383d1e8d5e23df10a6386d086e4 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 16 Dec 2024 17:51:06 +0100 Subject: [PATCH 2/4] Remove # noqa: F401 --- py/soundswallower/__init__.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/py/soundswallower/__init__.py b/py/soundswallower/__init__.py index 17c00ecb..1d52c79e 100644 --- a/py/soundswallower/__init__.py +++ b/py/soundswallower/__init__.py @@ -21,13 +21,7 @@ import wave from typing import Optional, Tuple -from ._soundswallower import ( # noqa: F401 - Config, - Decoder, - Endpointer, - FsgModel, - Vad, -) +from ._soundswallower import Config, Decoder, Endpointer, FsgModel, Vad def get_model_path(subpath: Optional[str] = None) -> str: From c4d6ae43449a1ac38a9826f175e8058bd4935878 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 16 Dec 2024 18:10:16 +0100 Subject: [PATCH 3/4] Add RUF rules --- py/soundswallower/__init__.py | 10 +++++----- pyproject.toml | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/py/soundswallower/__init__.py b/py/soundswallower/__init__.py index 1d52c79e..4944d941 100644 --- a/py/soundswallower/__init__.py +++ b/py/soundswallower/__init__.py @@ -87,14 +87,14 @@ def get_audio_data(input_file: str) -> Tuple[bytes, Optional[int]]: Hyp.prob.__doc__ = "Posterior probability of hypothesis (often 1.0, sorry)." __all__ = [ + "Arg", "Config", "Decoder", - "FsgModel", - "Vad", "Endpointer", - "Arg", - "Seg", + "FsgModel", "Hyp", - "get_model_path", + "Seg", + "Vad", "get_audio_data", + "get_model_path", ] diff --git a/pyproject.toml b/pyproject.toml index 7400c58d..8d21b0f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,6 +82,7 @@ select = [ "F", # pyflakes "I", # isort "PL", # pylint + "RUF", # Ruff-specific rules "W", # pycodestyle whitespace ] From d1aea61e35d6f1d9a7a11cade50c51f4f937e3b0 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 16 Dec 2024 18:24:50 +0100 Subject: [PATCH 4/4] Fix only isort and ruff format --- .pre-commit-config.yaml | 1 + pyproject.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1e8680ae..27791727 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,6 +12,7 @@ repos: rev: v0.8.3 hooks: - id: ruff + args: [ --fix ] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.13.0 diff --git a/pyproject.toml b/pyproject.toml index 8d21b0f6..93b43230 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,6 +85,7 @@ select = [ "RUF", # Ruff-specific rules "W", # pycodestyle whitespace ] +fixable = ["I"] [tool.ruff.lint.isort] known-first-party = ["soundswallower"]