From 867fb6179b6187d66e6a9cc1a5801e94d4167423 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 12 Apr 2023 12:20:16 +0200 Subject: [PATCH] use ruff --- .gitignore | 1 + .pre-commit-config.yaml | 47 +- docs/Usage/distance/img/jaro.svg | 1630 ++++++++++----------- docs/Usage/distance/img/jaro_winkler.svg | 1682 +++++++++++----------- pyproject.toml | 65 +- setup.cfg | 6 - tests/distance/test_init.py | 14 +- 7 files changed, 1728 insertions(+), 1717 deletions(-) delete mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index afbda6f..499a733 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ test.py src/*.html .coverage coverage.xml +sde/ # Sphinx documentation site/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1646ded..0d6b77e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,19 +30,6 @@ repos: - id: requirements-txt-fixer - id: trailing-whitespace -# Upgrade old Python syntax -- repo: https://github.com/asottile/pyupgrade - rev: "v3.3.1" - hooks: - - id: pyupgrade - args: [--py37-plus] - -# Nicely sort includes -- repo: https://github.com/PyCQA/isort - rev: "5.12.0" - hooks: - - id: isort - # Black, the code formatter, natively supports pre-commit - repo: https://github.com/psf/black rev: "23.3.0" # Keep in sync with blacken-docs @@ -69,41 +56,15 @@ repos: - id: fix-ligatures - id: fix-smartquotes -# Autoremoves unused imports -- repo: https://github.com/hadialqattan/pycln - rev: "v2.1.3" - hooks: - - id: pycln - stages: [manual] # Checking for common mistakes - repo: https://github.com/pre-commit/pygrep-hooks rev: "v1.10.0" hooks: - - id: python-check-blanket-noqa - - id: python-check-blanket-type-ignore - - id: python-no-log-warn - - id: python-use-type-annotations - id: rst-backticks - id: rst-directive-colons - id: rst-inline-touching-normal -# Automatically remove noqa that are not used -- repo: https://github.com/asottile/yesqa - rev: "v1.4.0" - hooks: - - id: yesqa - additional_dependencies: &flake8_dependencies - - flake8-bugbear - - pep8-naming - -# Flake8 also supports pre-commit natively (same author) -- repo: https://github.com/PyCQA/flake8 - rev: "6.0.0" - hooks: - - id: flake8 - exclude: ^(docs/.*|tools/.*)$ - additional_dependencies: *flake8_dependencies # PyLint has native support - not always usable, but works for us - repo: https://github.com/PyCQA/pylint @@ -139,9 +100,13 @@ repos: stages: [manual] additional_dependencies: [cmake, ninja] +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.261 + hooks: + - id: ruff + args: ["--fix", "--show-fixes"] + # Check for spelling -# Use tools/codespell_ignore_lines_from_errors.py -# to rebuild .codespell-ignore-lines - repo: https://github.com/codespell-project/codespell rev: "v2.2.4" hooks: diff --git a/docs/Usage/distance/img/jaro.svg b/docs/Usage/distance/img/jaro.svg index 72fd1e8..835b706 100644 --- a/docs/Usage/distance/img/jaro.svg +++ b/docs/Usage/distance/img/jaro.svg @@ -21,33 +21,33 @@ - - - - @@ -58,25 +58,25 @@ L 0 3.5 - @@ -86,8 +86,8 @@ z - @@ -99,53 +99,53 @@ L 143.653012 41.472 - - @@ -156,8 +156,8 @@ z - @@ -169,81 +169,81 @@ L 229.706024 41.472 - - - @@ -255,8 +255,8 @@ z - @@ -268,34 +268,34 @@ L 315.759036 41.472 - @@ -307,8 +307,8 @@ z - @@ -320,29 +320,29 @@ L 401.812048 41.472 - @@ -356,267 +356,267 @@ z - - - - - - - - - - - - - @@ -655,14 +655,14 @@ z - - @@ -678,8 +678,8 @@ L -3.5 0 - @@ -696,8 +696,8 @@ L 414.72 260.571697 - @@ -714,8 +714,8 @@ L 414.72 213.559394 - @@ -732,8 +732,8 @@ L 414.72 166.54709 - @@ -750,8 +750,8 @@ L 414.72 119.534787 - @@ -771,84 +771,84 @@ L 414.72 72.522484 - - - @@ -868,218 +868,218 @@ z - - - - - - - - - - @@ -1117,86 +1117,86 @@ z - - - - @@ -1242,39 +1242,39 @@ z - - - @@ -1290,32 +1290,32 @@ z - - diff --git a/docs/Usage/distance/img/jaro_winkler.svg b/docs/Usage/distance/img/jaro_winkler.svg index cf31272..3de12e9 100644 --- a/docs/Usage/distance/img/jaro_winkler.svg +++ b/docs/Usage/distance/img/jaro_winkler.svg @@ -21,33 +21,33 @@ - - - - @@ -58,25 +58,25 @@ L 0 3.5 - @@ -86,8 +86,8 @@ z - @@ -99,53 +99,53 @@ L 143.653012 41.472 - - @@ -156,8 +156,8 @@ z - @@ -169,81 +169,81 @@ L 229.706024 41.472 - - - @@ -255,8 +255,8 @@ z - @@ -268,34 +268,34 @@ L 315.759036 41.472 - @@ -307,8 +307,8 @@ z - @@ -320,29 +320,29 @@ L 401.812048 41.472 - @@ -356,267 +356,267 @@ z - - - - - - - - - - - - - @@ -655,14 +655,14 @@ z - - @@ -678,8 +678,8 @@ L -3.5 0 - @@ -696,8 +696,8 @@ L 414.72 260.035321 - @@ -714,8 +714,8 @@ L 414.72 212.486641 - @@ -732,8 +732,8 @@ L 414.72 164.937962 - @@ -750,8 +750,8 @@ L 414.72 117.389283 - @@ -771,84 +771,84 @@ L 414.72 69.840604 - - - @@ -868,218 +868,218 @@ z - - - - - - - - - - @@ -1117,116 +1117,116 @@ z - - - - - - @@ -1279,39 +1279,39 @@ z - - - @@ -1327,32 +1327,32 @@ z - - diff --git a/pyproject.toml b/pyproject.toml index 7c6e292..0bdf2bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,26 +7,26 @@ requires = [ build-backend = "backend" backend-path = ["_custom_build"] -[tool.isort] -profile = "black" [tool.mypy] -files = "src" +files = ["src"] python_version = "3.7" -strict = true +warn_unused_configs = true show_error_codes = true enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] -warn_unreachable = true +strict = true +disallow_untyped_defs = false [tool.pytest.ini_options] minversion = "6.0" +testpaths = ["tests"] addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"] +norecursedirs = ["_skbuild"] xfail_strict = true log_cli_level = "info" -testpaths = ["tests"] -[tool.pylint.master] -py-version = "3.6" +[tool.pylint] +py-version = "3.7" [tool.pylint.reports] output-format = "colorized" @@ -42,3 +42,52 @@ disable = [ "protected-access", "missing-module-docstring", ] + + +[tool.ruff] +select = [ + "E", "F", "W", # flake8 + "B", # flake8-bugbear + "I", # isort + "ARG", # flake8-unused-arguments + "C4", # flake8-comprehensions + "EM", # flake8-errmsg + "ICN", # flake8-import-conventions + "ISC", # flake8-implicit-str-concat + "G", # flake8-logging-format + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "PT", # flake8-pytest-style + "PTH", # flake8-use-pathlib + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "T20", # flake8-print + "UP", # pyupgrade + "YTT", # flake8-2020 + "EXE", # flake8-executable + "NPY", # NumPy specific rules + "PD", # pandas-vet +] +extend-ignore = [ + "PLR", # Design related pylint codes + "E501", # Line too long + "PT004", # Use underscore for non-returning fixture (use usefixture instead) + "PTH123", # use pathlib instead of builtin open +] +target-version = "py37" +src = ["src"] +unfixable = [ + "T20", # Removes print statements + "F841", # Removes unused variables +] +exclude = [] +flake8-unused-arguments.ignore-variadic-names = true +isort.required-imports = ["from __future__ import annotations"] + +[tool.ruff.per-file-ignores] +"tests/**" = ["T20"] +"bench/**" = ["T20"] +"_custom_build/backend.py" = ["T20"] +"setup.py" = ["T20"] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 3485f50..0000000 --- a/setup.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[flake8] -max-line-length = 120 -show_source = True -exclude = .git, __pycache__, build, dist, docs, tools, venv -extend-ignore = E203, E722, B903, B950, N801, N802, N806, B905, B907 -extend-select = B9 diff --git a/tests/distance/test_init.py b/tests/distance/test_init.py index 74d28ed..833b379 100644 --- a/tests/distance/test_init.py +++ b/tests/distance/test_init.py @@ -17,9 +17,9 @@ def test_editops_comparison(): """ ops = Levenshtein.editops("aaabaaa", "abbaaabba") assert ops == ops - assert not (ops != ops) # noqa + assert not (ops != ops) # noqa: SIM202 assert ops == ops.copy() - assert not (ops != ops.copy()) # noqa + assert not (ops != ops.copy()) # noqa: SIM202 @pytest.mark.parametrize("module", [distance_py, distance_cpp]) @@ -99,10 +99,12 @@ def test_editops_get_slice(module): assert ops[-3:].as_list() == ops_list[-3:] assert ops[-3:-1].as_list() == ops_list[-3:-1] - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="slice step cannot be zero"): ops[::0] - with pytest.raises(ValueError): + with pytest.raises( + ValueError, match="step sizes below 0 lead to an invalid order of editops" + ): ops[::-1] @@ -185,9 +187,9 @@ def test_opcodes_comparison(): """ ops = Levenshtein.opcodes("aaabaaa", "abbaaabba") assert ops == ops - assert not (ops != ops) # noqa + assert not (ops != ops) # noqa: SIM202 assert ops == ops.copy() - assert not (ops != ops.copy()) # noqa + assert not (ops != ops.copy()) # noqa: SIM202 @pytest.mark.parametrize("module", [distance_py, distance_cpp])