diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a9cf58e91..228f5ec09 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/haystack/mmh3.py b/haystack/mmh3.py index 7dc482ded..c9b08286a 100644 --- a/haystack/mmh3.py +++ b/haystack/mmh3.py @@ -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 diff --git a/haystack/modeling/data_handler/processor.py b/haystack/modeling/data_handler/processor.py index b2ea292b8..710a69046 100644 --- a/haystack/modeling/data_handler/processor.py +++ b/haystack/modeling/data_handler/processor.py @@ -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 diff --git a/haystack/pipelines/base.py b/haystack/pipelines/base.py index 8d4ea8a51..ea81f3e55 100644 --- a/haystack/pipelines/base.py +++ b/haystack/pipelines/base.py @@ -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, diff --git a/pyproject.toml b/pyproject.toml index ec5e4f3fe..72763c320 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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/*", diff --git a/test/mocks/pinecone.py b/test/mocks/pinecone.py index 2c247dbf4..60a2518f0 100644 --- a/test/mocks/pinecone.py +++ b/test/mocks/pinecone.py @@ -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 = []