ci: Use ruff in pre-commit to further limit code complexity (#5783)

* ci: Use ruff in pre-commit to further limit complexity

* Delete releasenotes/notes/ruff-4d2504d362035166.yaml

---------

Co-authored-by: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com>
This commit is contained in:
Christian Clauss 2023-09-13 15:18:16 +02:00 committed by GitHub
parent 5888fb7052
commit 30ca042370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 8 deletions

View File

@ -16,6 +16,11 @@ repos:
- id: trailing-whitespace # trims trailing whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.289
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:

View File

@ -22,8 +22,10 @@ else:
del _sys
def hash128(key, seed=0x0, x64arch=True):
def hash128(key, seed=0x0, x64arch=True): # noqa: C901,PLR0915
"""Implements 128bit murmur3 hash."""
# This function has a very high McCabe cyclomatic complexity score of 44
# (recommended is 10) and contains 212 statements (recommended is 50).
def hash128_x64(key, seed):
"""Implements 128bit murmur3 hash for x64."""
@ -153,8 +155,9 @@ def hash128(key, seed=0x0, x64arch=True):
return h2 << 64 | h1
def hash128_x86(key, seed):
def hash128_x86(key, seed): # noqa: PLR0915
"""Implements 128bit murmur3 hash for x86."""
# This function contains 125 statements (recommended is 50).
def fmix(h):
h ^= h >> 16

View File

@ -474,7 +474,7 @@ class SquadProcessor(Processor):
max_answers = (
self.max_answers
if self.max_answers is not None
else max(max(len(basket.raw["answers"]) for basket in baskets), 1)
else max(*(len(basket.raw["answers"]) for basket in baskets), 1)
)
# Convert answers from string to token space, skip this step for inference

View File

@ -607,7 +607,7 @@ class Pipeline:
return node_output
def run_batch( # type: ignore
def run_batch( # noqa: C901,PLR0912 type: ignore
self,
queries: Optional[List[str]] = None,
file_paths: Optional[List[str]] = None,

View File

@ -332,9 +332,11 @@ disable = [
[tool.pylint.'DESIGN']
max-args = 37 # Default is 5
max-attributes = 27 # Default is 7
max-branches = 33 # Default is 12
max-locals = 44 # Default is 15
max-statements = 205 # Default is 50
max-branches = 34 # Default is 12
max-locals = 45 # Default is 15
max-module-lines = 2468 # Default is 1000
max-nested-blocks = 7 # Default is 5
max-statements = 206 # Default is 50
[tool.pylint.'SIMILARITIES']
min-similarity-lines=6
@ -370,6 +372,31 @@ plugins = [
"pydantic.mypy",
]
[tool.ruff]
ignore = [
"PLR1714", # repeated-equality-comparison
"PLR5501", # collapsible-else-if
"PLW0603", # global-statement
"PLW1510", # subprocess-run-without-check
"PLW2901", # redefined-loop-name
"W605", # invalid-escape-sequence
]
select = [
"C90", # McCabe cyclomatic complexity
"PL", # Pylint
"W", # Pycodestyle warnings
]
[tool.ruff.mccabe]
max-complexity = 28
[tool.ruff.pylint]
allow-magic-value-types = ["float", "int", "str"]
max-args = 38 # Default is 5
max-branches = 32 # Default is 12
max-returns = 9 # Default is 6
max-statements = 105 # Default is 50
[tool.coverage.run]
omit = [
"haystack/testing/*",

View File

@ -148,7 +148,7 @@ class Index:
}
return response
def _filter(
def _filter( # noqa: C901,PLR0912
self,
metadata: dict,
filters: Optional[Union[FilterType, List[Optional[FilterType]]]],
@ -158,6 +158,8 @@ class Index:
"""
Mock filtering function
"""
# This function has a very high McCabe cyclomatic complexity score of 38
# (recommended is 10) and contains 55 branches (recommended is 12).
bools = []
if type(filters) is list:
list_bools = []