mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-08-19 22:18:11 +00:00
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:
parent
5888fb7052
commit
30ca042370
@ -16,6 +16,11 @@ repos:
|
|||||||
- id: trailing-whitespace # trims trailing whitespace
|
- id: trailing-whitespace # trims trailing whitespace
|
||||||
args: [--markdown-linebreak-ext=md]
|
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
|
- repo: https://github.com/psf/black
|
||||||
rev: 23.9.1
|
rev: 23.9.1
|
||||||
hooks:
|
hooks:
|
||||||
|
@ -22,8 +22,10 @@ else:
|
|||||||
del _sys
|
del _sys
|
||||||
|
|
||||||
|
|
||||||
def hash128(key, seed=0x0, x64arch=True):
|
def hash128(key, seed=0x0, x64arch=True): # noqa: C901,PLR0915
|
||||||
"""Implements 128bit murmur3 hash."""
|
"""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):
|
def hash128_x64(key, seed):
|
||||||
"""Implements 128bit murmur3 hash for x64."""
|
"""Implements 128bit murmur3 hash for x64."""
|
||||||
@ -153,8 +155,9 @@ def hash128(key, seed=0x0, x64arch=True):
|
|||||||
|
|
||||||
return h2 << 64 | h1
|
return h2 << 64 | h1
|
||||||
|
|
||||||
def hash128_x86(key, seed):
|
def hash128_x86(key, seed): # noqa: PLR0915
|
||||||
"""Implements 128bit murmur3 hash for x86."""
|
"""Implements 128bit murmur3 hash for x86."""
|
||||||
|
# This function contains 125 statements (recommended is 50).
|
||||||
|
|
||||||
def fmix(h):
|
def fmix(h):
|
||||||
h ^= h >> 16
|
h ^= h >> 16
|
||||||
|
@ -474,7 +474,7 @@ class SquadProcessor(Processor):
|
|||||||
max_answers = (
|
max_answers = (
|
||||||
self.max_answers
|
self.max_answers
|
||||||
if self.max_answers is not None
|
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
|
# Convert answers from string to token space, skip this step for inference
|
||||||
|
@ -607,7 +607,7 @@ class Pipeline:
|
|||||||
|
|
||||||
return node_output
|
return node_output
|
||||||
|
|
||||||
def run_batch( # type: ignore
|
def run_batch( # noqa: C901,PLR0912 type: ignore
|
||||||
self,
|
self,
|
||||||
queries: Optional[List[str]] = None,
|
queries: Optional[List[str]] = None,
|
||||||
file_paths: Optional[List[str]] = None,
|
file_paths: Optional[List[str]] = None,
|
||||||
|
@ -332,9 +332,11 @@ disable = [
|
|||||||
[tool.pylint.'DESIGN']
|
[tool.pylint.'DESIGN']
|
||||||
max-args = 37 # Default is 5
|
max-args = 37 # Default is 5
|
||||||
max-attributes = 27 # Default is 7
|
max-attributes = 27 # Default is 7
|
||||||
max-branches = 33 # Default is 12
|
max-branches = 34 # Default is 12
|
||||||
max-locals = 44 # Default is 15
|
max-locals = 45 # Default is 15
|
||||||
max-statements = 205 # Default is 50
|
max-module-lines = 2468 # Default is 1000
|
||||||
|
max-nested-blocks = 7 # Default is 5
|
||||||
|
max-statements = 206 # Default is 50
|
||||||
[tool.pylint.'SIMILARITIES']
|
[tool.pylint.'SIMILARITIES']
|
||||||
min-similarity-lines=6
|
min-similarity-lines=6
|
||||||
|
|
||||||
@ -370,6 +372,31 @@ plugins = [
|
|||||||
"pydantic.mypy",
|
"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]
|
[tool.coverage.run]
|
||||||
omit = [
|
omit = [
|
||||||
"haystack/testing/*",
|
"haystack/testing/*",
|
||||||
|
@ -148,7 +148,7 @@ class Index:
|
|||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def _filter(
|
def _filter( # noqa: C901,PLR0912
|
||||||
self,
|
self,
|
||||||
metadata: dict,
|
metadata: dict,
|
||||||
filters: Optional[Union[FilterType, List[Optional[FilterType]]]],
|
filters: Optional[Union[FilterType, List[Optional[FilterType]]]],
|
||||||
@ -158,6 +158,8 @@ class Index:
|
|||||||
"""
|
"""
|
||||||
Mock filtering function
|
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 = []
|
bools = []
|
||||||
if type(filters) is list:
|
if type(filters) is list:
|
||||||
list_bools = []
|
list_bools = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user